blob: 56557e3736c199a94db2592bbc29d1257c2f7e9d [file] [log] [blame]
Kevin Enderbyccab3172009-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 Cheng11424442011-07-26 00:24:13 +000010#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMBaseInfo.h"
13#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000014#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000015#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000018#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000019#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000021#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000023#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/MC/MCExpr.h"
25#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCInstrDesc.h"
27#include "llvm/MC/MCParser/MCAsmLexer.h"
28#include "llvm/MC/MCParser/MCAsmParser.h"
29#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
30#include "llvm/MC/MCRegisterInfo.h"
31#include "llvm/MC/MCStreamer.h"
32#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000033#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/Support/MathExtras.h"
35#include "llvm/Support/SourceMgr.h"
36#include "llvm/Support/TargetRegistry.h"
37#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000038
Kevin Enderbyccab3172009-09-15 00:27:25 +000039using namespace llvm;
40
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000041namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000042
43class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000044
Jim Grosbach04945c42011-12-02 00:35:16 +000045enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000046
Evan Cheng11424442011-07-26 00:24:13 +000047class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000048 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000049 MCAsmParser &Parser;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000050 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000051
Logan Chien4ea23b52013-05-10 16:17:24 +000052 // Unwind directives state
53 SMLoc FnStartLoc;
54 SMLoc CantUnwindLoc;
55 SMLoc PersonalityLoc;
56 SMLoc HandlerDataLoc;
57 int FPReg;
58 void resetUnwindDirectiveParserState() {
59 FnStartLoc = SMLoc();
60 CantUnwindLoc = SMLoc();
61 PersonalityLoc = SMLoc();
62 HandlerDataLoc = SMLoc();
63 FPReg = -1;
64 }
65
Jim Grosbachab5830e2011-12-14 02:16:11 +000066 // Map of register aliases registers via the .req directive.
67 StringMap<unsigned> RegisterReqs;
68
Jim Grosbached16ec42011-08-29 22:24:09 +000069 struct {
70 ARMCC::CondCodes Cond; // Condition for IT block.
71 unsigned Mask:4; // Condition mask for instructions.
72 // Starting at first 1 (from lsb).
73 // '1' condition as indicated in IT.
74 // '0' inverse of condition (else).
75 // Count of instructions in IT block is
76 // 4 - trailingzeroes(mask)
77
78 bool FirstCond; // Explicit flag for when we're parsing the
79 // First instruction in the IT block. It's
80 // implied in the mask, so needs special
81 // handling.
82
83 unsigned CurPosition; // Current position in parsing of IT
84 // block. In range [0,3]. Initialized
85 // according to count of instructions in block.
86 // ~0U if no active IT block.
87 } ITState;
88 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000089 void forwardITPosition() {
90 if (!inITBlock()) return;
91 // Move to the next instruction in the IT block, if there is one. If not,
92 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +000093 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +000094 if (++ITState.CurPosition == 5 - TZ)
95 ITState.CurPosition = ~0U; // Done with the IT block after this.
96 }
Jim Grosbached16ec42011-08-29 22:24:09 +000097
98
Kevin Enderbyccab3172009-09-15 00:27:25 +000099 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000100 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
101
Benjamin Kramer673824b2012-04-15 17:04:27 +0000102 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000103 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000104 return Parser.Warning(L, Msg, Ranges);
105 }
106 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000107 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000108 return Parser.Error(L, Msg, Ranges);
109 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000110
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000111 int tryParseRegister();
112 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000113 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000115 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000116 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
117 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000118 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
119 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000120 bool parseDirectiveWord(unsigned Size, SMLoc L);
121 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000122 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000123 bool parseDirectiveThumbFunc(SMLoc L);
124 bool parseDirectiveCode(SMLoc L);
125 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000126 bool parseDirectiveReq(StringRef Name, SMLoc L);
127 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000128 bool parseDirectiveArch(SMLoc L);
129 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000130 bool parseDirectiveFnStart(SMLoc L);
131 bool parseDirectiveFnEnd(SMLoc L);
132 bool parseDirectiveCantUnwind(SMLoc L);
133 bool parseDirectivePersonality(SMLoc L);
134 bool parseDirectiveHandlerData(SMLoc L);
135 bool parseDirectiveSetFP(SMLoc L);
136 bool parseDirectivePad(SMLoc L);
137 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000138
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000139 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000140 bool &CarrySetting, unsigned &ProcessorIMod,
141 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000142 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000143 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000144
Evan Cheng4d1ca962011-07-08 01:53:10 +0000145 bool isThumb() const {
146 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000147 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000148 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000149 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000150 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000151 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000152 bool isThumbTwo() const {
153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
154 }
Tim Northovera2292d02013-06-10 23:20:58 +0000155 bool hasThumb() const {
156 return STI.getFeatureBits() & ARM::HasV4TOps;
157 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000158 bool hasV6Ops() const {
159 return STI.getFeatureBits() & ARM::HasV6Ops;
160 }
James Molloy21efa7d2011-09-28 14:21:38 +0000161 bool hasV7Ops() const {
162 return STI.getFeatureBits() & ARM::HasV7Ops;
163 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000164 bool hasV8Ops() const {
165 return STI.getFeatureBits() & ARM::HasV8Ops;
166 }
Tim Northovera2292d02013-06-10 23:20:58 +0000167 bool hasARM() const {
168 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
169 }
170
Evan Cheng284b4672011-07-08 22:36:29 +0000171 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000172 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
173 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000174 }
James Molloy21efa7d2011-09-28 14:21:38 +0000175 bool isMClass() const {
176 return STI.getFeatureBits() & ARM::FeatureMClass;
177 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000178
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000179 /// @name Auto-generated Match Functions
180 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000181
Chris Lattner3e4582a2010-09-06 19:11:01 +0000182#define GET_ASSEMBLER_HEADER
183#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000184
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000185 /// }
186
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000187 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000188 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000189 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000190 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000191 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000192 OperandMatchResultTy parseCoprocOptionOperand(
193 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000194 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000195 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000196 OperandMatchResultTy parseInstSyncBarrierOptOperand(
197 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000198 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000199 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000200 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000201 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000202 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
203 StringRef Op, int Low, int High);
204 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
205 return parsePKHImm(O, "lsl", 0, 31);
206 }
207 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "asr", 1, 32);
209 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000210 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000211 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000212 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000213 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000214 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000215 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000216 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000217 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000218 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
219 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000220
221 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000222 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
223 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
224 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +0000225 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000226 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +0000227 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000228 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000229 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000230 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +0000231 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000232 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +0000233 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000234 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000235 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000236 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +0000237 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000238 void cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000239 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000240 void cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000241 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000242 void cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000243 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000244 void cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000245 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000246 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
247 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
248 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +0000249 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000250 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000251 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000252 void cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000253 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000254 void cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000255 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000256 void cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000257 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000258 void cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000259 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000260 bool validateInstruction(MCInst &Inst,
261 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000262 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000263 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000264 bool shouldOmitCCOutOperand(StringRef Mnemonic,
265 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000266
Kevin Enderbyccab3172009-09-15 00:27:25 +0000267public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000268 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000269 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000270 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000271 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000272 Match_RequiresThumb2,
273#define GET_OPERAND_DIAGNOSTIC_TYPES
274#include "ARMGenAsmMatcher.inc"
275
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000276 };
277
Evan Cheng91111d22011-07-09 05:47:46 +0000278 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Logan Chien4ea23b52013-05-10 16:17:24 +0000279 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000280 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000281
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000282 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000283 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000284
Evan Cheng4d1ca962011-07-08 01:53:10 +0000285 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000286 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000287
288 // Not in an ITBlock to start with.
289 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000290
291 // Set ELF header flags.
292 // FIXME: This should eventually end up somewhere else where more
293 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000294 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
295 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
296 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000297 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000298
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000299 // Implementation of the MCTargetAsmParser interface:
300 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000301 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
302 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000303 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000304 bool ParseDirective(AsmToken DirectiveID);
305
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000306 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000307 unsigned checkTargetMatchPredicate(MCInst &Inst);
308
Chad Rosier49963552012-10-13 00:26:04 +0000309 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000310 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000311 MCStreamer &Out, unsigned &ErrorInfo,
312 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000313};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000314} // end anonymous namespace
315
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000316namespace {
317
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000318/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000319/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000320class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000321 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000322 k_CondCode,
323 k_CCOut,
324 k_ITCondMask,
325 k_CoprocNum,
326 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000327 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000328 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000329 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000330 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000331 k_Memory,
332 k_PostIndexRegister,
333 k_MSRMask,
334 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000335 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000336 k_Register,
337 k_RegisterList,
338 k_DPRRegisterList,
339 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000340 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000341 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000342 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000343 k_ShiftedRegister,
344 k_ShiftedImmediate,
345 k_ShifterImmediate,
346 k_RotateImmediate,
347 k_BitfieldDescriptor,
348 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000349 } Kind;
350
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000351 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000352 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000353
Eric Christopher8996c5d2013-03-15 00:42:55 +0000354 struct CCOp {
355 ARMCC::CondCodes Val;
356 };
357
358 struct CopOp {
359 unsigned Val;
360 };
361
362 struct CoprocOptionOp {
363 unsigned Val;
364 };
365
366 struct ITMaskOp {
367 unsigned Mask:4;
368 };
369
370 struct MBOptOp {
371 ARM_MB::MemBOpt Val;
372 };
373
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000374 struct ISBOptOp {
375 ARM_ISB::InstSyncBOpt Val;
376 };
377
Eric Christopher8996c5d2013-03-15 00:42:55 +0000378 struct IFlagsOp {
379 ARM_PROC::IFlags Val;
380 };
381
382 struct MMaskOp {
383 unsigned Val;
384 };
385
386 struct TokOp {
387 const char *Data;
388 unsigned Length;
389 };
390
391 struct RegOp {
392 unsigned RegNum;
393 };
394
395 // A vector register list is a sequential list of 1 to 4 registers.
396 struct VectorListOp {
397 unsigned RegNum;
398 unsigned Count;
399 unsigned LaneIndex;
400 bool isDoubleSpaced;
401 };
402
403 struct VectorIndexOp {
404 unsigned Val;
405 };
406
407 struct ImmOp {
408 const MCExpr *Val;
409 };
410
411 /// Combined record for all forms of ARM address expressions.
412 struct MemoryOp {
413 unsigned BaseRegNum;
414 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
415 // was specified.
416 const MCConstantExpr *OffsetImm; // Offset immediate value
417 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
418 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
419 unsigned ShiftImm; // shift for OffsetReg.
420 unsigned Alignment; // 0 = no alignment specified
421 // n = alignment in bytes (2, 4, 8, 16, or 32)
422 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
423 };
424
425 struct PostIdxRegOp {
426 unsigned RegNum;
427 bool isAdd;
428 ARM_AM::ShiftOpc ShiftTy;
429 unsigned ShiftImm;
430 };
431
432 struct ShifterImmOp {
433 bool isASR;
434 unsigned Imm;
435 };
436
437 struct RegShiftedRegOp {
438 ARM_AM::ShiftOpc ShiftTy;
439 unsigned SrcReg;
440 unsigned ShiftReg;
441 unsigned ShiftImm;
442 };
443
444 struct RegShiftedImmOp {
445 ARM_AM::ShiftOpc ShiftTy;
446 unsigned SrcReg;
447 unsigned ShiftImm;
448 };
449
450 struct RotImmOp {
451 unsigned Imm;
452 };
453
454 struct BitfieldOp {
455 unsigned LSB;
456 unsigned Width;
457 };
458
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000459 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000460 struct CCOp CC;
461 struct CopOp Cop;
462 struct CoprocOptionOp CoprocOption;
463 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000464 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000465 struct ITMaskOp ITMask;
466 struct IFlagsOp IFlags;
467 struct MMaskOp MMask;
468 struct TokOp Tok;
469 struct RegOp Reg;
470 struct VectorListOp VectorList;
471 struct VectorIndexOp VectorIndex;
472 struct ImmOp Imm;
473 struct MemoryOp Memory;
474 struct PostIdxRegOp PostIdxReg;
475 struct ShifterImmOp ShifterImm;
476 struct RegShiftedRegOp RegShiftedReg;
477 struct RegShiftedImmOp RegShiftedImm;
478 struct RotImmOp RotImm;
479 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000480 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000481
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000482 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
483public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000484 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
485 Kind = o.Kind;
486 StartLoc = o.StartLoc;
487 EndLoc = o.EndLoc;
488 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000489 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000490 CC = o.CC;
491 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000492 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000493 ITMask = o.ITMask;
494 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000495 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000496 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000497 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000498 case k_CCOut:
499 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000500 Reg = o.Reg;
501 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000502 case k_RegisterList:
503 case k_DPRRegisterList:
504 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000505 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000506 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000507 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000508 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000509 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000510 VectorList = o.VectorList;
511 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000512 case k_CoprocNum:
513 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000514 Cop = o.Cop;
515 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000516 case k_CoprocOption:
517 CoprocOption = o.CoprocOption;
518 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000519 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000520 Imm = o.Imm;
521 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000522 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000523 MBOpt = o.MBOpt;
524 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000525 case k_InstSyncBarrierOpt:
526 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000527 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000528 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000529 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000530 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000531 PostIdxReg = o.PostIdxReg;
532 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000533 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000534 MMask = o.MMask;
535 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000536 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000537 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000538 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000539 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000540 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000541 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000542 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000543 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000544 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000545 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000546 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000547 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000548 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000549 RotImm = o.RotImm;
550 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000551 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000552 Bitfield = o.Bitfield;
553 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000554 case k_VectorIndex:
555 VectorIndex = o.VectorIndex;
556 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000557 }
558 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000559
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000560 /// getStartLoc - Get the location of the first token of this operand.
561 SMLoc getStartLoc() const { return StartLoc; }
562 /// getEndLoc - Get the location of the last token of this operand.
563 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000564 /// getLocRange - Get the range between the first and last token of this
565 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000566 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
567
Daniel Dunbard8042b72010-08-11 06:36:53 +0000568 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000569 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000570 return CC.Val;
571 }
572
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000573 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000574 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000575 return Cop.Val;
576 }
577
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000578 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000579 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000580 return StringRef(Tok.Data, Tok.Length);
581 }
582
583 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000584 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000585 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000586 }
587
Bill Wendlingbed94652010-11-09 23:28:44 +0000588 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000589 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
590 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000591 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000592 }
593
Kevin Enderbyf5079942009-10-13 22:19:02 +0000594 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000595 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000596 return Imm.Val;
597 }
598
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000599 unsigned getVectorIndex() const {
600 assert(Kind == k_VectorIndex && "Invalid access!");
601 return VectorIndex.Val;
602 }
603
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000604 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000605 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000606 return MBOpt.Val;
607 }
608
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000609 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
610 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
611 return ISBOpt.Val;
612 }
613
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000614 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000615 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000616 return IFlags.Val;
617 }
618
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000619 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000620 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000621 return MMask.Val;
622 }
623
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000624 bool isCoprocNum() const { return Kind == k_CoprocNum; }
625 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000626 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000627 bool isCondCode() const { return Kind == k_CondCode; }
628 bool isCCOut() const { return Kind == k_CCOut; }
629 bool isITMask() const { return Kind == k_ITCondMask; }
630 bool isITCondCode() const { return Kind == k_CondCode; }
631 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000632 // checks whether this operand is an unsigned offset which fits is a field
633 // of specified width and scaled by a specific number of bits
634 template<unsigned width, unsigned scale>
635 bool isUnsignedOffset() const {
636 if (!isImm()) return false;
637 if (dyn_cast<MCSymbolRefExpr>(Imm.Val)) return true;
638 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
639 int64_t Val = CE->getValue();
640 int64_t Align = 1LL << scale;
641 int64_t Max = Align * ((1LL << width) - 1);
642 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
643 }
644 return false;
645 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000646 bool isFPImm() const {
647 if (!isImm()) return false;
648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
649 if (!CE) return false;
650 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
651 return Val != -1;
652 }
Jim Grosbachea231912011-12-22 22:19:05 +0000653 bool isFBits16() const {
654 if (!isImm()) return false;
655 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
656 if (!CE) return false;
657 int64_t Value = CE->getValue();
658 return Value >= 0 && Value <= 16;
659 }
660 bool isFBits32() const {
661 if (!isImm()) return false;
662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
663 if (!CE) return false;
664 int64_t Value = CE->getValue();
665 return Value >= 1 && Value <= 32;
666 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000667 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000668 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
670 if (!CE) return false;
671 int64_t Value = CE->getValue();
672 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
673 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000674 bool isImm0_4() const {
675 if (!isImm()) return false;
676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
677 if (!CE) return false;
678 int64_t Value = CE->getValue();
679 return Value >= 0 && Value < 5;
680 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000681 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000682 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
684 if (!CE) return false;
685 int64_t Value = CE->getValue();
686 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
687 }
688 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000689 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
691 if (!CE) return false;
692 int64_t Value = CE->getValue();
693 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
694 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000695 bool isImm0_508s4Neg() const {
696 if (!isImm()) return false;
697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
698 if (!CE) return false;
699 int64_t Value = -CE->getValue();
700 // explicitly exclude zero. we want that to use the normal 0_508 version.
701 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
702 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000703 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000704 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
706 if (!CE) return false;
707 int64_t Value = CE->getValue();
708 return Value >= 0 && Value < 256;
709 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000710 bool isImm0_4095() const {
711 if (!isImm()) return false;
712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
713 if (!CE) return false;
714 int64_t Value = CE->getValue();
715 return Value >= 0 && Value < 4096;
716 }
717 bool isImm0_4095Neg() const {
718 if (!isImm()) return false;
719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
720 if (!CE) return false;
721 int64_t Value = -CE->getValue();
722 return Value > 0 && Value < 4096;
723 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000724 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000725 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
727 if (!CE) return false;
728 int64_t Value = CE->getValue();
729 return Value >= 0 && Value < 2;
730 }
731 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000732 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
734 if (!CE) return false;
735 int64_t Value = CE->getValue();
736 return Value >= 0 && Value < 4;
737 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000738 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000739 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
741 if (!CE) return false;
742 int64_t Value = CE->getValue();
743 return Value >= 0 && Value < 8;
744 }
745 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000746 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
748 if (!CE) return false;
749 int64_t Value = CE->getValue();
750 return Value >= 0 && Value < 16;
751 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000752 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000753 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +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 }
Jim Grosbach00326402011-12-08 01:30:04 +0000759 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000760 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30: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 < 64;
765 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000766 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000767 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
769 if (!CE) return false;
770 int64_t Value = CE->getValue();
771 return Value == 8;
772 }
773 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000774 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 if (!CE) return false;
777 int64_t Value = CE->getValue();
778 return Value == 16;
779 }
780 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000781 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
783 if (!CE) return false;
784 int64_t Value = CE->getValue();
785 return Value == 32;
786 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000787 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000788 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000789 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
790 if (!CE) return false;
791 int64_t Value = CE->getValue();
792 return Value > 0 && Value <= 8;
793 }
794 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000795 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
797 if (!CE) return false;
798 int64_t Value = CE->getValue();
799 return Value > 0 && Value <= 16;
800 }
801 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000802 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return Value > 0 && Value <= 32;
807 }
808 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000809 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return Value > 0 && Value <= 64;
814 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000815 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000816 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
818 if (!CE) return false;
819 int64_t Value = CE->getValue();
820 return Value > 0 && Value < 8;
821 }
822 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000823 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
825 if (!CE) return false;
826 int64_t Value = CE->getValue();
827 return Value > 0 && Value < 16;
828 }
829 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000830 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
832 if (!CE) return false;
833 int64_t Value = CE->getValue();
834 return Value > 0 && Value < 32;
835 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000836 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000837 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
839 if (!CE) return false;
840 int64_t Value = CE->getValue();
841 return Value > 0 && Value < 17;
842 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000843 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000844 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
846 if (!CE) return false;
847 int64_t Value = CE->getValue();
848 return Value > 0 && Value < 33;
849 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000850 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000851 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 if (!CE) return false;
854 int64_t Value = CE->getValue();
855 return Value >= 0 && Value < 33;
856 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000857 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000858 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000859 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
860 if (!CE) return false;
861 int64_t Value = CE->getValue();
862 return Value >= 0 && Value < 65536;
863 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000864 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000865 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
867 // If it's not a constant expression, it'll generate a fixup and be
868 // handled later.
869 if (!CE) return true;
870 int64_t Value = CE->getValue();
871 return Value >= 0 && Value < 65536;
872 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000873 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000874 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
876 if (!CE) return false;
877 int64_t Value = CE->getValue();
878 return Value >= 0 && Value <= 0xffffff;
879 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000880 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000881 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
883 if (!CE) return false;
884 int64_t Value = CE->getValue();
885 return Value > 0 && Value < 33;
886 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000887 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000888 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
890 if (!CE) return false;
891 int64_t Value = CE->getValue();
892 return Value >= 0 && Value < 32;
893 }
894 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000895 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000896 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
897 if (!CE) return false;
898 int64_t Value = CE->getValue();
899 return Value > 0 && Value <= 32;
900 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000901 bool isAdrLabel() const {
902 // If we have an immediate that's not a constant, treat it as a label
903 // reference needing a fixup. If it is a constant, but it can't fit
904 // into shift immediate encoding, we reject it.
905 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
906 else return (isARMSOImm() || isARMSOImmNeg());
907 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000908 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000909 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000910 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
911 if (!CE) return false;
912 int64_t Value = CE->getValue();
913 return ARM_AM::getSOImmVal(Value) != -1;
914 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000915 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000916 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
918 if (!CE) return false;
919 int64_t Value = CE->getValue();
920 return ARM_AM::getSOImmVal(~Value) != -1;
921 }
Jim Grosbach30506252011-12-08 00:31:07 +0000922 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000923 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000924 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
925 if (!CE) return false;
926 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000927 // Only use this when not representable as a plain so_imm.
928 return ARM_AM::getSOImmVal(Value) == -1 &&
929 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000930 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000931 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000932 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
934 if (!CE) return false;
935 int64_t Value = CE->getValue();
936 return ARM_AM::getT2SOImmVal(Value) != -1;
937 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000938 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000939 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000940 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
941 if (!CE) return false;
942 int64_t Value = CE->getValue();
943 return ARM_AM::getT2SOImmVal(~Value) != -1;
944 }
Jim Grosbach30506252011-12-08 00:31:07 +0000945 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000946 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000947 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
948 if (!CE) return false;
949 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000950 // Only use this when not representable as a plain so_imm.
951 return ARM_AM::getT2SOImmVal(Value) == -1 &&
952 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000953 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000954 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000955 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000956 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
957 if (!CE) return false;
958 int64_t Value = CE->getValue();
959 return Value == 1 || Value == 0;
960 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000961 bool isReg() const { return Kind == k_Register; }
962 bool isRegList() const { return Kind == k_RegisterList; }
963 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
964 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
965 bool isToken() const { return Kind == k_Token; }
966 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000967 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000968 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000969 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
970 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
971 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
972 bool isRotImm() const { return Kind == k_RotateImmediate; }
973 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
974 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000975 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000976 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000977 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000978 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000979 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000980 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000981 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000982 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
983 (alignOK || Memory.Alignment == 0);
984 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000985 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000986 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000987 return false;
988 // Base register must be PC.
989 if (Memory.BaseRegNum != ARM::PC)
990 return false;
991 // Immediate offset in range [-4095, 4095].
992 if (!Memory.OffsetImm) return true;
993 int64_t Val = Memory.OffsetImm->getValue();
994 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
995 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000996 bool isAlignedMemory() const {
997 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000998 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000999 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001000 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001001 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001002 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001003 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001004 if (!Memory.OffsetImm) return true;
1005 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001006 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001007 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001008 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001009 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001010 // Immediate offset in range [-4095, 4095].
1011 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1012 if (!CE) return false;
1013 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001014 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001015 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001016 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001017 // If we have an immediate that's not a constant, treat it as a label
1018 // reference needing a fixup. If it is a constant, it's something else
1019 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001020 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001021 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001022 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001023 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001024 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001025 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001026 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001027 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001028 if (!Memory.OffsetImm) return true;
1029 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001030 // The #-0 offset is encoded as INT32_MIN, and we have to check
1031 // for this too.
1032 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001033 }
1034 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001035 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001036 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001037 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001038 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1039 // Immediate offset in range [-255, 255].
1040 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1041 if (!CE) return false;
1042 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001043 // Special case, #-0 is INT32_MIN.
1044 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001045 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001046 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001047 // If we have an immediate that's not a constant, treat it as a label
1048 // reference needing a fixup. If it is a constant, it's something else
1049 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001050 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001051 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001052 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001053 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001054 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001055 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001056 if (!Memory.OffsetImm) return true;
1057 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001058 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001059 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001060 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001061 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001062 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001063 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001064 return false;
1065 return true;
1066 }
1067 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001068 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001069 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1070 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001071 return false;
1072 return true;
1073 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001074 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001075 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001076 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001077 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001078 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001079 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001080 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001081 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001082 return false;
1083 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001084 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001085 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001086 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001087 return false;
1088 return true;
1089 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001090 bool isMemThumbRR() const {
1091 // Thumb reg+reg addressing is simple. Just two registers, a base and
1092 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001093 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001094 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001095 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001096 return isARMLowRegister(Memory.BaseRegNum) &&
1097 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001098 }
1099 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001100 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001101 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001102 return false;
1103 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001104 if (!Memory.OffsetImm) return true;
1105 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001106 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1107 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001108 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001109 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001110 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001111 return false;
1112 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001113 if (!Memory.OffsetImm) return true;
1114 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001115 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1116 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001117 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001118 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001119 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001120 return false;
1121 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001122 if (!Memory.OffsetImm) return true;
1123 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001124 return Val >= 0 && Val <= 31;
1125 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001126 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001127 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001128 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001129 return false;
1130 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001131 if (!Memory.OffsetImm) return true;
1132 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001133 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001134 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001135 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001136 // If we have an immediate that's not a constant, treat it as a label
1137 // reference needing a fixup. If it is a constant, it's something else
1138 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001139 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001140 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001141 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001142 return false;
1143 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001144 if (!Memory.OffsetImm) return true;
1145 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001146 // Special case, #-0 is INT32_MIN.
1147 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001148 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001149 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001150 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001151 return false;
1152 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001153 if (!Memory.OffsetImm) return true;
1154 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001155 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1156 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001157 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001158 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001159 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001160 // Base reg of PC isn't allowed for these encodings.
1161 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001162 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001163 if (!Memory.OffsetImm) return true;
1164 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001165 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001166 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001167 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001168 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001169 return false;
1170 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001171 if (!Memory.OffsetImm) return true;
1172 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001173 return Val >= 0 && Val < 256;
1174 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001175 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001176 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001177 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001178 // Base reg of PC isn't allowed for these encodings.
1179 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001180 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001181 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001182 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001183 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001184 }
1185 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001186 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001187 return false;
1188 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001189 if (!Memory.OffsetImm) return true;
1190 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001191 return (Val >= 0 && Val < 4096);
1192 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001193 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001194 // If we have an immediate that's not a constant, treat it as a label
1195 // reference needing a fixup. If it is a constant, it's something else
1196 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001197 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001198 return true;
1199
Chad Rosier41099832012-09-11 23:02:35 +00001200 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001201 return false;
1202 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001203 if (!Memory.OffsetImm) return true;
1204 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001205 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001206 }
1207 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001208 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001209 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1210 if (!CE) return false;
1211 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001212 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001213 }
Jim Grosbach93981412011-10-11 21:55:36 +00001214 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001215 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001216 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1217 if (!CE) return false;
1218 int64_t Val = CE->getValue();
1219 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1220 (Val == INT32_MIN);
1221 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001222
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001223 bool isMSRMask() const { return Kind == k_MSRMask; }
1224 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001225
Jim Grosbach741cd732011-10-17 22:26:03 +00001226 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001227 bool isSingleSpacedVectorList() const {
1228 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1229 }
1230 bool isDoubleSpacedVectorList() const {
1231 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1232 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001233 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001234 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001235 return VectorList.Count == 1;
1236 }
1237
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001238 bool isVecListDPair() const {
1239 if (!isSingleSpacedVectorList()) return false;
1240 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1241 .contains(VectorList.RegNum));
1242 }
1243
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001244 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001245 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001246 return VectorList.Count == 3;
1247 }
1248
Jim Grosbach846bcff2011-10-21 20:35:01 +00001249 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001250 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001251 return VectorList.Count == 4;
1252 }
1253
Jim Grosbache5307f92012-03-05 21:43:40 +00001254 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001255 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001256 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1257 .contains(VectorList.RegNum));
1258 }
1259
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001260 bool isVecListThreeQ() const {
1261 if (!isDoubleSpacedVectorList()) return false;
1262 return VectorList.Count == 3;
1263 }
1264
Jim Grosbach1e946a42012-01-24 00:43:12 +00001265 bool isVecListFourQ() const {
1266 if (!isDoubleSpacedVectorList()) return false;
1267 return VectorList.Count == 4;
1268 }
1269
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001270 bool isSingleSpacedVectorAllLanes() const {
1271 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1272 }
1273 bool isDoubleSpacedVectorAllLanes() const {
1274 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1275 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001276 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001277 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001278 return VectorList.Count == 1;
1279 }
1280
Jim Grosbach13a292c2012-03-06 22:01:44 +00001281 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001282 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001283 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1284 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001285 }
1286
Jim Grosbached428bc2012-03-06 23:10:38 +00001287 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001288 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001289 return VectorList.Count == 2;
1290 }
1291
Jim Grosbachb78403c2012-01-24 23:47:04 +00001292 bool isVecListThreeDAllLanes() const {
1293 if (!isSingleSpacedVectorAllLanes()) return false;
1294 return VectorList.Count == 3;
1295 }
1296
1297 bool isVecListThreeQAllLanes() const {
1298 if (!isDoubleSpacedVectorAllLanes()) return false;
1299 return VectorList.Count == 3;
1300 }
1301
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001302 bool isVecListFourDAllLanes() const {
1303 if (!isSingleSpacedVectorAllLanes()) return false;
1304 return VectorList.Count == 4;
1305 }
1306
1307 bool isVecListFourQAllLanes() const {
1308 if (!isDoubleSpacedVectorAllLanes()) return false;
1309 return VectorList.Count == 4;
1310 }
1311
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001312 bool isSingleSpacedVectorIndexed() const {
1313 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1314 }
1315 bool isDoubleSpacedVectorIndexed() const {
1316 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1317 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001318 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001319 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001320 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1321 }
1322
Jim Grosbachda511042011-12-14 23:35:06 +00001323 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001324 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001325 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1326 }
1327
1328 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001329 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001330 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1331 }
1332
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001333 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001334 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001335 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1336 }
1337
Jim Grosbachda511042011-12-14 23:35:06 +00001338 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001339 if (!isSingleSpacedVectorIndexed()) return false;
1340 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1341 }
1342
1343 bool isVecListTwoQWordIndexed() const {
1344 if (!isDoubleSpacedVectorIndexed()) return false;
1345 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1346 }
1347
1348 bool isVecListTwoQHWordIndexed() const {
1349 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001350 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1351 }
1352
1353 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001354 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001355 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1356 }
1357
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001358 bool isVecListThreeDByteIndexed() const {
1359 if (!isSingleSpacedVectorIndexed()) return false;
1360 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1361 }
1362
1363 bool isVecListThreeDHWordIndexed() const {
1364 if (!isSingleSpacedVectorIndexed()) return false;
1365 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1366 }
1367
1368 bool isVecListThreeQWordIndexed() const {
1369 if (!isDoubleSpacedVectorIndexed()) return false;
1370 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1371 }
1372
1373 bool isVecListThreeQHWordIndexed() const {
1374 if (!isDoubleSpacedVectorIndexed()) return false;
1375 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1376 }
1377
1378 bool isVecListThreeDWordIndexed() const {
1379 if (!isSingleSpacedVectorIndexed()) return false;
1380 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1381 }
1382
Jim Grosbach14952a02012-01-24 18:37:25 +00001383 bool isVecListFourDByteIndexed() const {
1384 if (!isSingleSpacedVectorIndexed()) return false;
1385 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1386 }
1387
1388 bool isVecListFourDHWordIndexed() const {
1389 if (!isSingleSpacedVectorIndexed()) return false;
1390 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1391 }
1392
1393 bool isVecListFourQWordIndexed() const {
1394 if (!isDoubleSpacedVectorIndexed()) return false;
1395 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1396 }
1397
1398 bool isVecListFourQHWordIndexed() const {
1399 if (!isDoubleSpacedVectorIndexed()) return false;
1400 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1401 }
1402
1403 bool isVecListFourDWordIndexed() const {
1404 if (!isSingleSpacedVectorIndexed()) return false;
1405 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1406 }
1407
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001408 bool isVectorIndex8() const {
1409 if (Kind != k_VectorIndex) return false;
1410 return VectorIndex.Val < 8;
1411 }
1412 bool isVectorIndex16() const {
1413 if (Kind != k_VectorIndex) return false;
1414 return VectorIndex.Val < 4;
1415 }
1416 bool isVectorIndex32() const {
1417 if (Kind != k_VectorIndex) return false;
1418 return VectorIndex.Val < 2;
1419 }
1420
Jim Grosbach741cd732011-10-17 22:26:03 +00001421 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001422 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001423 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1424 // Must be a constant.
1425 if (!CE) return false;
1426 int64_t Value = CE->getValue();
1427 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1428 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001429 return Value >= 0 && Value < 256;
1430 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001431
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001432 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001433 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001434 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1435 // Must be a constant.
1436 if (!CE) return false;
1437 int64_t Value = CE->getValue();
1438 // i16 value in the range [0,255] or [0x0100, 0xff00]
1439 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1440 }
1441
Jim Grosbach8211c052011-10-18 00:22:00 +00001442 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001443 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001444 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1445 // Must be a constant.
1446 if (!CE) return false;
1447 int64_t Value = CE->getValue();
1448 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1449 return (Value >= 0 && Value < 256) ||
1450 (Value >= 0x0100 && Value <= 0xff00) ||
1451 (Value >= 0x010000 && Value <= 0xff0000) ||
1452 (Value >= 0x01000000 && Value <= 0xff000000);
1453 }
1454
1455 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001456 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001457 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1458 // Must be a constant.
1459 if (!CE) return false;
1460 int64_t Value = CE->getValue();
1461 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1462 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1463 return (Value >= 0 && Value < 256) ||
1464 (Value >= 0x0100 && Value <= 0xff00) ||
1465 (Value >= 0x010000 && Value <= 0xff0000) ||
1466 (Value >= 0x01000000 && Value <= 0xff000000) ||
1467 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1468 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1469 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001470 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001471 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001472 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1473 // Must be a constant.
1474 if (!CE) return false;
1475 int64_t Value = ~CE->getValue();
1476 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1477 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1478 return (Value >= 0 && Value < 256) ||
1479 (Value >= 0x0100 && Value <= 0xff00) ||
1480 (Value >= 0x010000 && Value <= 0xff0000) ||
1481 (Value >= 0x01000000 && Value <= 0xff000000) ||
1482 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1483 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1484 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001485
Jim Grosbache4454e02011-10-18 16:18:11 +00001486 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001487 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001488 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1489 // Must be a constant.
1490 if (!CE) return false;
1491 uint64_t Value = CE->getValue();
1492 // i64 value with each byte being either 0 or 0xff.
1493 for (unsigned i = 0; i < 8; ++i)
1494 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1495 return true;
1496 }
1497
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001498 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001499 // Add as immediates when possible. Null MCExpr = 0.
1500 if (Expr == 0)
1501 Inst.addOperand(MCOperand::CreateImm(0));
1502 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001503 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1504 else
1505 Inst.addOperand(MCOperand::CreateExpr(Expr));
1506 }
1507
Daniel Dunbard8042b72010-08-11 06:36:53 +00001508 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001509 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001510 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001511 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1512 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001513 }
1514
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001515 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1516 assert(N == 1 && "Invalid number of operands!");
1517 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1518 }
1519
Jim Grosbach48399582011-10-12 17:34:41 +00001520 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1521 assert(N == 1 && "Invalid number of operands!");
1522 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1523 }
1524
1525 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1526 assert(N == 1 && "Invalid number of operands!");
1527 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1528 }
1529
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001530 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1531 assert(N == 1 && "Invalid number of operands!");
1532 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1533 }
1534
1535 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1536 assert(N == 1 && "Invalid number of operands!");
1537 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1538 }
1539
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001540 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1541 assert(N == 1 && "Invalid number of operands!");
1542 Inst.addOperand(MCOperand::CreateReg(getReg()));
1543 }
1544
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001545 void addRegOperands(MCInst &Inst, unsigned N) const {
1546 assert(N == 1 && "Invalid number of operands!");
1547 Inst.addOperand(MCOperand::CreateReg(getReg()));
1548 }
1549
Jim Grosbachac798e12011-07-25 20:49:51 +00001550 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001551 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001552 assert(isRegShiftedReg() &&
1553 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001554 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1555 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001556 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001557 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001558 }
1559
Jim Grosbachac798e12011-07-25 20:49:51 +00001560 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001561 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001562 assert(isRegShiftedImm() &&
1563 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001564 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001565 // Shift of #32 is encoded as 0 where permitted
1566 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001567 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001568 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001569 }
1570
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001571 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001572 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001573 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1574 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001575 }
1576
Bill Wendling8d2aa032010-11-08 23:49:57 +00001577 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001578 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001579 const SmallVectorImpl<unsigned> &RegList = getRegList();
1580 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001581 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1582 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001583 }
1584
Bill Wendling9898ac92010-11-17 04:32:08 +00001585 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1586 addRegListOperands(Inst, N);
1587 }
1588
1589 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1590 addRegListOperands(Inst, N);
1591 }
1592
Jim Grosbach833b9d32011-07-27 20:15:40 +00001593 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1594 assert(N == 1 && "Invalid number of operands!");
1595 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1596 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1597 }
1598
Jim Grosbach864b6092011-07-28 21:34:26 +00001599 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1600 assert(N == 1 && "Invalid number of operands!");
1601 // Munge the lsb/width into a bitfield mask.
1602 unsigned lsb = Bitfield.LSB;
1603 unsigned width = Bitfield.Width;
1604 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1605 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1606 (32 - (lsb + width)));
1607 Inst.addOperand(MCOperand::CreateImm(Mask));
1608 }
1609
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001610 void addImmOperands(MCInst &Inst, unsigned N) const {
1611 assert(N == 1 && "Invalid number of operands!");
1612 addExpr(Inst, getImm());
1613 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001614
Jim Grosbachea231912011-12-22 22:19:05 +00001615 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1616 assert(N == 1 && "Invalid number of operands!");
1617 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1618 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1619 }
1620
1621 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1622 assert(N == 1 && "Invalid number of operands!");
1623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1624 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1625 }
1626
Jim Grosbache7fbce72011-10-03 23:38:36 +00001627 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1630 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1631 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001632 }
1633
Jim Grosbach7db8d692011-09-08 22:07:06 +00001634 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1635 assert(N == 1 && "Invalid number of operands!");
1636 // FIXME: We really want to scale the value here, but the LDRD/STRD
1637 // instruction don't encode operands that way yet.
1638 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1639 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1640 }
1641
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001642 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1643 assert(N == 1 && "Invalid number of operands!");
1644 // The immediate is scaled by four in the encoding and is stored
1645 // in the MCInst as such. Lop off the low two bits here.
1646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1647 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1648 }
1649
Jim Grosbach930f2f62012-04-05 20:57:13 +00001650 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 // The immediate is scaled by four in the encoding and is stored
1653 // in the MCInst as such. Lop off the low two bits here.
1654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1655 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1656 }
1657
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001658 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1659 assert(N == 1 && "Invalid number of operands!");
1660 // The immediate is scaled by four in the encoding and is stored
1661 // in the MCInst as such. Lop off the low two bits here.
1662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1664 }
1665
Jim Grosbach475c6db2011-07-25 23:09:14 +00001666 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1667 assert(N == 1 && "Invalid number of operands!");
1668 // The constant encodes as the immediate-1, and we store in the instruction
1669 // the bits as encoded, so subtract off one here.
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1672 }
1673
Jim Grosbach801e0a32011-07-22 23:16:18 +00001674 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1675 assert(N == 1 && "Invalid number of operands!");
1676 // The constant encodes as the immediate-1, and we store in the instruction
1677 // the bits as encoded, so subtract off one here.
1678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1679 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1680 }
1681
Jim Grosbach46dd4132011-08-17 21:51:27 +00001682 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1683 assert(N == 1 && "Invalid number of operands!");
1684 // The constant encodes as the immediate, except for 32, which encodes as
1685 // zero.
1686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1687 unsigned Imm = CE->getValue();
1688 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1689 }
1690
Jim Grosbach27c1e252011-07-21 17:23:04 +00001691 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1692 assert(N == 1 && "Invalid number of operands!");
1693 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1694 // the instruction as well.
1695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1696 int Val = CE->getValue();
1697 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1698 }
1699
Jim Grosbachb009a872011-10-28 22:36:30 +00001700 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1701 assert(N == 1 && "Invalid number of operands!");
1702 // The operand is actually a t2_so_imm, but we have its bitwise
1703 // negation in the assembly source, so twiddle it here.
1704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1705 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1706 }
1707
Jim Grosbach30506252011-12-08 00:31:07 +00001708 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1709 assert(N == 1 && "Invalid number of operands!");
1710 // The operand is actually a t2_so_imm, but we have its
1711 // negation in the assembly source, so twiddle it here.
1712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1713 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1714 }
1715
Jim Grosbach930f2f62012-04-05 20:57:13 +00001716 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1717 assert(N == 1 && "Invalid number of operands!");
1718 // The operand is actually an imm0_4095, but we have its
1719 // negation in the assembly source, so twiddle it here.
1720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1721 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1722 }
1723
Mihai Popad36cbaa2013-07-03 09:21:44 +00001724 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1725 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1726 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1727 return;
1728 }
1729
1730 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1731 assert(SR && "Unknown value type!");
1732 Inst.addOperand(MCOperand::CreateExpr(SR));
1733 }
1734
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001735 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1736 assert(N == 1 && "Invalid number of operands!");
1737 // The operand is actually a so_imm, but we have its bitwise
1738 // negation in the assembly source, so twiddle it here.
1739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1740 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1741 }
1742
Jim Grosbach30506252011-12-08 00:31:07 +00001743 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1744 assert(N == 1 && "Invalid number of operands!");
1745 // The operand is actually a so_imm, but we have its
1746 // negation in the assembly source, so twiddle it here.
1747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1748 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1749 }
1750
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001751 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1752 assert(N == 1 && "Invalid number of operands!");
1753 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1754 }
1755
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001756 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1757 assert(N == 1 && "Invalid number of operands!");
1758 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1759 }
1760
Jim Grosbachd3595712011-08-03 23:50:40 +00001761 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1762 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001763 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001764 }
1765
Jim Grosbach94298a92012-01-18 22:46:46 +00001766 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1767 assert(N == 1 && "Invalid number of operands!");
1768 int32_t Imm = Memory.OffsetImm->getValue();
1769 // FIXME: Handle #-0
1770 if (Imm == INT32_MIN) Imm = 0;
1771 Inst.addOperand(MCOperand::CreateImm(Imm));
1772 }
1773
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001774 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1775 assert(N == 1 && "Invalid number of operands!");
1776 assert(isImm() && "Not an immediate!");
1777
1778 // If we have an immediate that's not a constant, treat it as a label
1779 // reference needing a fixup.
1780 if (!isa<MCConstantExpr>(getImm())) {
1781 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1782 return;
1783 }
1784
1785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1786 int Val = CE->getValue();
1787 Inst.addOperand(MCOperand::CreateImm(Val));
1788 }
1789
Jim Grosbacha95ec992011-10-11 17:29:55 +00001790 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1791 assert(N == 2 && "Invalid number of operands!");
1792 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1793 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1794 }
1795
Jim Grosbachd3595712011-08-03 23:50:40 +00001796 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1797 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001798 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1799 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001800 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1801 // Special case for #-0
1802 if (Val == INT32_MIN) Val = 0;
1803 if (Val < 0) Val = -Val;
1804 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1805 } else {
1806 // For register offset, we encode the shift type and negation flag
1807 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001808 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1809 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001810 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001811 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1812 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001813 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001814 }
1815
Jim Grosbachcd17c122011-08-04 23:01:30 +00001816 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1817 assert(N == 2 && "Invalid number of operands!");
1818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1819 assert(CE && "non-constant AM2OffsetImm operand!");
1820 int32_t Val = CE->getValue();
1821 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1822 // Special case for #-0
1823 if (Val == INT32_MIN) Val = 0;
1824 if (Val < 0) Val = -Val;
1825 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1826 Inst.addOperand(MCOperand::CreateReg(0));
1827 Inst.addOperand(MCOperand::CreateImm(Val));
1828 }
1829
Jim Grosbach5b96b802011-08-10 20:29:19 +00001830 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1831 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001832 // If we have an immediate that's not a constant, treat it as a label
1833 // reference needing a fixup. If it is a constant, it's something else
1834 // and we reject it.
1835 if (isImm()) {
1836 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1837 Inst.addOperand(MCOperand::CreateReg(0));
1838 Inst.addOperand(MCOperand::CreateImm(0));
1839 return;
1840 }
1841
Jim Grosbach871dff72011-10-11 15:59:20 +00001842 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1843 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001844 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1845 // Special case for #-0
1846 if (Val == INT32_MIN) Val = 0;
1847 if (Val < 0) Val = -Val;
1848 Val = ARM_AM::getAM3Opc(AddSub, Val);
1849 } else {
1850 // For register offset, we encode the shift type and negation flag
1851 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001852 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001853 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001854 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1855 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001856 Inst.addOperand(MCOperand::CreateImm(Val));
1857 }
1858
1859 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1860 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001861 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001862 int32_t Val =
1863 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1864 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1865 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001866 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001867 }
1868
1869 // Constant offset.
1870 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1871 int32_t Val = CE->getValue();
1872 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1873 // Special case for #-0
1874 if (Val == INT32_MIN) Val = 0;
1875 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001876 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001877 Inst.addOperand(MCOperand::CreateReg(0));
1878 Inst.addOperand(MCOperand::CreateImm(Val));
1879 }
1880
Jim Grosbachd3595712011-08-03 23:50:40 +00001881 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1882 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001883 // If we have an immediate that's not a constant, treat it as a label
1884 // reference needing a fixup. If it is a constant, it's something else
1885 // and we reject it.
1886 if (isImm()) {
1887 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1888 Inst.addOperand(MCOperand::CreateImm(0));
1889 return;
1890 }
1891
Jim Grosbachd3595712011-08-03 23:50:40 +00001892 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001893 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001894 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1895 // Special case for #-0
1896 if (Val == INT32_MIN) Val = 0;
1897 if (Val < 0) Val = -Val;
1898 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001899 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001900 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001901 }
1902
Jim Grosbach7db8d692011-09-08 22:07:06 +00001903 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1904 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001905 // If we have an immediate that's not a constant, treat it as a label
1906 // reference needing a fixup. If it is a constant, it's something else
1907 // and we reject it.
1908 if (isImm()) {
1909 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1910 Inst.addOperand(MCOperand::CreateImm(0));
1911 return;
1912 }
1913
Jim Grosbach871dff72011-10-11 15:59:20 +00001914 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1915 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001916 Inst.addOperand(MCOperand::CreateImm(Val));
1917 }
1918
Jim Grosbacha05627e2011-09-09 18:37:27 +00001919 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1920 assert(N == 2 && "Invalid number of operands!");
1921 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001922 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1923 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001924 Inst.addOperand(MCOperand::CreateImm(Val));
1925 }
1926
Jim Grosbachd3595712011-08-03 23:50:40 +00001927 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1928 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001929 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1930 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001931 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001932 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001933
Jim Grosbach2392c532011-09-07 23:39:14 +00001934 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1935 addMemImm8OffsetOperands(Inst, N);
1936 }
1937
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001938 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001939 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001940 }
1941
1942 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1943 assert(N == 2 && "Invalid number of operands!");
1944 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001945 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001946 addExpr(Inst, getImm());
1947 Inst.addOperand(MCOperand::CreateImm(0));
1948 return;
1949 }
1950
1951 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001952 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1953 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001954 Inst.addOperand(MCOperand::CreateImm(Val));
1955 }
1956
Jim Grosbachd3595712011-08-03 23:50:40 +00001957 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1958 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001959 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001960 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001961 addExpr(Inst, getImm());
1962 Inst.addOperand(MCOperand::CreateImm(0));
1963 return;
1964 }
1965
1966 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001967 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1968 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001969 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001970 }
Bill Wendling811c9362010-11-30 07:44:32 +00001971
Jim Grosbach05541f42011-09-19 22:21:13 +00001972 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1973 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001974 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1975 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001976 }
1977
1978 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1979 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001980 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1981 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001982 }
1983
Jim Grosbachd3595712011-08-03 23:50:40 +00001984 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1985 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001986 unsigned Val =
1987 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1988 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001989 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1990 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001991 Inst.addOperand(MCOperand::CreateImm(Val));
1992 }
1993
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001994 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1995 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001996 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1997 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1998 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001999 }
2000
Jim Grosbachd3595712011-08-03 23:50:40 +00002001 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2002 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002003 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2004 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002005 }
2006
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002007 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2008 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002009 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2010 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002011 Inst.addOperand(MCOperand::CreateImm(Val));
2012 }
2013
Jim Grosbach26d35872011-08-19 18:55:51 +00002014 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2015 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002016 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2017 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002018 Inst.addOperand(MCOperand::CreateImm(Val));
2019 }
2020
Jim Grosbacha32c7532011-08-19 18:49:59 +00002021 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2022 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002023 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2024 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002025 Inst.addOperand(MCOperand::CreateImm(Val));
2026 }
2027
Jim Grosbach23983d62011-08-19 18:13:48 +00002028 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2029 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002030 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2031 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002032 Inst.addOperand(MCOperand::CreateImm(Val));
2033 }
2034
Jim Grosbachd3595712011-08-03 23:50:40 +00002035 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2036 assert(N == 1 && "Invalid number of operands!");
2037 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2038 assert(CE && "non-constant post-idx-imm8 operand!");
2039 int Imm = CE->getValue();
2040 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002041 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002042 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2043 Inst.addOperand(MCOperand::CreateImm(Imm));
2044 }
2045
Jim Grosbach93981412011-10-11 21:55:36 +00002046 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2047 assert(N == 1 && "Invalid number of operands!");
2048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2049 assert(CE && "non-constant post-idx-imm8s4 operand!");
2050 int Imm = CE->getValue();
2051 bool isAdd = Imm >= 0;
2052 if (Imm == INT32_MIN) Imm = 0;
2053 // Immediate is scaled by 4.
2054 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2055 Inst.addOperand(MCOperand::CreateImm(Imm));
2056 }
2057
Jim Grosbachd3595712011-08-03 23:50:40 +00002058 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2059 assert(N == 2 && "Invalid number of operands!");
2060 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002061 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2062 }
2063
2064 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2065 assert(N == 2 && "Invalid number of operands!");
2066 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2067 // The sign, shift type, and shift amount are encoded in a single operand
2068 // using the AM2 encoding helpers.
2069 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2070 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2071 PostIdxReg.ShiftTy);
2072 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002073 }
2074
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002075 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2076 assert(N == 1 && "Invalid number of operands!");
2077 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2078 }
2079
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002080 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2081 assert(N == 1 && "Invalid number of operands!");
2082 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2083 }
2084
Jim Grosbach182b6a02011-11-29 23:51:09 +00002085 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002086 assert(N == 1 && "Invalid number of operands!");
2087 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2088 }
2089
Jim Grosbach04945c42011-12-02 00:35:16 +00002090 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2091 assert(N == 2 && "Invalid number of operands!");
2092 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2093 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2094 }
2095
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002096 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2097 assert(N == 1 && "Invalid number of operands!");
2098 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2099 }
2100
2101 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2102 assert(N == 1 && "Invalid number of operands!");
2103 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2104 }
2105
2106 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2107 assert(N == 1 && "Invalid number of operands!");
2108 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2109 }
2110
Jim Grosbach741cd732011-10-17 22:26:03 +00002111 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 1 && "Invalid number of operands!");
2113 // The immediate encodes the type of constant as well as the value.
2114 // Mask in that this is an i8 splat.
2115 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2116 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2117 }
2118
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002119 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2120 assert(N == 1 && "Invalid number of operands!");
2121 // The immediate encodes the type of constant as well as the value.
2122 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2123 unsigned Value = CE->getValue();
2124 if (Value >= 256)
2125 Value = (Value >> 8) | 0xa00;
2126 else
2127 Value |= 0x800;
2128 Inst.addOperand(MCOperand::CreateImm(Value));
2129 }
2130
Jim Grosbach8211c052011-10-18 00:22:00 +00002131 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2132 assert(N == 1 && "Invalid number of operands!");
2133 // The immediate encodes the type of constant as well as the value.
2134 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2135 unsigned Value = CE->getValue();
2136 if (Value >= 256 && Value <= 0xff00)
2137 Value = (Value >> 8) | 0x200;
2138 else if (Value > 0xffff && Value <= 0xff0000)
2139 Value = (Value >> 16) | 0x400;
2140 else if (Value > 0xffffff)
2141 Value = (Value >> 24) | 0x600;
2142 Inst.addOperand(MCOperand::CreateImm(Value));
2143 }
2144
2145 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2146 assert(N == 1 && "Invalid number of operands!");
2147 // The immediate encodes the type of constant as well as the value.
2148 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2149 unsigned Value = CE->getValue();
2150 if (Value >= 256 && Value <= 0xffff)
2151 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2152 else if (Value > 0xffff && Value <= 0xffffff)
2153 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2154 else if (Value > 0xffffff)
2155 Value = (Value >> 24) | 0x600;
2156 Inst.addOperand(MCOperand::CreateImm(Value));
2157 }
2158
Jim Grosbach045b6c72011-12-19 23:51:07 +00002159 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2160 assert(N == 1 && "Invalid number of operands!");
2161 // The immediate encodes the type of constant as well as the value.
2162 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2163 unsigned Value = ~CE->getValue();
2164 if (Value >= 256 && Value <= 0xffff)
2165 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2166 else if (Value > 0xffff && Value <= 0xffffff)
2167 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2168 else if (Value > 0xffffff)
2169 Value = (Value >> 24) | 0x600;
2170 Inst.addOperand(MCOperand::CreateImm(Value));
2171 }
2172
Jim Grosbache4454e02011-10-18 16:18:11 +00002173 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2174 assert(N == 1 && "Invalid number of operands!");
2175 // The immediate encodes the type of constant as well as the value.
2176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2177 uint64_t Value = CE->getValue();
2178 unsigned Imm = 0;
2179 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2180 Imm |= (Value & 1) << i;
2181 }
2182 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2183 }
2184
Jim Grosbach602aa902011-07-13 15:34:57 +00002185 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002186
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002187 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002188 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002189 Op->ITMask.Mask = Mask;
2190 Op->StartLoc = S;
2191 Op->EndLoc = S;
2192 return Op;
2193 }
2194
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002195 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002196 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002197 Op->CC.Val = CC;
2198 Op->StartLoc = S;
2199 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002200 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002201 }
2202
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002203 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002204 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002205 Op->Cop.Val = CopVal;
2206 Op->StartLoc = S;
2207 Op->EndLoc = S;
2208 return Op;
2209 }
2210
2211 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002212 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002213 Op->Cop.Val = CopVal;
2214 Op->StartLoc = S;
2215 Op->EndLoc = S;
2216 return Op;
2217 }
2218
Jim Grosbach48399582011-10-12 17:34:41 +00002219 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2220 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2221 Op->Cop.Val = Val;
2222 Op->StartLoc = S;
2223 Op->EndLoc = E;
2224 return Op;
2225 }
2226
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002227 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002228 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002229 Op->Reg.RegNum = RegNum;
2230 Op->StartLoc = S;
2231 Op->EndLoc = S;
2232 return Op;
2233 }
2234
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002235 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002236 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002237 Op->Tok.Data = Str.data();
2238 Op->Tok.Length = Str.size();
2239 Op->StartLoc = S;
2240 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002241 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002242 }
2243
Bill Wendling2063b842010-11-18 23:43:05 +00002244 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002245 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002246 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002247 Op->StartLoc = S;
2248 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002249 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002250 }
2251
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002252 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2253 unsigned SrcReg,
2254 unsigned ShiftReg,
2255 unsigned ShiftImm,
2256 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002257 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002258 Op->RegShiftedReg.ShiftTy = ShTy;
2259 Op->RegShiftedReg.SrcReg = SrcReg;
2260 Op->RegShiftedReg.ShiftReg = ShiftReg;
2261 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002262 Op->StartLoc = S;
2263 Op->EndLoc = E;
2264 return Op;
2265 }
2266
Owen Andersonb595ed02011-07-21 18:54:16 +00002267 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2268 unsigned SrcReg,
2269 unsigned ShiftImm,
2270 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002271 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002272 Op->RegShiftedImm.ShiftTy = ShTy;
2273 Op->RegShiftedImm.SrcReg = SrcReg;
2274 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002275 Op->StartLoc = S;
2276 Op->EndLoc = E;
2277 return Op;
2278 }
2279
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002280 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002281 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002282 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002283 Op->ShifterImm.isASR = isASR;
2284 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002285 Op->StartLoc = S;
2286 Op->EndLoc = E;
2287 return Op;
2288 }
2289
Jim Grosbach833b9d32011-07-27 20:15:40 +00002290 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002291 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002292 Op->RotImm.Imm = Imm;
2293 Op->StartLoc = S;
2294 Op->EndLoc = E;
2295 return Op;
2296 }
2297
Jim Grosbach864b6092011-07-28 21:34:26 +00002298 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2299 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002300 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002301 Op->Bitfield.LSB = LSB;
2302 Op->Bitfield.Width = Width;
2303 Op->StartLoc = S;
2304 Op->EndLoc = E;
2305 return Op;
2306 }
2307
Bill Wendling2cae3272010-11-09 22:44:22 +00002308 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002309 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002310 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002311 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002312 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002313
Chad Rosierfa705ee2013-07-01 20:49:23 +00002314 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002315 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002316 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002317 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002318 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002319
Chad Rosierfa705ee2013-07-01 20:49:23 +00002320 // Sort based on the register encoding values.
2321 array_pod_sort(Regs.begin(), Regs.end());
2322
Bill Wendling9898ac92010-11-17 04:32:08 +00002323 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002324 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002325 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002326 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002327 Op->StartLoc = StartLoc;
2328 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002329 return Op;
2330 }
2331
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002332 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002333 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002334 ARMOperand *Op = new ARMOperand(k_VectorList);
2335 Op->VectorList.RegNum = RegNum;
2336 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002337 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002338 Op->StartLoc = S;
2339 Op->EndLoc = E;
2340 return Op;
2341 }
2342
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002343 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002344 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002345 SMLoc S, SMLoc E) {
2346 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2347 Op->VectorList.RegNum = RegNum;
2348 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002349 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002350 Op->StartLoc = S;
2351 Op->EndLoc = E;
2352 return Op;
2353 }
2354
Jim Grosbach04945c42011-12-02 00:35:16 +00002355 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002356 unsigned Index,
2357 bool isDoubleSpaced,
2358 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002359 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2360 Op->VectorList.RegNum = RegNum;
2361 Op->VectorList.Count = Count;
2362 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002363 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002364 Op->StartLoc = S;
2365 Op->EndLoc = E;
2366 return Op;
2367 }
2368
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002369 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2370 MCContext &Ctx) {
2371 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2372 Op->VectorIndex.Val = Idx;
2373 Op->StartLoc = S;
2374 Op->EndLoc = E;
2375 return Op;
2376 }
2377
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002378 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002379 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002380 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002381 Op->StartLoc = S;
2382 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002383 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002384 }
2385
Jim Grosbachd3595712011-08-03 23:50:40 +00002386 static ARMOperand *CreateMem(unsigned BaseRegNum,
2387 const MCConstantExpr *OffsetImm,
2388 unsigned OffsetRegNum,
2389 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002390 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002391 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002392 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002393 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002394 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002395 Op->Memory.BaseRegNum = BaseRegNum;
2396 Op->Memory.OffsetImm = OffsetImm;
2397 Op->Memory.OffsetRegNum = OffsetRegNum;
2398 Op->Memory.ShiftType = ShiftType;
2399 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002400 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002401 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002402 Op->StartLoc = S;
2403 Op->EndLoc = E;
2404 return Op;
2405 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002406
Jim Grosbachc320c852011-08-05 21:28:30 +00002407 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2408 ARM_AM::ShiftOpc ShiftTy,
2409 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002410 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002411 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002412 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002413 Op->PostIdxReg.isAdd = isAdd;
2414 Op->PostIdxReg.ShiftTy = ShiftTy;
2415 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002416 Op->StartLoc = S;
2417 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002418 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002419 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002420
2421 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002422 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002423 Op->MBOpt.Val = Opt;
2424 Op->StartLoc = S;
2425 Op->EndLoc = S;
2426 return Op;
2427 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002428
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002429 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2430 SMLoc S) {
2431 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2432 Op->ISBOpt.Val = Opt;
2433 Op->StartLoc = S;
2434 Op->EndLoc = S;
2435 return Op;
2436 }
2437
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002438 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002439 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002440 Op->IFlags.Val = IFlags;
2441 Op->StartLoc = S;
2442 Op->EndLoc = S;
2443 return Op;
2444 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002445
2446 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002447 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002448 Op->MMask.Val = MMask;
2449 Op->StartLoc = S;
2450 Op->EndLoc = S;
2451 return Op;
2452 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002453};
2454
2455} // end anonymous namespace.
2456
Jim Grosbach602aa902011-07-13 15:34:57 +00002457void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002458 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002459 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002460 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002461 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002462 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002463 OS << "<ccout " << getReg() << ">";
2464 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002465 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002466 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002467 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2468 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2469 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002470 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2471 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2472 break;
2473 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002474 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002475 OS << "<coprocessor number: " << getCoproc() << ">";
2476 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002477 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002478 OS << "<coprocessor register: " << getCoproc() << ">";
2479 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002480 case k_CoprocOption:
2481 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2482 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002483 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002484 OS << "<mask: " << getMSRMask() << ">";
2485 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002486 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002487 getImm()->print(OS);
2488 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002489 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002490 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2491 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002492 case k_InstSyncBarrierOpt:
2493 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2494 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002495 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002496 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002497 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002498 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002499 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002500 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002501 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2502 << PostIdxReg.RegNum;
2503 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2504 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2505 << PostIdxReg.ShiftImm;
2506 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002507 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002508 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002509 OS << "<ARM_PROC::";
2510 unsigned IFlags = getProcIFlags();
2511 for (int i=2; i >= 0; --i)
2512 if (IFlags & (1 << i))
2513 OS << ARM_PROC::IFlagsToString(1 << i);
2514 OS << ">";
2515 break;
2516 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002517 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002518 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002519 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002520 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002521 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2522 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002523 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002524 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002525 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002526 << RegShiftedReg.SrcReg << " "
2527 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2528 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002529 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002530 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002531 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002532 << RegShiftedImm.SrcReg << " "
2533 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2534 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002535 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002536 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002537 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2538 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002539 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002540 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2541 << ", width: " << Bitfield.Width << ">";
2542 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002543 case k_RegisterList:
2544 case k_DPRRegisterList:
2545 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002546 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002547
Bill Wendlingbed94652010-11-09 23:28:44 +00002548 const SmallVectorImpl<unsigned> &RegList = getRegList();
2549 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002550 I = RegList.begin(), E = RegList.end(); I != E; ) {
2551 OS << *I;
2552 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002553 }
2554
2555 OS << ">";
2556 break;
2557 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002558 case k_VectorList:
2559 OS << "<vector_list " << VectorList.Count << " * "
2560 << VectorList.RegNum << ">";
2561 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002562 case k_VectorListAllLanes:
2563 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2564 << VectorList.RegNum << ">";
2565 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002566 case k_VectorListIndexed:
2567 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2568 << VectorList.Count << " * " << VectorList.RegNum << ">";
2569 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002570 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002571 OS << "'" << getToken() << "'";
2572 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002573 case k_VectorIndex:
2574 OS << "<vectorindex " << getVectorIndex() << ">";
2575 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002576 }
2577}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002578
2579/// @name Auto-generated Match Functions
2580/// {
2581
2582static unsigned MatchRegisterName(StringRef Name);
2583
2584/// }
2585
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002586bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2587 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002588 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002589 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002590 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002591
2592 return (RegNo == (unsigned)-1);
2593}
2594
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002595/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002596/// and if it is a register name the token is eaten and the register number is
2597/// returned. Otherwise return -1.
2598///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002599int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002600 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002601 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002602
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002603 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002604 unsigned RegNum = MatchRegisterName(lowerCase);
2605 if (!RegNum) {
2606 RegNum = StringSwitch<unsigned>(lowerCase)
2607 .Case("r13", ARM::SP)
2608 .Case("r14", ARM::LR)
2609 .Case("r15", ARM::PC)
2610 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002611 // Additional register name aliases for 'gas' compatibility.
2612 .Case("a1", ARM::R0)
2613 .Case("a2", ARM::R1)
2614 .Case("a3", ARM::R2)
2615 .Case("a4", ARM::R3)
2616 .Case("v1", ARM::R4)
2617 .Case("v2", ARM::R5)
2618 .Case("v3", ARM::R6)
2619 .Case("v4", ARM::R7)
2620 .Case("v5", ARM::R8)
2621 .Case("v6", ARM::R9)
2622 .Case("v7", ARM::R10)
2623 .Case("v8", ARM::R11)
2624 .Case("sb", ARM::R9)
2625 .Case("sl", ARM::R10)
2626 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002627 .Default(0);
2628 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002629 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002630 // Check for aliases registered via .req. Canonicalize to lower case.
2631 // That's more consistent since register names are case insensitive, and
2632 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2633 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002634 // If no match, return failure.
2635 if (Entry == RegisterReqs.end())
2636 return -1;
2637 Parser.Lex(); // Eat identifier token.
2638 return Entry->getValue();
2639 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002640
Chris Lattner44e5981c2010-10-30 04:09:10 +00002641 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002642
Chris Lattner44e5981c2010-10-30 04:09:10 +00002643 return RegNum;
2644}
Jim Grosbach99710a82010-11-01 16:44:21 +00002645
Jim Grosbachbb24c592011-07-13 18:49:30 +00002646// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2647// If a recoverable error occurs, return 1. If an irrecoverable error
2648// occurs, return -1. An irrecoverable error is one where tokens have been
2649// consumed in the process of trying to parse the shifter (i.e., when it is
2650// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002651int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002652 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2653 SMLoc S = Parser.getTok().getLoc();
2654 const AsmToken &Tok = Parser.getTok();
2655 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2656
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002657 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002658 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002659 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002660 .Case("lsl", ARM_AM::lsl)
2661 .Case("lsr", ARM_AM::lsr)
2662 .Case("asr", ARM_AM::asr)
2663 .Case("ror", ARM_AM::ror)
2664 .Case("rrx", ARM_AM::rrx)
2665 .Default(ARM_AM::no_shift);
2666
2667 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002668 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002669
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002670 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002671
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002672 // The source register for the shift has already been added to the
2673 // operand list, so we need to pop it off and combine it into the shifted
2674 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002675 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002676 if (!PrevOp->isReg())
2677 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2678 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002679
2680 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002681 int64_t Imm = 0;
2682 int ShiftReg = 0;
2683 if (ShiftTy == ARM_AM::rrx) {
2684 // RRX Doesn't have an explicit shift amount. The encoder expects
2685 // the shift register to be the same as the source register. Seems odd,
2686 // but OK.
2687 ShiftReg = SrcReg;
2688 } else {
2689 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002690 if (Parser.getTok().is(AsmToken::Hash) ||
2691 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002692 Parser.Lex(); // Eat hash.
2693 SMLoc ImmLoc = Parser.getTok().getLoc();
2694 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002695 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002696 Error(ImmLoc, "invalid immediate shift value");
2697 return -1;
2698 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002699 // The expression must be evaluatable as an immediate.
2700 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002701 if (!CE) {
2702 Error(ImmLoc, "invalid immediate shift value");
2703 return -1;
2704 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002705 // Range check the immediate.
2706 // lsl, ror: 0 <= imm <= 31
2707 // lsr, asr: 0 <= imm <= 32
2708 Imm = CE->getValue();
2709 if (Imm < 0 ||
2710 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2711 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002712 Error(ImmLoc, "immediate shift value out of range");
2713 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002714 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002715 // shift by zero is a nop. Always send it through as lsl.
2716 // ('as' compatibility)
2717 if (Imm == 0)
2718 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002719 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002720 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002721 EndLoc = Parser.getTok().getEndLoc();
2722 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002723 if (ShiftReg == -1) {
2724 Error (L, "expected immediate or register in shift operand");
2725 return -1;
2726 }
2727 } else {
2728 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002729 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002730 return -1;
2731 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002732 }
2733
Owen Andersonb595ed02011-07-21 18:54:16 +00002734 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2735 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002736 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002737 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002738 else
2739 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002740 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002741
Jim Grosbachbb24c592011-07-13 18:49:30 +00002742 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002743}
2744
2745
Bill Wendling2063b842010-11-18 23:43:05 +00002746/// Try to parse a register name. The token must be an Identifier when called.
2747/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2748/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002749///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002750/// TODO this is likely to change to allow different register types and or to
2751/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002752bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002753tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002754 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002755 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002756 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002757 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002758
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002759 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2760 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002761
Chris Lattner44e5981c2010-10-30 04:09:10 +00002762 const AsmToken &ExclaimTok = Parser.getTok();
2763 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002764 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2765 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002766 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002767 return false;
2768 }
2769
2770 // Also check for an index operand. This is only legal for vector registers,
2771 // but that'll get caught OK in operand matching, so we don't need to
2772 // explicitly filter everything else out here.
2773 if (Parser.getTok().is(AsmToken::LBrac)) {
2774 SMLoc SIdx = Parser.getTok().getLoc();
2775 Parser.Lex(); // Eat left bracket token.
2776
2777 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002778 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002779 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002780 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002781 if (!MCE)
2782 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002783
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002784 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002785 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002786
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002787 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002788 Parser.Lex(); // Eat right bracket token.
2789
2790 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2791 SIdx, E,
2792 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002793 }
2794
Bill Wendling2063b842010-11-18 23:43:05 +00002795 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002796}
2797
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002798/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2799/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2800/// "c5", ...
2801static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002802 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2803 // but efficient.
2804 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002805 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002806 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002807 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002808 return -1;
2809 switch (Name[1]) {
2810 default: return -1;
2811 case '0': return 0;
2812 case '1': return 1;
2813 case '2': return 2;
2814 case '3': return 3;
2815 case '4': return 4;
2816 case '5': return 5;
2817 case '6': return 6;
2818 case '7': return 7;
2819 case '8': return 8;
2820 case '9': return 9;
2821 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002822 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002823 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002824 return -1;
2825 switch (Name[2]) {
2826 default: return -1;
2827 case '0': return 10;
2828 case '1': return 11;
2829 case '2': return 12;
2830 case '3': return 13;
2831 case '4': return 14;
2832 case '5': return 15;
2833 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002834 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002835}
2836
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002837/// parseITCondCode - Try to parse a condition code for an IT instruction.
2838ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2839parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2840 SMLoc S = Parser.getTok().getLoc();
2841 const AsmToken &Tok = Parser.getTok();
2842 if (!Tok.is(AsmToken::Identifier))
2843 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002844 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002845 .Case("eq", ARMCC::EQ)
2846 .Case("ne", ARMCC::NE)
2847 .Case("hs", ARMCC::HS)
2848 .Case("cs", ARMCC::HS)
2849 .Case("lo", ARMCC::LO)
2850 .Case("cc", ARMCC::LO)
2851 .Case("mi", ARMCC::MI)
2852 .Case("pl", ARMCC::PL)
2853 .Case("vs", ARMCC::VS)
2854 .Case("vc", ARMCC::VC)
2855 .Case("hi", ARMCC::HI)
2856 .Case("ls", ARMCC::LS)
2857 .Case("ge", ARMCC::GE)
2858 .Case("lt", ARMCC::LT)
2859 .Case("gt", ARMCC::GT)
2860 .Case("le", ARMCC::LE)
2861 .Case("al", ARMCC::AL)
2862 .Default(~0U);
2863 if (CC == ~0U)
2864 return MatchOperand_NoMatch;
2865 Parser.Lex(); // Eat the token.
2866
2867 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2868
2869 return MatchOperand_Success;
2870}
2871
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002872/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002873/// token must be an Identifier when called, and if it is a coprocessor
2874/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002875ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002876parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002877 SMLoc S = Parser.getTok().getLoc();
2878 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002879 if (Tok.isNot(AsmToken::Identifier))
2880 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002881
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002882 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002883 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002884 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002885
2886 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002887 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002888 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002889}
2890
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002891/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002892/// token must be an Identifier when called, and if it is a coprocessor
2893/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002894ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002895parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002896 SMLoc S = Parser.getTok().getLoc();
2897 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002898 if (Tok.isNot(AsmToken::Identifier))
2899 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002900
2901 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2902 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002903 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002904
2905 Parser.Lex(); // Eat identifier token.
2906 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002907 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002908}
2909
Jim Grosbach48399582011-10-12 17:34:41 +00002910/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2911/// coproc_option : '{' imm0_255 '}'
2912ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2913parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2914 SMLoc S = Parser.getTok().getLoc();
2915
2916 // If this isn't a '{', this isn't a coprocessor immediate operand.
2917 if (Parser.getTok().isNot(AsmToken::LCurly))
2918 return MatchOperand_NoMatch;
2919 Parser.Lex(); // Eat the '{'
2920
2921 const MCExpr *Expr;
2922 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002923 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002924 Error(Loc, "illegal expression");
2925 return MatchOperand_ParseFail;
2926 }
2927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2928 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2929 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2930 return MatchOperand_ParseFail;
2931 }
2932 int Val = CE->getValue();
2933
2934 // Check for and consume the closing '}'
2935 if (Parser.getTok().isNot(AsmToken::RCurly))
2936 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002937 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002938 Parser.Lex(); // Eat the '}'
2939
2940 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2941 return MatchOperand_Success;
2942}
2943
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002944// For register list parsing, we need to map from raw GPR register numbering
2945// to the enumeration values. The enumeration values aren't sorted by
2946// register number due to our using "sp", "lr" and "pc" as canonical names.
2947static unsigned getNextRegister(unsigned Reg) {
2948 // If this is a GPR, we need to do it manually, otherwise we can rely
2949 // on the sort ordering of the enumeration since the other reg-classes
2950 // are sane.
2951 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2952 return Reg + 1;
2953 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002954 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002955 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2956 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2957 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2958 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2959 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2960 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2961 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2962 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2963 }
2964}
2965
Jim Grosbach85a23432011-11-11 21:27:40 +00002966// Return the low-subreg of a given Q register.
2967static unsigned getDRegFromQReg(unsigned QReg) {
2968 switch (QReg) {
2969 default: llvm_unreachable("expected a Q register!");
2970 case ARM::Q0: return ARM::D0;
2971 case ARM::Q1: return ARM::D2;
2972 case ARM::Q2: return ARM::D4;
2973 case ARM::Q3: return ARM::D6;
2974 case ARM::Q4: return ARM::D8;
2975 case ARM::Q5: return ARM::D10;
2976 case ARM::Q6: return ARM::D12;
2977 case ARM::Q7: return ARM::D14;
2978 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002979 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002980 case ARM::Q10: return ARM::D20;
2981 case ARM::Q11: return ARM::D22;
2982 case ARM::Q12: return ARM::D24;
2983 case ARM::Q13: return ARM::D26;
2984 case ARM::Q14: return ARM::D28;
2985 case ARM::Q15: return ARM::D30;
2986 }
2987}
2988
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002989/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002990bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002991parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002992 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002993 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00002994 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002995 Parser.Lex(); // Eat '{' token.
2996 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00002997
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002998 // Check the first register in the list to see what register class
2999 // this is a list of.
3000 int Reg = tryParseRegister();
3001 if (Reg == -1)
3002 return Error(RegLoc, "register expected");
3003
Jim Grosbach85a23432011-11-11 21:27:40 +00003004 // The reglist instructions have at most 16 registers, so reserve
3005 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003006 int EReg = 0;
3007 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003008
3009 // Allow Q regs and just interpret them as the two D sub-registers.
3010 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3011 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003012 EReg = MRI->getEncodingValue(Reg);
3013 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003014 ++Reg;
3015 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003016 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003017 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3018 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3019 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3020 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3021 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3022 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3023 else
3024 return Error(RegLoc, "invalid register in register list");
3025
Jim Grosbach85a23432011-11-11 21:27:40 +00003026 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003027 EReg = MRI->getEncodingValue(Reg);
3028 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003029
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003030 // This starts immediately after the first register token in the list,
3031 // so we can see either a comma or a minus (range separator) as a legal
3032 // next token.
3033 while (Parser.getTok().is(AsmToken::Comma) ||
3034 Parser.getTok().is(AsmToken::Minus)) {
3035 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003036 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003037 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003038 int EndReg = tryParseRegister();
3039 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003040 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003041 // Allow Q regs and just interpret them as the two D sub-registers.
3042 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3043 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003044 // If the register is the same as the start reg, there's nothing
3045 // more to do.
3046 if (Reg == EndReg)
3047 continue;
3048 // The register must be in the same register class as the first.
3049 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003050 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003051 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003052 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003053 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003054
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003055 // Add all the registers in the range to the register list.
3056 while (Reg != EndReg) {
3057 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003058 EReg = MRI->getEncodingValue(Reg);
3059 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003060 }
3061 continue;
3062 }
3063 Parser.Lex(); // Eat the comma.
3064 RegLoc = Parser.getTok().getLoc();
3065 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003066 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003067 Reg = tryParseRegister();
3068 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003069 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003070 // Allow Q regs and just interpret them as the two D sub-registers.
3071 bool isQReg = false;
3072 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3073 Reg = getDRegFromQReg(Reg);
3074 isQReg = true;
3075 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003076 // The register must be in the same register class as the first.
3077 if (!RC->contains(Reg))
3078 return Error(RegLoc, "invalid register in register list");
3079 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003080 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003081 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3082 Warning(RegLoc, "register list not in ascending order");
3083 else
3084 return Error(RegLoc, "register list not in ascending order");
3085 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003086 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003087 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3088 ") in register list");
3089 continue;
3090 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003091 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003092 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3093 Reg != OldReg + 1)
3094 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003095 EReg = MRI->getEncodingValue(Reg);
3096 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3097 if (isQReg) {
3098 EReg = MRI->getEncodingValue(++Reg);
3099 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3100 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003101 }
3102
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003103 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003104 return Error(Parser.getTok().getLoc(), "'}' expected");
3105 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003106 Parser.Lex(); // Eat '}' token.
3107
Jim Grosbach18bf3632011-12-13 21:48:29 +00003108 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003109 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003110
3111 // The ARM system instruction variants for LDM/STM have a '^' token here.
3112 if (Parser.getTok().is(AsmToken::Caret)) {
3113 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3114 Parser.Lex(); // Eat '^' token.
3115 }
3116
Bill Wendling2063b842010-11-18 23:43:05 +00003117 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003118}
3119
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003120// Helper function to parse the lane index for vector lists.
3121ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003122parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003123 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003124 if (Parser.getTok().is(AsmToken::LBrac)) {
3125 Parser.Lex(); // Eat the '['.
3126 if (Parser.getTok().is(AsmToken::RBrac)) {
3127 // "Dn[]" is the 'all lanes' syntax.
3128 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003129 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003130 Parser.Lex(); // Eat the ']'.
3131 return MatchOperand_Success;
3132 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003133
3134 // There's an optional '#' token here. Normally there wouldn't be, but
3135 // inline assemble puts one in, and it's friendly to accept that.
3136 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003137 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003138
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003139 const MCExpr *LaneIndex;
3140 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003141 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003142 Error(Loc, "illegal expression");
3143 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003144 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003145 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3146 if (!CE) {
3147 Error(Loc, "lane index must be empty or an integer");
3148 return MatchOperand_ParseFail;
3149 }
3150 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3151 Error(Parser.getTok().getLoc(), "']' expected");
3152 return MatchOperand_ParseFail;
3153 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003154 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003155 Parser.Lex(); // Eat the ']'.
3156 int64_t Val = CE->getValue();
3157
3158 // FIXME: Make this range check context sensitive for .8, .16, .32.
3159 if (Val < 0 || Val > 7) {
3160 Error(Parser.getTok().getLoc(), "lane index out of range");
3161 return MatchOperand_ParseFail;
3162 }
3163 Index = Val;
3164 LaneKind = IndexedLane;
3165 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003166 }
3167 LaneKind = NoLanes;
3168 return MatchOperand_Success;
3169}
3170
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003171// parse a vector register list
3172ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3173parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003174 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003175 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003176 SMLoc S = Parser.getTok().getLoc();
3177 // As an extension (to match gas), support a plain D register or Q register
3178 // (without encosing curly braces) as a single or double entry list,
3179 // respectively.
3180 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003181 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003182 int Reg = tryParseRegister();
3183 if (Reg == -1)
3184 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003185 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003186 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003187 if (Res != MatchOperand_Success)
3188 return Res;
3189 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003190 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003191 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003192 break;
3193 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003194 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3195 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003196 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003197 case IndexedLane:
3198 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003199 LaneIndex,
3200 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003201 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003202 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003203 return MatchOperand_Success;
3204 }
3205 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3206 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003207 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003208 if (Res != MatchOperand_Success)
3209 return Res;
3210 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003211 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003212 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003213 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003214 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003215 break;
3216 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003217 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3218 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003219 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3220 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003221 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003222 case IndexedLane:
3223 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003224 LaneIndex,
3225 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003226 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003227 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003228 return MatchOperand_Success;
3229 }
3230 Error(S, "vector register expected");
3231 return MatchOperand_ParseFail;
3232 }
3233
3234 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003235 return MatchOperand_NoMatch;
3236
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003237 Parser.Lex(); // Eat '{' token.
3238 SMLoc RegLoc = Parser.getTok().getLoc();
3239
3240 int Reg = tryParseRegister();
3241 if (Reg == -1) {
3242 Error(RegLoc, "register expected");
3243 return MatchOperand_ParseFail;
3244 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003245 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003246 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003247 unsigned FirstReg = Reg;
3248 // The list is of D registers, but we also allow Q regs and just interpret
3249 // them as the two D sub-registers.
3250 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3251 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003252 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3253 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003254 ++Reg;
3255 ++Count;
3256 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003257
3258 SMLoc E;
3259 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003260 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003261
Jim Grosbache891fe82011-11-15 23:19:15 +00003262 while (Parser.getTok().is(AsmToken::Comma) ||
3263 Parser.getTok().is(AsmToken::Minus)) {
3264 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003265 if (!Spacing)
3266 Spacing = 1; // Register range implies a single spaced list.
3267 else if (Spacing == 2) {
3268 Error(Parser.getTok().getLoc(),
3269 "sequential registers in double spaced list");
3270 return MatchOperand_ParseFail;
3271 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003272 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003273 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003274 int EndReg = tryParseRegister();
3275 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003276 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003277 return MatchOperand_ParseFail;
3278 }
3279 // Allow Q regs and just interpret them as the two D sub-registers.
3280 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3281 EndReg = getDRegFromQReg(EndReg) + 1;
3282 // If the register is the same as the start reg, there's nothing
3283 // more to do.
3284 if (Reg == EndReg)
3285 continue;
3286 // The register must be in the same register class as the first.
3287 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003288 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003289 return MatchOperand_ParseFail;
3290 }
3291 // Ranges must go from low to high.
3292 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003293 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003294 return MatchOperand_ParseFail;
3295 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003296 // Parse the lane specifier if present.
3297 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003298 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003299 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3300 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003301 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003302 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003303 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003304 return MatchOperand_ParseFail;
3305 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003306
3307 // Add all the registers in the range to the register list.
3308 Count += EndReg - Reg;
3309 Reg = EndReg;
3310 continue;
3311 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003312 Parser.Lex(); // Eat the comma.
3313 RegLoc = Parser.getTok().getLoc();
3314 int OldReg = Reg;
3315 Reg = tryParseRegister();
3316 if (Reg == -1) {
3317 Error(RegLoc, "register expected");
3318 return MatchOperand_ParseFail;
3319 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003320 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003321 // It's OK to use the enumeration values directly here rather, as the
3322 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003323 //
3324 // The list is of D registers, but we also allow Q regs and just interpret
3325 // them as the two D sub-registers.
3326 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003327 if (!Spacing)
3328 Spacing = 1; // Register range implies a single spaced list.
3329 else if (Spacing == 2) {
3330 Error(RegLoc,
3331 "invalid register in double-spaced list (must be 'D' register')");
3332 return MatchOperand_ParseFail;
3333 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003334 Reg = getDRegFromQReg(Reg);
3335 if (Reg != OldReg + 1) {
3336 Error(RegLoc, "non-contiguous register range");
3337 return MatchOperand_ParseFail;
3338 }
3339 ++Reg;
3340 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003341 // Parse the lane specifier if present.
3342 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003343 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003344 SMLoc LaneLoc = Parser.getTok().getLoc();
3345 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3346 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003347 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003348 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003349 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003350 return MatchOperand_ParseFail;
3351 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003352 continue;
3353 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003354 // Normal D register.
3355 // Figure out the register spacing (single or double) of the list if
3356 // we don't know it already.
3357 if (!Spacing)
3358 Spacing = 1 + (Reg == OldReg + 2);
3359
3360 // Just check that it's contiguous and keep going.
3361 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003362 Error(RegLoc, "non-contiguous register range");
3363 return MatchOperand_ParseFail;
3364 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003365 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003366 // Parse the lane specifier if present.
3367 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003368 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003369 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003370 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003371 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003372 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003373 Error(EndLoc, "mismatched lane index in register list");
3374 return MatchOperand_ParseFail;
3375 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003376 }
3377
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003378 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003379 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003380 return MatchOperand_ParseFail;
3381 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003382 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003383 Parser.Lex(); // Eat '}' token.
3384
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003385 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003386 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003387 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003388 // composite register classes.
3389 if (Count == 2) {
3390 const MCRegisterClass *RC = (Spacing == 1) ?
3391 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3392 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3393 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3394 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003395
Jim Grosbach2f50e922011-12-15 21:44:33 +00003396 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3397 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003398 break;
3399 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003400 // Two-register operands have been converted to the
3401 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003402 if (Count == 2) {
3403 const MCRegisterClass *RC = (Spacing == 1) ?
3404 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3405 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003406 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3407 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003408 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003409 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003410 S, E));
3411 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003412 case IndexedLane:
3413 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003414 LaneIndex,
3415 (Spacing == 2),
3416 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003417 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003418 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003419 return MatchOperand_Success;
3420}
3421
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003422/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003423ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003424parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003425 SMLoc S = Parser.getTok().getLoc();
3426 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003427 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003428
Jiangning Liu288e1af2012-08-02 08:21:27 +00003429 if (Tok.is(AsmToken::Identifier)) {
3430 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003431
Jiangning Liu288e1af2012-08-02 08:21:27 +00003432 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3433 .Case("sy", ARM_MB::SY)
3434 .Case("st", ARM_MB::ST)
3435 .Case("sh", ARM_MB::ISH)
3436 .Case("ish", ARM_MB::ISH)
3437 .Case("shst", ARM_MB::ISHST)
3438 .Case("ishst", ARM_MB::ISHST)
3439 .Case("nsh", ARM_MB::NSH)
3440 .Case("un", ARM_MB::NSH)
3441 .Case("nshst", ARM_MB::NSHST)
3442 .Case("unst", ARM_MB::NSHST)
3443 .Case("osh", ARM_MB::OSH)
3444 .Case("oshst", ARM_MB::OSHST)
3445 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003446
Jiangning Liu288e1af2012-08-02 08:21:27 +00003447 if (Opt == ~0U)
3448 return MatchOperand_NoMatch;
3449
3450 Parser.Lex(); // Eat identifier token.
3451 } else if (Tok.is(AsmToken::Hash) ||
3452 Tok.is(AsmToken::Dollar) ||
3453 Tok.is(AsmToken::Integer)) {
3454 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003455 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003456 SMLoc Loc = Parser.getTok().getLoc();
3457
3458 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003459 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003460 Error(Loc, "illegal expression");
3461 return MatchOperand_ParseFail;
3462 }
3463
3464 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3465 if (!CE) {
3466 Error(Loc, "constant expression expected");
3467 return MatchOperand_ParseFail;
3468 }
3469
3470 int Val = CE->getValue();
3471 if (Val & ~0xf) {
3472 Error(Loc, "immediate value out of range");
3473 return MatchOperand_ParseFail;
3474 }
3475
3476 Opt = ARM_MB::RESERVED_0 + Val;
3477 } else
3478 return MatchOperand_ParseFail;
3479
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003480 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003481 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003482}
3483
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003484/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3485ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3486parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3487 SMLoc S = Parser.getTok().getLoc();
3488 const AsmToken &Tok = Parser.getTok();
3489 unsigned Opt;
3490
3491 if (Tok.is(AsmToken::Identifier)) {
3492 StringRef OptStr = Tok.getString();
3493
3494 if (OptStr.lower() == "sy")
3495 Opt = ARM_ISB::SY;
3496 else
3497 return MatchOperand_NoMatch;
3498
3499 Parser.Lex(); // Eat identifier token.
3500 } else if (Tok.is(AsmToken::Hash) ||
3501 Tok.is(AsmToken::Dollar) ||
3502 Tok.is(AsmToken::Integer)) {
3503 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003504 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003505 SMLoc Loc = Parser.getTok().getLoc();
3506
3507 const MCExpr *ISBarrierID;
3508 if (getParser().parseExpression(ISBarrierID)) {
3509 Error(Loc, "illegal expression");
3510 return MatchOperand_ParseFail;
3511 }
3512
3513 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3514 if (!CE) {
3515 Error(Loc, "constant expression expected");
3516 return MatchOperand_ParseFail;
3517 }
3518
3519 int Val = CE->getValue();
3520 if (Val & ~0xf) {
3521 Error(Loc, "immediate value out of range");
3522 return MatchOperand_ParseFail;
3523 }
3524
3525 Opt = ARM_ISB::RESERVED_0 + Val;
3526 } else
3527 return MatchOperand_ParseFail;
3528
3529 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3530 (ARM_ISB::InstSyncBOpt)Opt, S));
3531 return MatchOperand_Success;
3532}
3533
3534
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003535/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003536ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003537parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003538 SMLoc S = Parser.getTok().getLoc();
3539 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003540 if (!Tok.is(AsmToken::Identifier))
3541 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003542 StringRef IFlagsStr = Tok.getString();
3543
Owen Anderson10c5b122011-10-05 17:16:40 +00003544 // An iflags string of "none" is interpreted to mean that none of the AIF
3545 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003546 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003547 if (IFlagsStr != "none") {
3548 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3549 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3550 .Case("a", ARM_PROC::A)
3551 .Case("i", ARM_PROC::I)
3552 .Case("f", ARM_PROC::F)
3553 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003554
Owen Anderson10c5b122011-10-05 17:16:40 +00003555 // If some specific iflag is already set, it means that some letter is
3556 // present more than once, this is not acceptable.
3557 if (Flag == ~0U || (IFlags & Flag))
3558 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003559
Owen Anderson10c5b122011-10-05 17:16:40 +00003560 IFlags |= Flag;
3561 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003562 }
3563
3564 Parser.Lex(); // Eat identifier token.
3565 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3566 return MatchOperand_Success;
3567}
3568
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003569/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003570ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003571parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003572 SMLoc S = Parser.getTok().getLoc();
3573 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003574 if (!Tok.is(AsmToken::Identifier))
3575 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003576 StringRef Mask = Tok.getString();
3577
James Molloy21efa7d2011-09-28 14:21:38 +00003578 if (isMClass()) {
3579 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003580 std::string Name = Mask.lower();
3581 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003582 // Note: in the documentation:
3583 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3584 // for MSR APSR_nzcvq.
3585 // but we do make it an alias here. This is so to get the "mask encoding"
3586 // bits correct on MSR APSR writes.
3587 //
3588 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3589 // should really only be allowed when writing a special register. Note
3590 // they get dropped in the MRS instruction reading a special register as
3591 // the SYSm field is only 8 bits.
3592 //
3593 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3594 // includes the DSP extension but that is not checked.
3595 .Case("apsr", 0x800)
3596 .Case("apsr_nzcvq", 0x800)
3597 .Case("apsr_g", 0x400)
3598 .Case("apsr_nzcvqg", 0xc00)
3599 .Case("iapsr", 0x801)
3600 .Case("iapsr_nzcvq", 0x801)
3601 .Case("iapsr_g", 0x401)
3602 .Case("iapsr_nzcvqg", 0xc01)
3603 .Case("eapsr", 0x802)
3604 .Case("eapsr_nzcvq", 0x802)
3605 .Case("eapsr_g", 0x402)
3606 .Case("eapsr_nzcvqg", 0xc02)
3607 .Case("xpsr", 0x803)
3608 .Case("xpsr_nzcvq", 0x803)
3609 .Case("xpsr_g", 0x403)
3610 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003611 .Case("ipsr", 0x805)
3612 .Case("epsr", 0x806)
3613 .Case("iepsr", 0x807)
3614 .Case("msp", 0x808)
3615 .Case("psp", 0x809)
3616 .Case("primask", 0x810)
3617 .Case("basepri", 0x811)
3618 .Case("basepri_max", 0x812)
3619 .Case("faultmask", 0x813)
3620 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003621 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003622
James Molloy21efa7d2011-09-28 14:21:38 +00003623 if (FlagsVal == ~0U)
3624 return MatchOperand_NoMatch;
3625
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003626 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003627 // basepri, basepri_max and faultmask only valid for V7m.
3628 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003629
James Molloy21efa7d2011-09-28 14:21:38 +00003630 Parser.Lex(); // Eat identifier token.
3631 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3632 return MatchOperand_Success;
3633 }
3634
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003635 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3636 size_t Start = 0, Next = Mask.find('_');
3637 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003638 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003639 if (Next != StringRef::npos)
3640 Flags = Mask.slice(Next+1, Mask.size());
3641
3642 // FlagsVal contains the complete mask:
3643 // 3-0: Mask
3644 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3645 unsigned FlagsVal = 0;
3646
3647 if (SpecReg == "apsr") {
3648 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003649 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003650 .Case("g", 0x4) // same as CPSR_s
3651 .Case("nzcvqg", 0xc) // same as CPSR_fs
3652 .Default(~0U);
3653
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003654 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003655 if (!Flags.empty())
3656 return MatchOperand_NoMatch;
3657 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003658 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003659 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003660 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003661 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3662 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003663 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003664 for (int i = 0, e = Flags.size(); i != e; ++i) {
3665 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3666 .Case("c", 1)
3667 .Case("x", 2)
3668 .Case("s", 4)
3669 .Case("f", 8)
3670 .Default(~0U);
3671
3672 // If some specific flag is already set, it means that some letter is
3673 // present more than once, this is not acceptable.
3674 if (FlagsVal == ~0U || (FlagsVal & Flag))
3675 return MatchOperand_NoMatch;
3676 FlagsVal |= Flag;
3677 }
3678 } else // No match for special register.
3679 return MatchOperand_NoMatch;
3680
Owen Anderson03a173e2011-10-21 18:43:28 +00003681 // Special register without flags is NOT equivalent to "fc" flags.
3682 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3683 // two lines would enable gas compatibility at the expense of breaking
3684 // round-tripping.
3685 //
3686 // if (!FlagsVal)
3687 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003688
3689 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3690 if (SpecReg == "spsr")
3691 FlagsVal |= 16;
3692
3693 Parser.Lex(); // Eat identifier token.
3694 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3695 return MatchOperand_Success;
3696}
3697
Jim Grosbach27c1e252011-07-21 17:23:04 +00003698ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3699parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3700 int Low, int High) {
3701 const AsmToken &Tok = Parser.getTok();
3702 if (Tok.isNot(AsmToken::Identifier)) {
3703 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3704 return MatchOperand_ParseFail;
3705 }
3706 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003707 std::string LowerOp = Op.lower();
3708 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003709 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3710 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3711 return MatchOperand_ParseFail;
3712 }
3713 Parser.Lex(); // Eat shift type token.
3714
3715 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003716 if (Parser.getTok().isNot(AsmToken::Hash) &&
3717 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003718 Error(Parser.getTok().getLoc(), "'#' expected");
3719 return MatchOperand_ParseFail;
3720 }
3721 Parser.Lex(); // Eat hash token.
3722
3723 const MCExpr *ShiftAmount;
3724 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003725 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003726 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003727 Error(Loc, "illegal expression");
3728 return MatchOperand_ParseFail;
3729 }
3730 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3731 if (!CE) {
3732 Error(Loc, "constant expression expected");
3733 return MatchOperand_ParseFail;
3734 }
3735 int Val = CE->getValue();
3736 if (Val < Low || Val > High) {
3737 Error(Loc, "immediate value out of range");
3738 return MatchOperand_ParseFail;
3739 }
3740
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003741 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003742
3743 return MatchOperand_Success;
3744}
3745
Jim Grosbach0a547702011-07-22 17:44:50 +00003746ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3747parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3748 const AsmToken &Tok = Parser.getTok();
3749 SMLoc S = Tok.getLoc();
3750 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003751 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003752 return MatchOperand_ParseFail;
3753 }
Tim Northover4d141442013-05-31 15:58:45 +00003754 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003755 .Case("be", 1)
3756 .Case("le", 0)
3757 .Default(-1);
3758 Parser.Lex(); // Eat the token.
3759
3760 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003761 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003762 return MatchOperand_ParseFail;
3763 }
3764 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3765 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003766 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003767 return MatchOperand_Success;
3768}
3769
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003770/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3771/// instructions. Legal values are:
3772/// lsl #n 'n' in [0,31]
3773/// asr #n 'n' in [1,32]
3774/// n == 32 encoded as n == 0.
3775ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3776parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3777 const AsmToken &Tok = Parser.getTok();
3778 SMLoc S = Tok.getLoc();
3779 if (Tok.isNot(AsmToken::Identifier)) {
3780 Error(S, "shift operator 'asr' or 'lsl' expected");
3781 return MatchOperand_ParseFail;
3782 }
3783 StringRef ShiftName = Tok.getString();
3784 bool isASR;
3785 if (ShiftName == "lsl" || ShiftName == "LSL")
3786 isASR = false;
3787 else if (ShiftName == "asr" || ShiftName == "ASR")
3788 isASR = true;
3789 else {
3790 Error(S, "shift operator 'asr' or 'lsl' expected");
3791 return MatchOperand_ParseFail;
3792 }
3793 Parser.Lex(); // Eat the operator.
3794
3795 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003796 if (Parser.getTok().isNot(AsmToken::Hash) &&
3797 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003798 Error(Parser.getTok().getLoc(), "'#' expected");
3799 return MatchOperand_ParseFail;
3800 }
3801 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003802 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003803
3804 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003805 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003806 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003807 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003808 return MatchOperand_ParseFail;
3809 }
3810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3811 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003812 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003813 return MatchOperand_ParseFail;
3814 }
3815
3816 int64_t Val = CE->getValue();
3817 if (isASR) {
3818 // Shift amount must be in [1,32]
3819 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003820 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003821 return MatchOperand_ParseFail;
3822 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003823 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3824 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003825 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003826 return MatchOperand_ParseFail;
3827 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003828 if (Val == 32) Val = 0;
3829 } else {
3830 // Shift amount must be in [1,32]
3831 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003832 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003833 return MatchOperand_ParseFail;
3834 }
3835 }
3836
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003837 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003838
3839 return MatchOperand_Success;
3840}
3841
Jim Grosbach833b9d32011-07-27 20:15:40 +00003842/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3843/// of instructions. Legal values are:
3844/// ror #n 'n' in {0, 8, 16, 24}
3845ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3846parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3847 const AsmToken &Tok = Parser.getTok();
3848 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003849 if (Tok.isNot(AsmToken::Identifier))
3850 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003851 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003852 if (ShiftName != "ror" && ShiftName != "ROR")
3853 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003854 Parser.Lex(); // Eat the operator.
3855
3856 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003857 if (Parser.getTok().isNot(AsmToken::Hash) &&
3858 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003859 Error(Parser.getTok().getLoc(), "'#' expected");
3860 return MatchOperand_ParseFail;
3861 }
3862 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003863 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003864
3865 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003866 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003867 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003868 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003869 return MatchOperand_ParseFail;
3870 }
3871 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3872 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003873 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003874 return MatchOperand_ParseFail;
3875 }
3876
3877 int64_t Val = CE->getValue();
3878 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3879 // normally, zero is represented in asm by omitting the rotate operand
3880 // entirely.
3881 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003882 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003883 return MatchOperand_ParseFail;
3884 }
3885
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003886 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003887
3888 return MatchOperand_Success;
3889}
3890
Jim Grosbach864b6092011-07-28 21:34:26 +00003891ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3892parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3893 SMLoc S = Parser.getTok().getLoc();
3894 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003895 if (Parser.getTok().isNot(AsmToken::Hash) &&
3896 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003897 Error(Parser.getTok().getLoc(), "'#' expected");
3898 return MatchOperand_ParseFail;
3899 }
3900 Parser.Lex(); // Eat hash token.
3901
3902 const MCExpr *LSBExpr;
3903 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003904 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003905 Error(E, "malformed immediate expression");
3906 return MatchOperand_ParseFail;
3907 }
3908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3909 if (!CE) {
3910 Error(E, "'lsb' operand must be an immediate");
3911 return MatchOperand_ParseFail;
3912 }
3913
3914 int64_t LSB = CE->getValue();
3915 // The LSB must be in the range [0,31]
3916 if (LSB < 0 || LSB > 31) {
3917 Error(E, "'lsb' operand must be in the range [0,31]");
3918 return MatchOperand_ParseFail;
3919 }
3920 E = Parser.getTok().getLoc();
3921
3922 // Expect another immediate operand.
3923 if (Parser.getTok().isNot(AsmToken::Comma)) {
3924 Error(Parser.getTok().getLoc(), "too few operands");
3925 return MatchOperand_ParseFail;
3926 }
3927 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003928 if (Parser.getTok().isNot(AsmToken::Hash) &&
3929 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003930 Error(Parser.getTok().getLoc(), "'#' expected");
3931 return MatchOperand_ParseFail;
3932 }
3933 Parser.Lex(); // Eat hash token.
3934
3935 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003936 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003937 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003938 Error(E, "malformed immediate expression");
3939 return MatchOperand_ParseFail;
3940 }
3941 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3942 if (!CE) {
3943 Error(E, "'width' operand must be an immediate");
3944 return MatchOperand_ParseFail;
3945 }
3946
3947 int64_t Width = CE->getValue();
3948 // The LSB must be in the range [1,32-lsb]
3949 if (Width < 1 || Width > 32 - LSB) {
3950 Error(E, "'width' operand must be in the range [1,32-lsb]");
3951 return MatchOperand_ParseFail;
3952 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003953
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003954 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003955
3956 return MatchOperand_Success;
3957}
3958
Jim Grosbachd3595712011-08-03 23:50:40 +00003959ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3960parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3961 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003962 // postidx_reg := '+' register {, shift}
3963 // | '-' register {, shift}
3964 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003965
3966 // This method must return MatchOperand_NoMatch without consuming any tokens
3967 // in the case where there is no match, as other alternatives take other
3968 // parse methods.
3969 AsmToken Tok = Parser.getTok();
3970 SMLoc S = Tok.getLoc();
3971 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003972 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003973 if (Tok.is(AsmToken::Plus)) {
3974 Parser.Lex(); // Eat the '+' token.
3975 haveEaten = true;
3976 } else if (Tok.is(AsmToken::Minus)) {
3977 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003978 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003979 haveEaten = true;
3980 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003981
3982 SMLoc E = Parser.getTok().getEndLoc();
3983 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00003984 if (Reg == -1) {
3985 if (!haveEaten)
3986 return MatchOperand_NoMatch;
3987 Error(Parser.getTok().getLoc(), "register expected");
3988 return MatchOperand_ParseFail;
3989 }
Jim Grosbachd3595712011-08-03 23:50:40 +00003990
Jim Grosbachc320c852011-08-05 21:28:30 +00003991 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3992 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003993 if (Parser.getTok().is(AsmToken::Comma)) {
3994 Parser.Lex(); // Eat the ','.
3995 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3996 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003997
3998 // FIXME: Only approximates end...may include intervening whitespace.
3999 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004000 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004001
4002 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4003 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004004
4005 return MatchOperand_Success;
4006}
4007
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004008ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4009parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4010 // Check for a post-index addressing register operand. Specifically:
4011 // am3offset := '+' register
4012 // | '-' register
4013 // | register
4014 // | # imm
4015 // | # + imm
4016 // | # - imm
4017
4018 // This method must return MatchOperand_NoMatch without consuming any tokens
4019 // in the case where there is no match, as other alternatives take other
4020 // parse methods.
4021 AsmToken Tok = Parser.getTok();
4022 SMLoc S = Tok.getLoc();
4023
4024 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004025 if (Parser.getTok().is(AsmToken::Hash) ||
4026 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004027 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004028 // Explicitly look for a '-', as we need to encode negative zero
4029 // differently.
4030 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4031 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004032 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004033 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004034 return MatchOperand_ParseFail;
4035 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4036 if (!CE) {
4037 Error(S, "constant expression expected");
4038 return MatchOperand_ParseFail;
4039 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004040 // Negative zero is encoded as the flag value INT32_MIN.
4041 int32_t Val = CE->getValue();
4042 if (isNegative && Val == 0)
4043 Val = INT32_MIN;
4044
4045 Operands.push_back(
4046 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4047
4048 return MatchOperand_Success;
4049 }
4050
4051
4052 bool haveEaten = false;
4053 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004054 if (Tok.is(AsmToken::Plus)) {
4055 Parser.Lex(); // Eat the '+' token.
4056 haveEaten = true;
4057 } else if (Tok.is(AsmToken::Minus)) {
4058 Parser.Lex(); // Eat the '-' token.
4059 isAdd = false;
4060 haveEaten = true;
4061 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004062
4063 Tok = Parser.getTok();
4064 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004065 if (Reg == -1) {
4066 if (!haveEaten)
4067 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004068 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004069 return MatchOperand_ParseFail;
4070 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004071
4072 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004073 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004074
4075 return MatchOperand_Success;
4076}
4077
Jim Grosbach7db8d692011-09-08 22:07:06 +00004078/// cvtT2LdrdPre - Convert parsed operands to MCInst.
4079/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4080/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004081void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004082cvtT2LdrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00004083 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4084 // Rt, Rt2
4085 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4086 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4087 // Create a writeback register dummy placeholder.
4088 Inst.addOperand(MCOperand::CreateReg(0));
4089 // addr
4090 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4091 // pred
4092 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00004093}
4094
4095/// cvtT2StrdPre - Convert parsed operands to MCInst.
4096/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4097/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004098void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004099cvtT2StrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00004100 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4101 // Create a writeback register dummy placeholder.
4102 Inst.addOperand(MCOperand::CreateReg(0));
4103 // Rt, Rt2
4104 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4105 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4106 // addr
4107 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4108 // pred
4109 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00004110}
4111
Jim Grosbachc086f682011-09-08 00:39:19 +00004112/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4113/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4114/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004115void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004116cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +00004117 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4118 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4119
4120 // Create a writeback register dummy placeholder.
4121 Inst.addOperand(MCOperand::CreateImm(0));
4122
4123 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4124 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachc086f682011-09-08 00:39:19 +00004125}
4126
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004127/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4128/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4129/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004130void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004131cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004132 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4133 // Create a writeback register dummy placeholder.
4134 Inst.addOperand(MCOperand::CreateImm(0));
4135 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4136 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4137 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004138}
4139
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004140/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004141/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4142/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004143void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004144cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004145 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4146 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4147
4148 // Create a writeback register dummy placeholder.
4149 Inst.addOperand(MCOperand::CreateImm(0));
4150
Jim Grosbachd3595712011-08-03 23:50:40 +00004151 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004152 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004153}
4154
Owen Anderson16d33f32011-08-26 20:43:14 +00004155/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4156/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4157/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004158void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004159cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +00004160 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4161 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4162
4163 // Create a writeback register dummy placeholder.
4164 Inst.addOperand(MCOperand::CreateImm(0));
4165
4166 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4167 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson16d33f32011-08-26 20:43:14 +00004168}
4169
4170
Jim Grosbachd564bf32011-08-11 19:22:40 +00004171/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4172/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4173/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004174void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004175cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +00004176 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4177 // Create a writeback register dummy placeholder.
4178 Inst.addOperand(MCOperand::CreateImm(0));
4179 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4180 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4181 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd564bf32011-08-11 19:22:40 +00004182}
4183
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004184/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004185/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4186/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004187void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004188cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004189 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4190 // Create a writeback register dummy placeholder.
4191 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd564bf32011-08-11 19:22:40 +00004192 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4193 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4194 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004195}
4196
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004197/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4198/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4199/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004200void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004201cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004202 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4203 // Create a writeback register dummy placeholder.
4204 Inst.addOperand(MCOperand::CreateImm(0));
4205 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4206 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4207 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004208}
4209
Jim Grosbachd3595712011-08-03 23:50:40 +00004210/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4211/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4212/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004213void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004214cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004215 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4216 // Rt
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004217 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004218 // Create a writeback register dummy placeholder.
4219 Inst.addOperand(MCOperand::CreateImm(0));
4220 // addr
4221 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4222 // offset
4223 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4224 // pred
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004225 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004226}
4227
Jim Grosbachd3595712011-08-03 23:50:40 +00004228/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004229/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4230/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004231void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004232cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004233 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4234 // Rt
Owen Andersonb0e68992011-07-28 17:18:57 +00004235 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004236 // Create a writeback register dummy placeholder.
4237 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004238 // addr
4239 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4240 // offset
4241 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4242 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004243 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004244}
4245
Jim Grosbachd3595712011-08-03 23:50:40 +00004246/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004247/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4248/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004249void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004250cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004251 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004252 // Create a writeback register dummy placeholder.
4253 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004254 // Rt
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004255 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004256 // addr
4257 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4258 // offset
4259 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4260 // pred
4261 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004262}
4263
4264/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4265/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4266/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004267void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004268cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004269 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4270 // Create a writeback register dummy placeholder.
4271 Inst.addOperand(MCOperand::CreateImm(0));
4272 // Rt
4273 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4274 // addr
4275 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4276 // offset
4277 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4278 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004279 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004280}
4281
Jim Grosbach5b96b802011-08-10 20:29:19 +00004282/// cvtLdrdPre - Convert parsed operands to MCInst.
4283/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4284/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004285void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004286cvtLdrdPre(MCInst &Inst,
Jim Grosbach5b96b802011-08-10 20:29:19 +00004287 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4288 // Rt, Rt2
4289 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4290 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4291 // Create a writeback register dummy placeholder.
4292 Inst.addOperand(MCOperand::CreateImm(0));
4293 // addr
4294 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4295 // pred
4296 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach5b96b802011-08-10 20:29:19 +00004297}
4298
Jim Grosbacheb09f492011-08-11 20:28:23 +00004299/// cvtStrdPre - Convert parsed operands to MCInst.
4300/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4301/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004302void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004303cvtStrdPre(MCInst &Inst,
Jim Grosbacheb09f492011-08-11 20:28:23 +00004304 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4305 // Create a writeback register dummy placeholder.
4306 Inst.addOperand(MCOperand::CreateImm(0));
4307 // Rt, Rt2
4308 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4309 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4310 // addr
4311 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4312 // pred
4313 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheb09f492011-08-11 20:28:23 +00004314}
4315
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004316/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4317/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4318/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004319void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004320cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004321 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4322 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4323 // Create a writeback register dummy placeholder.
4324 Inst.addOperand(MCOperand::CreateImm(0));
4325 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4326 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004327}
4328
Chad Rosier5eec49f2012-08-30 23:00:00 +00004329/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach8e048492011-08-19 22:07:46 +00004330/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4331/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004332void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004333cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004334 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004335 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4336 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004337 // If we have a three-operand form, make sure to set Rn to be the operand
4338 // that isn't the same as Rd.
4339 unsigned RegOp = 4;
4340 if (Operands.size() == 6 &&
4341 ((ARMOperand*)Operands[4])->getReg() ==
4342 ((ARMOperand*)Operands[3])->getReg())
4343 RegOp = 5;
4344 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4345 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004346 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004347}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004348
Chad Rosier98cfa102012-08-31 00:03:31 +00004349void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004350cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004351 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4352 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004353 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004354 // Create a writeback register dummy placeholder.
4355 Inst.addOperand(MCOperand::CreateImm(0));
4356 // Vn
4357 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4358 // pred
4359 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004360}
4361
Chad Rosier98cfa102012-08-31 00:03:31 +00004362void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004363cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004364 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4365 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004366 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004367 // Create a writeback register dummy placeholder.
4368 Inst.addOperand(MCOperand::CreateImm(0));
4369 // Vn
4370 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4371 // Vm
4372 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4373 // pred
4374 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004375}
4376
Chad Rosier98cfa102012-08-31 00:03:31 +00004377void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004378cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004379 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4380 // Create a writeback register dummy placeholder.
4381 Inst.addOperand(MCOperand::CreateImm(0));
4382 // Vn
4383 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4384 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004385 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004386 // pred
4387 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004388}
4389
Chad Rosier98cfa102012-08-31 00:03:31 +00004390void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004391cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004392 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4393 // Create a writeback register dummy placeholder.
4394 Inst.addOperand(MCOperand::CreateImm(0));
4395 // Vn
4396 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4397 // Vm
4398 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4399 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004400 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004401 // pred
4402 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004403}
4404
Bill Wendlinge18980a2010-11-06 22:36:58 +00004405/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004406/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004407bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004408parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004409 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004410 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004411 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004412 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004413 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004414
Sean Callanan936b0d32010-01-19 21:44:56 +00004415 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004416 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004417 if (BaseRegNum == -1)
4418 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004419
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004420 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004421 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004422 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4423 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004424 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004425
Jim Grosbachd3595712011-08-03 23:50:40 +00004426 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004427 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004428 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004429
Jim Grosbachd3595712011-08-03 23:50:40 +00004430 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004431 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004432
Jim Grosbach40700e02011-09-19 18:42:21 +00004433 // If there's a pre-indexing writeback marker, '!', just add it as a token
4434 // operand. It's rather odd, but syntactically valid.
4435 if (Parser.getTok().is(AsmToken::Exclaim)) {
4436 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4437 Parser.Lex(); // Eat the '!'.
4438 }
4439
Jim Grosbachd3595712011-08-03 23:50:40 +00004440 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004441 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004442
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004443 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4444 "Lost colon or comma in memory operand?!");
4445 if (Tok.is(AsmToken::Comma)) {
4446 Parser.Lex(); // Eat the comma.
4447 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004448
Jim Grosbacha95ec992011-10-11 17:29:55 +00004449 // If we have a ':', it's an alignment specifier.
4450 if (Parser.getTok().is(AsmToken::Colon)) {
4451 Parser.Lex(); // Eat the ':'.
4452 E = Parser.getTok().getLoc();
4453
4454 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004455 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004456 return true;
4457
4458 // The expression has to be a constant. Memory references with relocations
4459 // don't come through here, as they use the <label> forms of the relevant
4460 // instructions.
4461 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4462 if (!CE)
4463 return Error (E, "constant expression expected");
4464
4465 unsigned Align = 0;
4466 switch (CE->getValue()) {
4467 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004468 return Error(E,
4469 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4470 case 16: Align = 2; break;
4471 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004472 case 64: Align = 8; break;
4473 case 128: Align = 16; break;
4474 case 256: Align = 32; break;
4475 }
4476
4477 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004478 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004479 return Error(Parser.getTok().getLoc(), "']' expected");
4480 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004481 Parser.Lex(); // Eat right bracket token.
4482
4483 // Don't worry about range checking the value here. That's handled by
4484 // the is*() predicates.
4485 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4486 ARM_AM::no_shift, 0, Align,
4487 false, S, E));
4488
4489 // If there's a pre-indexing writeback marker, '!', just add it as a token
4490 // operand.
4491 if (Parser.getTok().is(AsmToken::Exclaim)) {
4492 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4493 Parser.Lex(); // Eat the '!'.
4494 }
4495
4496 return false;
4497 }
4498
4499 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004500 // offset. Be friendly and also accept a plain integer (without a leading
4501 // hash) for gas compatibility.
4502 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004503 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004504 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004505 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004506 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004507 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004508
Owen Anderson967674d2011-08-29 19:36:44 +00004509 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004510 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004511 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004512 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004513
4514 // The expression has to be a constant. Memory references with relocations
4515 // don't come through here, as they use the <label> forms of the relevant
4516 // instructions.
4517 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4518 if (!CE)
4519 return Error (E, "constant expression expected");
4520
Owen Anderson967674d2011-08-29 19:36:44 +00004521 // If the constant was #-0, represent it as INT32_MIN.
4522 int32_t Val = CE->getValue();
4523 if (isNegative && Val == 0)
4524 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4525
Jim Grosbachd3595712011-08-03 23:50:40 +00004526 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004527 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004528 return Error(Parser.getTok().getLoc(), "']' expected");
4529 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004530 Parser.Lex(); // Eat right bracket token.
4531
4532 // Don't worry about range checking the value here. That's handled by
4533 // the is*() predicates.
4534 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004535 ARM_AM::no_shift, 0, 0,
4536 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004537
4538 // If there's a pre-indexing writeback marker, '!', just add it as a token
4539 // operand.
4540 if (Parser.getTok().is(AsmToken::Exclaim)) {
4541 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4542 Parser.Lex(); // Eat the '!'.
4543 }
4544
4545 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004546 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004547
4548 // The register offset is optionally preceded by a '+' or '-'
4549 bool isNegative = false;
4550 if (Parser.getTok().is(AsmToken::Minus)) {
4551 isNegative = true;
4552 Parser.Lex(); // Eat the '-'.
4553 } else if (Parser.getTok().is(AsmToken::Plus)) {
4554 // Nothing to do.
4555 Parser.Lex(); // Eat the '+'.
4556 }
4557
4558 E = Parser.getTok().getLoc();
4559 int OffsetRegNum = tryParseRegister();
4560 if (OffsetRegNum == -1)
4561 return Error(E, "register expected");
4562
4563 // If there's a shift operator, handle it.
4564 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004565 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004566 if (Parser.getTok().is(AsmToken::Comma)) {
4567 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004568 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004569 return true;
4570 }
4571
4572 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004573 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004574 return Error(Parser.getTok().getLoc(), "']' expected");
4575 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004576 Parser.Lex(); // Eat right bracket token.
4577
4578 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004579 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004580 S, E));
4581
Jim Grosbachc320c852011-08-05 21:28:30 +00004582 // If there's a pre-indexing writeback marker, '!', just add it as a token
4583 // operand.
4584 if (Parser.getTok().is(AsmToken::Exclaim)) {
4585 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4586 Parser.Lex(); // Eat the '!'.
4587 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004588
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004589 return false;
4590}
4591
Jim Grosbachd3595712011-08-03 23:50:40 +00004592/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004593/// ( lsl | lsr | asr | ror ) , # shift_amount
4594/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004595/// return true if it parses a shift otherwise it returns false.
4596bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4597 unsigned &Amount) {
4598 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004599 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004600 if (Tok.isNot(AsmToken::Identifier))
4601 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004602 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004603 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4604 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004605 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004606 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004607 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004608 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004609 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004610 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004611 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004612 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004613 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004614 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004615 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004616 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004617
Jim Grosbachd3595712011-08-03 23:50:40 +00004618 // rrx stands alone.
4619 Amount = 0;
4620 if (St != ARM_AM::rrx) {
4621 Loc = Parser.getTok().getLoc();
4622 // A '#' and a shift amount.
4623 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004624 if (HashTok.isNot(AsmToken::Hash) &&
4625 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004626 return Error(HashTok.getLoc(), "'#' expected");
4627 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004628
Jim Grosbachd3595712011-08-03 23:50:40 +00004629 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004630 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004631 return true;
4632 // Range check the immediate.
4633 // lsl, ror: 0 <= imm <= 31
4634 // lsr, asr: 0 <= imm <= 32
4635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4636 if (!CE)
4637 return Error(Loc, "shift amount must be an immediate");
4638 int64_t Imm = CE->getValue();
4639 if (Imm < 0 ||
4640 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4641 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4642 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004643 // If <ShiftTy> #0, turn it into a no_shift.
4644 if (Imm == 0)
4645 St = ARM_AM::lsl;
4646 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4647 if (Imm == 32)
4648 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004649 Amount = Imm;
4650 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004651
4652 return false;
4653}
4654
Jim Grosbache7fbce72011-10-03 23:38:36 +00004655/// parseFPImm - A floating point immediate expression operand.
4656ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4657parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004658 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004659 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004660 // integer only.
4661 //
4662 // This routine still creates a generic Immediate operand, containing
4663 // a bitcast of the 64-bit floating point value. The various operands
4664 // that accept floats can check whether the value is valid for them
4665 // via the standard is*() predicates.
4666
Jim Grosbache7fbce72011-10-03 23:38:36 +00004667 SMLoc S = Parser.getTok().getLoc();
4668
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004669 if (Parser.getTok().isNot(AsmToken::Hash) &&
4670 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004671 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004672
4673 // Disambiguate the VMOV forms that can accept an FP immediate.
4674 // vmov.f32 <sreg>, #imm
4675 // vmov.f64 <dreg>, #imm
4676 // vmov.f32 <dreg>, #imm @ vector f32x2
4677 // vmov.f32 <qreg>, #imm @ vector f32x4
4678 //
4679 // There are also the NEON VMOV instructions which expect an
4680 // integer constant. Make sure we don't try to parse an FPImm
4681 // for these:
4682 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4683 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4684 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4685 TyOp->getToken() != ".f64"))
4686 return MatchOperand_NoMatch;
4687
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004688 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004689
4690 // Handle negation, as that still comes through as a separate token.
4691 bool isNegative = false;
4692 if (Parser.getTok().is(AsmToken::Minus)) {
4693 isNegative = true;
4694 Parser.Lex();
4695 }
4696 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004697 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004698 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004699 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004700 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4701 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004702 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004703 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004704 Operands.push_back(ARMOperand::CreateImm(
4705 MCConstantExpr::Create(IntVal, getContext()),
4706 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004707 return MatchOperand_Success;
4708 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004709 // Also handle plain integers. Instructions which allow floating point
4710 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004711 if (Tok.is(AsmToken::Integer)) {
4712 int64_t Val = Tok.getIntVal();
4713 Parser.Lex(); // Eat the token.
4714 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004715 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004716 return MatchOperand_ParseFail;
4717 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004718 double RealVal = ARM_AM::getFPImmFloat(Val);
4719 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4720 Operands.push_back(ARMOperand::CreateImm(
4721 MCConstantExpr::Create(Val, getContext()), S,
4722 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004723 return MatchOperand_Success;
4724 }
4725
Jim Grosbach235c8d22012-01-19 02:47:30 +00004726 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004727 return MatchOperand_ParseFail;
4728}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004729
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004730/// Parse a arm instruction operand. For now this parses the operand regardless
4731/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004732bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004733 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004734 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004735
4736 // Check if the current operand has a custom associated parser, if so, try to
4737 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004738 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4739 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004740 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004741 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4742 // there was a match, but an error occurred, in which case, just return that
4743 // the operand parsing failed.
4744 if (ResTy == MatchOperand_ParseFail)
4745 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004746
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004747 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004748 default:
4749 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004750 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004751 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004752 // If we've seen a branch mnemonic, the next operand must be a label. This
4753 // is true even if the label is a register name. So "br r1" means branch to
4754 // label "r1".
4755 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4756 if (!ExpectLabel) {
4757 if (!tryParseRegisterWithWriteBack(Operands))
4758 return false;
4759 int Res = tryParseShiftRegister(Operands);
4760 if (Res == 0) // success
4761 return false;
4762 else if (Res == -1) // irrecoverable error
4763 return true;
4764 // If this is VMRS, check for the apsr_nzcv operand.
4765 if (Mnemonic == "vmrs" &&
4766 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4767 S = Parser.getTok().getLoc();
4768 Parser.Lex();
4769 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4770 return false;
4771 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004772 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004773
4774 // Fall though for the Identifier case that is not a register or a
4775 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004776 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004777 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004778 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004779 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004780 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004781 // This was not a register so parse other operands that start with an
4782 // identifier (like labels) as expressions and create them as immediates.
4783 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004784 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004785 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004786 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004787 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004788 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4789 return false;
4790 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004791 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004792 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004793 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004794 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004795 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004796 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004797 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004798 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004799 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004800
4801 if (Parser.getTok().isNot(AsmToken::Colon)) {
4802 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4803 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004804 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004805 return true;
4806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4807 if (CE) {
4808 int32_t Val = CE->getValue();
4809 if (isNegative && Val == 0)
4810 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4811 }
4812 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4813 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004814
4815 // There can be a trailing '!' on operands that we want as a separate
4816 // '!' Token operand. Handle that here. For example, the compatibilty
4817 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4818 if (Parser.getTok().is(AsmToken::Exclaim)) {
4819 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4820 Parser.getTok().getLoc()));
4821 Parser.Lex(); // Eat exclaim token
4822 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004823 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004824 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004825 // w/ a ':' after the '#', it's just like a plain ':'.
4826 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004827 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004828 case AsmToken::Colon: {
4829 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004830 // FIXME: Check it's an expression prefix,
4831 // e.g. (FOO - :lower16:BAR) isn't legal.
4832 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004833 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004834 return true;
4835
Evan Cheng965b3c72011-01-13 07:58:56 +00004836 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004837 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004838 return true;
4839
Evan Cheng965b3c72011-01-13 07:58:56 +00004840 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004841 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004842 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004843 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004844 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004845 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004846 }
4847}
4848
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004849// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004850// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004851bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004852 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004853
4854 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004855 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004856 Parser.Lex(); // Eat ':'
4857
4858 if (getLexer().isNot(AsmToken::Identifier)) {
4859 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4860 return true;
4861 }
4862
4863 StringRef IDVal = Parser.getTok().getIdentifier();
4864 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004865 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004866 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004867 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004868 } else {
4869 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4870 return true;
4871 }
4872 Parser.Lex();
4873
4874 if (getLexer().isNot(AsmToken::Colon)) {
4875 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4876 return true;
4877 }
4878 Parser.Lex(); // Eat the last ':'
4879 return false;
4880}
4881
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004882/// \brief Given a mnemonic, split out possible predication code and carry
4883/// setting letters to form a canonical mnemonic and flags.
4884//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004885// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004886// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004887StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004888 unsigned &PredicationCode,
4889 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004890 unsigned &ProcessorIMod,
4891 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004892 PredicationCode = ARMCC::AL;
4893 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004894 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004895
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004896 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004897 //
4898 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004899 if ((Mnemonic == "movs" && isThumb()) ||
4900 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4901 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4902 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4903 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Jim Grosbach9b81a4f2013-04-15 22:42:50 +00004904 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004905 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4906 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004907 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004908 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004909 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4910 Mnemonic == "vcvtm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004911 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004912
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004913 // First, split out any predication code. Ignore mnemonics we know aren't
4914 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004915 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004916 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004917 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004918 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004919 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4920 .Case("eq", ARMCC::EQ)
4921 .Case("ne", ARMCC::NE)
4922 .Case("hs", ARMCC::HS)
4923 .Case("cs", ARMCC::HS)
4924 .Case("lo", ARMCC::LO)
4925 .Case("cc", ARMCC::LO)
4926 .Case("mi", ARMCC::MI)
4927 .Case("pl", ARMCC::PL)
4928 .Case("vs", ARMCC::VS)
4929 .Case("vc", ARMCC::VC)
4930 .Case("hi", ARMCC::HI)
4931 .Case("ls", ARMCC::LS)
4932 .Case("ge", ARMCC::GE)
4933 .Case("lt", ARMCC::LT)
4934 .Case("gt", ARMCC::GT)
4935 .Case("le", ARMCC::LE)
4936 .Case("al", ARMCC::AL)
4937 .Default(~0U);
4938 if (CC != ~0U) {
4939 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4940 PredicationCode = CC;
4941 }
Bill Wendling193961b2010-10-29 23:50:21 +00004942 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004943
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004944 // Next, determine if we have a carry setting bit. We explicitly ignore all
4945 // the instructions we know end in 's'.
4946 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004947 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004948 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4949 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4950 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004951 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004952 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004953 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004954 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004955 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004956 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004957 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4958 CarrySetting = true;
4959 }
4960
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004961 // The "cps" instruction can have a interrupt mode operand which is glued into
4962 // the mnemonic. Check if this is the case, split it and parse the imod op
4963 if (Mnemonic.startswith("cps")) {
4964 // Split out any imod code.
4965 unsigned IMod =
4966 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4967 .Case("ie", ARM_PROC::IE)
4968 .Case("id", ARM_PROC::ID)
4969 .Default(~0U);
4970 if (IMod != ~0U) {
4971 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4972 ProcessorIMod = IMod;
4973 }
4974 }
4975
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004976 // The "it" instruction has the condition mask on the end of the mnemonic.
4977 if (Mnemonic.startswith("it")) {
4978 ITMask = Mnemonic.slice(2, Mnemonic.size());
4979 Mnemonic = Mnemonic.slice(0, 2);
4980 }
4981
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004982 return Mnemonic;
4983}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004984
4985/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4986/// inclusion of carry set or predication code operands.
4987//
4988// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004989void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004990getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004991 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004992 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4993 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004994 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004995 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004996 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004997 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004998 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004999 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005000 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005001 Mnemonic == "mla" || Mnemonic == "smlal" ||
5002 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005003 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005004 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005005 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005006
Tim Northover2c45a382013-06-26 16:52:40 +00005007 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5008 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
5009 Mnemonic == "trap" || Mnemonic == "setend" ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005010 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
5011 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
5012 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm") {
Tim Northover2c45a382013-06-26 16:52:40 +00005013 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005014 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005015 } else if (!isThumb()) {
5016 // Some instructions are only predicable in Thumb mode
5017 CanAcceptPredicationCode
5018 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5019 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5020 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5021 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5022 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5023 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5024 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5025 } else if (isThumbOne()) {
5026 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005027 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005028 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005029}
5030
Jim Grosbach7283da92011-08-16 21:12:37 +00005031bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
5032 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005033 // FIXME: This is all horribly hacky. We really need a better way to deal
5034 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005035
5036 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5037 // another does not. Specifically, the MOVW instruction does not. So we
5038 // special case it here and remove the defaulted (non-setting) cc_out
5039 // operand if that's the instruction we're trying to match.
5040 //
5041 // We do this as post-processing of the explicit operands rather than just
5042 // conditionally adding the cc_out in the first place because we need
5043 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005044 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00005045 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
5046 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
5047 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5048 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005049
5050 // Register-register 'add' for thumb does not have a cc_out operand
5051 // when there are only two register operands.
5052 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5053 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5054 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5055 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5056 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005057 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005058 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5059 // have to check the immediate range here since Thumb2 has a variant
5060 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005061 if (((isThumb() && Mnemonic == "add") ||
5062 (isThumbTwo() && Mnemonic == "sub")) &&
5063 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005064 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5065 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5066 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005067 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005068 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005069 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005070 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005071 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5072 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005073 // selecting via the generic "add" mnemonic, so to know that we
5074 // should remove the cc_out operand, we have to explicitly check that
5075 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005076 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5077 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005078 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5079 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5080 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5081 // Nest conditions rather than one big 'if' statement for readability.
5082 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005083 // If both registers are low, we're in an IT block, and the immediate is
5084 // in range, we should use encoding T1 instead, which has a cc_out.
5085 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005086 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005087 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5088 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5089 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005090 // Check against T3. If the second register is the PC, this is an
5091 // alternate form of ADR, which uses encoding T4, so check for that too.
5092 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5093 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5094 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005095
5096 // Otherwise, we use encoding T4, which does not have a cc_out
5097 // operand.
5098 return true;
5099 }
5100
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005101 // The thumb2 multiply instruction doesn't have a CCOut register, so
5102 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5103 // use the 16-bit encoding or not.
5104 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5105 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5106 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5107 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5108 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5109 // If the registers aren't low regs, the destination reg isn't the
5110 // same as one of the source regs, or the cc_out operand is zero
5111 // outside of an IT block, we have to use the 32-bit encoding, so
5112 // remove the cc_out operand.
5113 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5114 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00005115 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005116 !inITBlock() ||
5117 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5118 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5119 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5120 static_cast<ARMOperand*>(Operands[4])->getReg())))
5121 return true;
5122
Jim Grosbachefa7e952011-11-15 19:55:16 +00005123 // Also check the 'mul' syntax variant that doesn't specify an explicit
5124 // destination register.
5125 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5126 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5127 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5128 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5129 // If the registers aren't low regs or the cc_out operand is zero
5130 // outside of an IT block, we have to use the 32-bit encoding, so
5131 // remove the cc_out operand.
5132 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5133 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5134 !inITBlock()))
5135 return true;
5136
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005137
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005138
Jim Grosbach4b701af2011-08-24 21:42:27 +00005139 // Register-register 'add/sub' for thumb does not have a cc_out operand
5140 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5141 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5142 // right, this will result in better diagnostics (which operand is off)
5143 // anyway.
5144 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5145 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005146 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5147 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005148 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5149 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5150 (Operands.size() == 6 &&
5151 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005152 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005153
Jim Grosbach7283da92011-08-16 21:12:37 +00005154 return false;
5155}
5156
Jim Grosbach12952fe2011-11-11 23:08:10 +00005157static bool isDataTypeToken(StringRef Tok) {
5158 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5159 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5160 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5161 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5162 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5163 Tok == ".f" || Tok == ".d";
5164}
5165
5166// FIXME: This bit should probably be handled via an explicit match class
5167// in the .td files that matches the suffix instead of having it be
5168// a literal string token the way it is now.
5169static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5170 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5171}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005172static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5173 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005174/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005175bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5176 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005177 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005178 // Apply mnemonic aliases before doing anything else, as the destination
5179 // mnemnonic may include suffices and we want to handle them normally.
5180 // The generic tblgen'erated code does this later, at the start of
5181 // MatchInstructionImpl(), but that's too late for aliases that include
5182 // any sort of suffix.
5183 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005184 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5185 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005186
Jim Grosbachab5830e2011-12-14 02:16:11 +00005187 // First check for the ARM-specific .req directive.
5188 if (Parser.getTok().is(AsmToken::Identifier) &&
5189 Parser.getTok().getIdentifier() == ".req") {
5190 parseDirectiveReq(Name, NameLoc);
5191 // We always return 'error' for this, as we're done with this
5192 // statement and don't need to match the 'instruction."
5193 return true;
5194 }
5195
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005196 // Create the leading tokens for the mnemonic, split by '.' characters.
5197 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005198 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005199
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005200 // Split out the predication code and carry setting flag from the mnemonic.
5201 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005202 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005203 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005204 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005205 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005206 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005207
Jim Grosbach1c171b12011-08-25 17:23:55 +00005208 // In Thumb1, only the branch (B) instruction can be predicated.
5209 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005210 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005211 return Error(NameLoc, "conditional execution not supported in Thumb1");
5212 }
5213
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005214 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5215
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005216 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5217 // is the mask as it will be for the IT encoding if the conditional
5218 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5219 // where the conditional bit0 is zero, the instruction post-processing
5220 // will adjust the mask accordingly.
5221 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005222 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5223 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005224 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005225 return Error(Loc, "too many conditions on IT instruction");
5226 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005227 unsigned Mask = 8;
5228 for (unsigned i = ITMask.size(); i != 0; --i) {
5229 char pos = ITMask[i - 1];
5230 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005231 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005232 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005233 }
5234 Mask >>= 1;
5235 if (ITMask[i - 1] == 't')
5236 Mask |= 8;
5237 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005238 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005239 }
5240
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005241 // FIXME: This is all a pretty gross hack. We should automatically handle
5242 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005243
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005244 // Next, add the CCOut and ConditionCode operands, if needed.
5245 //
5246 // For mnemonics which can ever incorporate a carry setting bit or predication
5247 // code, our matching model involves us always generating CCOut and
5248 // ConditionCode operands to match the mnemonic "as written" and then we let
5249 // the matcher deal with finding the right instruction or generating an
5250 // appropriate error.
5251 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005252 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005253
Jim Grosbach03a8a162011-07-14 22:04:21 +00005254 // If we had a carry-set on an instruction that can't do that, issue an
5255 // error.
5256 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005257 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005258 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005259 "' can not set flags, but 's' suffix specified");
5260 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005261 // If we had a predication code on an instruction that can't do that, issue an
5262 // error.
5263 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005264 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005265 return Error(NameLoc, "instruction '" + Mnemonic +
5266 "' is not predicable, but condition code specified");
5267 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005268
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005269 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005270 if (CanAcceptCarrySet) {
5271 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005272 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005273 Loc));
5274 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005275
5276 // Add the predication code operand, if necessary.
5277 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005278 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5279 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005280 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005281 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005282 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005283
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005284 // Add the processor imod operand, if necessary.
5285 if (ProcessorIMod) {
5286 Operands.push_back(ARMOperand::CreateImm(
5287 MCConstantExpr::Create(ProcessorIMod, getContext()),
5288 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005289 }
5290
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005291 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005292 while (Next != StringRef::npos) {
5293 Start = Next;
5294 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005295 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005296
Jim Grosbach12952fe2011-11-11 23:08:10 +00005297 // Some NEON instructions have an optional datatype suffix that is
5298 // completely ignored. Check for that.
5299 if (isDataTypeToken(ExtraToken) &&
5300 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5301 continue;
5302
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005303 // For for ARM mode generate an error if the .n qualifier is used.
5304 if (ExtraToken == ".n" && !isThumb()) {
5305 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5306 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5307 "arm mode");
5308 }
5309
5310 // The .n qualifier is always discarded as that is what the tables
5311 // and matcher expect. In ARM mode the .w qualifier has no effect,
5312 // so discard it to avoid errors that can be caused by the matcher.
5313 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005314 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5315 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5316 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005317 }
5318
5319 // Read the remaining operands.
5320 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005321 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005322 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005323 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005324 return true;
5325 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005326
5327 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005328 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005329
5330 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005331 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005332 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005333 return true;
5334 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005335 }
5336 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005337
Chris Lattnera2a9d162010-09-11 16:18:25 +00005338 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005339 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005340 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005341 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005342 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005343
Chris Lattner91689c12010-09-08 05:10:46 +00005344 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005345
Jim Grosbach7283da92011-08-16 21:12:37 +00005346 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5347 // do and don't have a cc_out optional-def operand. With some spot-checks
5348 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005349 // parse and adjust accordingly before actually matching. We shouldn't ever
5350 // try to remove a cc_out operand that was explicitly set on the the
5351 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5352 // table driven matcher doesn't fit well with the ARM instruction set.
5353 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005354 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5355 Operands.erase(Operands.begin() + 1);
5356 delete Op;
5357 }
5358
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005359 // ARM mode 'blx' need special handling, as the register operand version
5360 // is predicable, but the label operand version is not. So, we can't rely
5361 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005362 // a k_CondCode operand in the list. If we're trying to match the label
5363 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005364 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5365 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5366 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5367 Operands.erase(Operands.begin() + 1);
5368 delete Op;
5369 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005370
Weiming Zhao8f56f882012-11-16 21:55:34 +00005371 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5372 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5373 // a single GPRPair reg operand is used in the .td file to replace the two
5374 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5375 // expressed as a GPRPair, so we have to manually merge them.
5376 // FIXME: We would really like to be able to tablegen'erate this.
5377 if (!isThumb() && Operands.size() > 4 &&
5378 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5379 bool isLoad = (Mnemonic == "ldrexd");
5380 unsigned Idx = isLoad ? 2 : 3;
5381 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5382 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5383
5384 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5385 // Adjust only if Op1 and Op2 are GPRs.
5386 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5387 MRC.contains(Op2->getReg())) {
5388 unsigned Reg1 = Op1->getReg();
5389 unsigned Reg2 = Op2->getReg();
5390 unsigned Rt = MRI->getEncodingValue(Reg1);
5391 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5392
5393 // Rt2 must be Rt + 1 and Rt must be even.
5394 if (Rt + 1 != Rt2 || (Rt & 1)) {
5395 Error(Op2->getStartLoc(), isLoad ?
5396 "destination operands must be sequential" :
5397 "source operands must be sequential");
5398 return true;
5399 }
5400 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5401 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5402 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5403 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5404 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5405 delete Op1;
5406 delete Op2;
5407 }
5408 }
5409
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005410 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005411}
5412
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005413// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005414
5415// return 'true' if register list contains non-low GPR registers,
5416// 'false' otherwise. If Reg is in the register list or is HiReg, set
5417// 'containsReg' to true.
5418static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5419 unsigned HiReg, bool &containsReg) {
5420 containsReg = false;
5421 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5422 unsigned OpReg = Inst.getOperand(i).getReg();
5423 if (OpReg == Reg)
5424 containsReg = true;
5425 // Anything other than a low register isn't legal here.
5426 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5427 return true;
5428 }
5429 return false;
5430}
5431
Jim Grosbacha31f2232011-09-07 18:05:34 +00005432// Check if the specified regisgter is in the register list of the inst,
5433// starting at the indicated operand number.
5434static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5435 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5436 unsigned OpReg = Inst.getOperand(i).getReg();
5437 if (OpReg == Reg)
5438 return true;
5439 }
5440 return false;
5441}
5442
Jim Grosbached16ec42011-08-29 22:24:09 +00005443// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5444// the ARMInsts array) instead. Getting that here requires awkward
5445// API changes, though. Better way?
5446namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005447extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005448}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005449static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005450 return ARMInsts[Opcode];
5451}
5452
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005453// FIXME: We would really like to be able to tablegen'erate this.
5454bool ARMAsmParser::
5455validateInstruction(MCInst &Inst,
5456 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005457 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005458 SMLoc Loc = Operands[0]->getStartLoc();
5459 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005460 // NOTE: BKPT instruction has the interesting property of being
5461 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005462 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005463 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5464 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005465 unsigned bit = 1;
5466 if (ITState.FirstCond)
5467 ITState.FirstCond = false;
5468 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005469 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005470 // The instruction must be predicable.
5471 if (!MCID.isPredicable())
5472 return Error(Loc, "instructions in IT block must be predicable");
5473 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5474 unsigned ITCond = bit ? ITState.Cond :
5475 ARMCC::getOppositeCondition(ITState.Cond);
5476 if (Cond != ITCond) {
5477 // Find the condition code Operand to get its SMLoc information.
5478 SMLoc CondLoc;
5479 for (unsigned i = 1; i < Operands.size(); ++i)
5480 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5481 CondLoc = Operands[i]->getStartLoc();
5482 return Error(CondLoc, "incorrect condition in IT block; got '" +
5483 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5484 "', but expected '" +
5485 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5486 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005487 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005488 } else if (isThumbTwo() && MCID.isPredicable() &&
5489 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005490 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5491 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005492 return Error(Loc, "predicated instructions must be in IT block");
5493
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005494 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005495 case ARM::LDRD:
5496 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005497 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005498 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005499 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5500 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005501 if (Rt2 != Rt + 1)
5502 return Error(Operands[3]->getStartLoc(),
5503 "destination operands must be sequential");
5504 return false;
5505 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005506 case ARM::STRD: {
5507 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005508 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5509 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005510 if (Rt2 != Rt + 1)
5511 return Error(Operands[3]->getStartLoc(),
5512 "source operands must be sequential");
5513 return false;
5514 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005515 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005516 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005517 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005518 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5519 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005520 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005521 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005522 "source operands must be sequential");
5523 return false;
5524 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005525 case ARM::SBFX:
5526 case ARM::UBFX: {
5527 // width must be in range [1, 32-lsb]
5528 unsigned lsb = Inst.getOperand(2).getImm();
5529 unsigned widthm1 = Inst.getOperand(3).getImm();
5530 if (widthm1 >= 32 - lsb)
5531 return Error(Operands[5]->getStartLoc(),
5532 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005533 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005534 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005535 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005536 // If we're parsing Thumb2, the .w variant is available and handles
5537 // most cases that are normally illegal for a Thumb1 LDM
5538 // instruction. We'll make the transformation in processInstruction()
5539 // if necessary.
5540 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005541 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005542 // in the register list.
5543 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005544 bool hasWritebackToken =
5545 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5546 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005547 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005548 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005549 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5550 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005551 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005552 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005553 return Error(Operands[2]->getStartLoc(),
5554 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005555 // If we should not have writeback, there must not be a '!'. This is
5556 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005557 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005558 return Error(Operands[3]->getStartLoc(),
5559 "writeback operator '!' not allowed when base register "
5560 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005561
5562 break;
5563 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005564 case ARM::t2LDMIA_UPD: {
5565 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5566 return Error(Operands[4]->getStartLoc(),
5567 "writeback operator '!' not allowed when base register "
5568 "in register list");
5569 break;
5570 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005571 case ARM::tMUL: {
5572 // The second source operand must be the same register as the destination
5573 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005574 //
5575 // In this case, we must directly check the parsed operands because the
5576 // cvtThumbMultiply() function is written in such a way that it guarantees
5577 // this first statement is always true for the new Inst. Essentially, the
5578 // destination is unconditionally copied into the second source operand
5579 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005580 if (Operands.size() == 6 &&
5581 (((ARMOperand*)Operands[3])->getReg() !=
5582 ((ARMOperand*)Operands[5])->getReg()) &&
5583 (((ARMOperand*)Operands[3])->getReg() !=
5584 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005585 return Error(Operands[3]->getStartLoc(),
5586 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005587 }
5588 break;
5589 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005590 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5591 // so only issue a diagnostic for thumb1. The instructions will be
5592 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005593 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005594 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005595 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5596 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005597 return Error(Operands[2]->getStartLoc(),
5598 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005599 break;
5600 }
5601 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005602 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005603 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5604 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005605 return Error(Operands[2]->getStartLoc(),
5606 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005607 break;
5608 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005609 case ARM::tSTMIA_UPD: {
5610 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005611 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005612 return Error(Operands[4]->getStartLoc(),
5613 "registers must be in range r0-r7");
5614 break;
5615 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005616 case ARM::tADDrSP: {
5617 // If the non-SP source operand and the destination operand are not the
5618 // same, we need thumb2 (for the wide encoding), or we have an error.
5619 if (!isThumbTwo() &&
5620 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5621 return Error(Operands[4]->getStartLoc(),
5622 "source register must be the same as destination");
5623 }
5624 break;
5625 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005626 }
5627
5628 return false;
5629}
5630
Jim Grosbach1a747242012-01-23 23:45:44 +00005631static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005632 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005633 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005634 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005635 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5636 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5637 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5638 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5639 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5640 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5641 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5642 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5643 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005644
5645 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005646 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5647 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5648 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5649 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5650 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005651
Jim Grosbach1e946a42012-01-24 00:43:12 +00005652 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5653 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5654 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5655 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5656 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005657
Jim Grosbach1e946a42012-01-24 00:43:12 +00005658 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5659 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5660 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5661 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5662 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005663
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005664 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005665 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5666 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5667 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5668 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5669 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5670 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5671 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5672 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5673 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5674 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5675 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5676 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5677 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5678 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5679 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005680
Jim Grosbach1a747242012-01-23 23:45:44 +00005681 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005682 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5683 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5684 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5685 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5686 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5687 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5688 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5689 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5690 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5691 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5692 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5693 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5694 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5695 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5696 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5697 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5698 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5699 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005700
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005701 // VST4LN
5702 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5703 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5704 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5705 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5706 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5707 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5708 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5709 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5710 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5711 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5712 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5713 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5714 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5715 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5716 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5717
Jim Grosbachda70eac2012-01-24 00:58:13 +00005718 // VST4
5719 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5720 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5721 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5722 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5723 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5724 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5725 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5726 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5727 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5728 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5729 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5730 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5731 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5732 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5733 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5734 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5735 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5736 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005737 }
5738}
5739
Jim Grosbach1a747242012-01-23 23:45:44 +00005740static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005741 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005742 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005743 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005744 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5745 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5746 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5747 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5748 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5749 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5750 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5751 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5752 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005753
5754 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005755 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5756 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5757 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5758 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5759 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5760 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5761 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5762 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5763 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5764 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5765 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5766 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5767 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5768 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5769 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005770
Jim Grosbachb78403c2012-01-24 23:47:04 +00005771 // VLD3DUP
5772 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5773 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5774 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5775 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5776 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5777 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5778 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5779 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5780 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5781 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5782 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5783 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5784 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5785 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5786 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5787 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5788 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5789 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5790
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005791 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005792 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5793 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5794 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5795 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5796 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5797 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5798 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5799 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5800 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5801 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5802 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5803 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5804 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5805 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5806 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005807
5808 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005809 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5810 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5811 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5812 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5813 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5814 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5815 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5816 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5817 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5818 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5819 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5820 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5821 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5822 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5823 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5824 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5825 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5826 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005827
Jim Grosbach14952a02012-01-24 18:37:25 +00005828 // VLD4LN
5829 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5830 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5831 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5832 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5833 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5834 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5835 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5836 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5837 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5838 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5839 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5840 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5841 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5842 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5843 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5844
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005845 // VLD4DUP
5846 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5847 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5848 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5849 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5850 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5851 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5852 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5853 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5854 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5855 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5856 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5857 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5858 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5859 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5860 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5861 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5862 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5863 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5864
Jim Grosbached561fc2012-01-24 00:43:17 +00005865 // VLD4
5866 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5867 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5868 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5869 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5870 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5871 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5872 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5873 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5874 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5875 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5876 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5877 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5878 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5879 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5880 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5881 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5882 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5883 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005884 }
5885}
5886
Jim Grosbachafad0532011-11-10 23:42:14 +00005887bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005888processInstruction(MCInst &Inst,
5889 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5890 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005891 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5892 case ARM::ADDri: {
5893 if (Inst.getOperand(1).getReg() != ARM::PC ||
5894 Inst.getOperand(5).getReg() != 0)
5895 return false;
5896 MCInst TmpInst;
5897 TmpInst.setOpcode(ARM::ADR);
5898 TmpInst.addOperand(Inst.getOperand(0));
5899 TmpInst.addOperand(Inst.getOperand(2));
5900 TmpInst.addOperand(Inst.getOperand(3));
5901 TmpInst.addOperand(Inst.getOperand(4));
5902 Inst = TmpInst;
5903 return true;
5904 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005905 // Aliases for alternate PC+imm syntax of LDR instructions.
5906 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005907 // Select the narrow version if the immediate will fit.
5908 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005909 Inst.getOperand(1).getImm() <= 0xff &&
5910 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5911 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005912 Inst.setOpcode(ARM::tLDRpci);
5913 else
5914 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005915 return true;
5916 case ARM::t2LDRBpcrel:
5917 Inst.setOpcode(ARM::t2LDRBpci);
5918 return true;
5919 case ARM::t2LDRHpcrel:
5920 Inst.setOpcode(ARM::t2LDRHpci);
5921 return true;
5922 case ARM::t2LDRSBpcrel:
5923 Inst.setOpcode(ARM::t2LDRSBpci);
5924 return true;
5925 case ARM::t2LDRSHpcrel:
5926 Inst.setOpcode(ARM::t2LDRSHpci);
5927 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005928 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005929 case ARM::VST1LNdWB_register_Asm_8:
5930 case ARM::VST1LNdWB_register_Asm_16:
5931 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005932 MCInst TmpInst;
5933 // Shuffle the operands around so the lane index operand is in the
5934 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005935 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005936 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005937 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5938 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5939 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5940 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5941 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5942 TmpInst.addOperand(Inst.getOperand(1)); // lane
5943 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5944 TmpInst.addOperand(Inst.getOperand(6));
5945 Inst = TmpInst;
5946 return true;
5947 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005948
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005949 case ARM::VST2LNdWB_register_Asm_8:
5950 case ARM::VST2LNdWB_register_Asm_16:
5951 case ARM::VST2LNdWB_register_Asm_32:
5952 case ARM::VST2LNqWB_register_Asm_16:
5953 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005954 MCInst TmpInst;
5955 // Shuffle the operands around so the lane index operand is in the
5956 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005957 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005958 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005959 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5960 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5961 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5962 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5963 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005964 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5965 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005966 TmpInst.addOperand(Inst.getOperand(1)); // lane
5967 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5968 TmpInst.addOperand(Inst.getOperand(6));
5969 Inst = TmpInst;
5970 return true;
5971 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005972
5973 case ARM::VST3LNdWB_register_Asm_8:
5974 case ARM::VST3LNdWB_register_Asm_16:
5975 case ARM::VST3LNdWB_register_Asm_32:
5976 case ARM::VST3LNqWB_register_Asm_16:
5977 case ARM::VST3LNqWB_register_Asm_32: {
5978 MCInst TmpInst;
5979 // Shuffle the operands around so the lane index operand is in the
5980 // right place.
5981 unsigned Spacing;
5982 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5983 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5984 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5985 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5986 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5987 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5988 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5989 Spacing));
5990 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5991 Spacing * 2));
5992 TmpInst.addOperand(Inst.getOperand(1)); // lane
5993 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5994 TmpInst.addOperand(Inst.getOperand(6));
5995 Inst = TmpInst;
5996 return true;
5997 }
5998
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005999 case ARM::VST4LNdWB_register_Asm_8:
6000 case ARM::VST4LNdWB_register_Asm_16:
6001 case ARM::VST4LNdWB_register_Asm_32:
6002 case ARM::VST4LNqWB_register_Asm_16:
6003 case ARM::VST4LNqWB_register_Asm_32: {
6004 MCInst TmpInst;
6005 // Shuffle the operands around so the lane index operand is in the
6006 // right place.
6007 unsigned Spacing;
6008 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6009 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6010 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6011 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6012 TmpInst.addOperand(Inst.getOperand(4)); // Rm
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(1)); // lane
6021 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6022 TmpInst.addOperand(Inst.getOperand(6));
6023 Inst = TmpInst;
6024 return true;
6025 }
6026
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006027 case ARM::VST1LNdWB_fixed_Asm_8:
6028 case ARM::VST1LNdWB_fixed_Asm_16:
6029 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006030 MCInst TmpInst;
6031 // Shuffle the operands around so the lane index operand is in the
6032 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006033 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006034 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006035 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6036 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6037 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6038 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6039 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6040 TmpInst.addOperand(Inst.getOperand(1)); // lane
6041 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6042 TmpInst.addOperand(Inst.getOperand(5));
6043 Inst = TmpInst;
6044 return true;
6045 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006046
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006047 case ARM::VST2LNdWB_fixed_Asm_8:
6048 case ARM::VST2LNdWB_fixed_Asm_16:
6049 case ARM::VST2LNdWB_fixed_Asm_32:
6050 case ARM::VST2LNqWB_fixed_Asm_16:
6051 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006052 MCInst TmpInst;
6053 // Shuffle the operands around so the lane index operand is in the
6054 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006055 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006056 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006057 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6058 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6059 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6060 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6061 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006062 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6063 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006064 TmpInst.addOperand(Inst.getOperand(1)); // lane
6065 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6066 TmpInst.addOperand(Inst.getOperand(5));
6067 Inst = TmpInst;
6068 return true;
6069 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006070
6071 case ARM::VST3LNdWB_fixed_Asm_8:
6072 case ARM::VST3LNdWB_fixed_Asm_16:
6073 case ARM::VST3LNdWB_fixed_Asm_32:
6074 case ARM::VST3LNqWB_fixed_Asm_16:
6075 case ARM::VST3LNqWB_fixed_Asm_32: {
6076 MCInst TmpInst;
6077 // Shuffle the operands around so the lane index operand is in the
6078 // right place.
6079 unsigned Spacing;
6080 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6081 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6082 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6083 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6084 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6085 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6086 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6087 Spacing));
6088 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6089 Spacing * 2));
6090 TmpInst.addOperand(Inst.getOperand(1)); // lane
6091 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6092 TmpInst.addOperand(Inst.getOperand(5));
6093 Inst = TmpInst;
6094 return true;
6095 }
6096
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006097 case ARM::VST4LNdWB_fixed_Asm_8:
6098 case ARM::VST4LNdWB_fixed_Asm_16:
6099 case ARM::VST4LNdWB_fixed_Asm_32:
6100 case ARM::VST4LNqWB_fixed_Asm_16:
6101 case ARM::VST4LNqWB_fixed_Asm_32: {
6102 MCInst TmpInst;
6103 // Shuffle the operands around so the lane index operand is in the
6104 // right place.
6105 unsigned Spacing;
6106 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6107 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6108 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6109 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6110 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6111 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6113 Spacing));
6114 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6115 Spacing * 2));
6116 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6117 Spacing * 3));
6118 TmpInst.addOperand(Inst.getOperand(1)); // lane
6119 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6120 TmpInst.addOperand(Inst.getOperand(5));
6121 Inst = TmpInst;
6122 return true;
6123 }
6124
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006125 case ARM::VST1LNdAsm_8:
6126 case ARM::VST1LNdAsm_16:
6127 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006128 MCInst TmpInst;
6129 // Shuffle the operands around so the lane index operand is in the
6130 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006131 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006132 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006133 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6134 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6135 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6136 TmpInst.addOperand(Inst.getOperand(1)); // lane
6137 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6138 TmpInst.addOperand(Inst.getOperand(5));
6139 Inst = TmpInst;
6140 return true;
6141 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006142
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006143 case ARM::VST2LNdAsm_8:
6144 case ARM::VST2LNdAsm_16:
6145 case ARM::VST2LNdAsm_32:
6146 case ARM::VST2LNqAsm_16:
6147 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006148 MCInst TmpInst;
6149 // Shuffle the operands around so the lane index operand is in the
6150 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006151 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006152 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006153 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6154 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6155 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006156 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6157 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006158 TmpInst.addOperand(Inst.getOperand(1)); // lane
6159 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6160 TmpInst.addOperand(Inst.getOperand(5));
6161 Inst = TmpInst;
6162 return true;
6163 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006164
6165 case ARM::VST3LNdAsm_8:
6166 case ARM::VST3LNdAsm_16:
6167 case ARM::VST3LNdAsm_32:
6168 case ARM::VST3LNqAsm_16:
6169 case ARM::VST3LNqAsm_32: {
6170 MCInst TmpInst;
6171 // Shuffle the operands around so the lane index operand is in the
6172 // right place.
6173 unsigned Spacing;
6174 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6175 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6176 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6177 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6178 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6179 Spacing));
6180 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6181 Spacing * 2));
6182 TmpInst.addOperand(Inst.getOperand(1)); // lane
6183 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6184 TmpInst.addOperand(Inst.getOperand(5));
6185 Inst = TmpInst;
6186 return true;
6187 }
6188
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006189 case ARM::VST4LNdAsm_8:
6190 case ARM::VST4LNdAsm_16:
6191 case ARM::VST4LNdAsm_32:
6192 case ARM::VST4LNqAsm_16:
6193 case ARM::VST4LNqAsm_32: {
6194 MCInst TmpInst;
6195 // Shuffle the operands around so the lane index operand is in the
6196 // right place.
6197 unsigned Spacing;
6198 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6199 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6200 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6201 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6202 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6203 Spacing));
6204 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6205 Spacing * 2));
6206 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6207 Spacing * 3));
6208 TmpInst.addOperand(Inst.getOperand(1)); // lane
6209 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6210 TmpInst.addOperand(Inst.getOperand(5));
6211 Inst = TmpInst;
6212 return true;
6213 }
6214
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006215 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006216 case ARM::VLD1LNdWB_register_Asm_8:
6217 case ARM::VLD1LNdWB_register_Asm_16:
6218 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006219 MCInst TmpInst;
6220 // Shuffle the operands around so the lane index operand is in the
6221 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006222 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006223 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006224 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6225 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6226 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6227 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6228 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6229 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6230 TmpInst.addOperand(Inst.getOperand(1)); // lane
6231 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6232 TmpInst.addOperand(Inst.getOperand(6));
6233 Inst = TmpInst;
6234 return true;
6235 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006236
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006237 case ARM::VLD2LNdWB_register_Asm_8:
6238 case ARM::VLD2LNdWB_register_Asm_16:
6239 case ARM::VLD2LNdWB_register_Asm_32:
6240 case ARM::VLD2LNqWB_register_Asm_16:
6241 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006242 MCInst TmpInst;
6243 // Shuffle the operands around so the lane index operand is in the
6244 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006245 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006246 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006247 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006248 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6249 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006250 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6251 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6252 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6253 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6254 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006255 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6256 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006257 TmpInst.addOperand(Inst.getOperand(1)); // lane
6258 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6259 TmpInst.addOperand(Inst.getOperand(6));
6260 Inst = TmpInst;
6261 return true;
6262 }
6263
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006264 case ARM::VLD3LNdWB_register_Asm_8:
6265 case ARM::VLD3LNdWB_register_Asm_16:
6266 case ARM::VLD3LNdWB_register_Asm_32:
6267 case ARM::VLD3LNqWB_register_Asm_16:
6268 case ARM::VLD3LNqWB_register_Asm_32: {
6269 MCInst TmpInst;
6270 // Shuffle the operands around so the lane index operand is in the
6271 // right place.
6272 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006273 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006274 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6275 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6276 Spacing));
6277 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006278 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006279 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6280 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6281 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6282 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6283 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6284 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6285 Spacing));
6286 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006287 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006288 TmpInst.addOperand(Inst.getOperand(1)); // lane
6289 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6290 TmpInst.addOperand(Inst.getOperand(6));
6291 Inst = TmpInst;
6292 return true;
6293 }
6294
Jim Grosbach14952a02012-01-24 18:37:25 +00006295 case ARM::VLD4LNdWB_register_Asm_8:
6296 case ARM::VLD4LNdWB_register_Asm_16:
6297 case ARM::VLD4LNdWB_register_Asm_32:
6298 case ARM::VLD4LNqWB_register_Asm_16:
6299 case ARM::VLD4LNqWB_register_Asm_32: {
6300 MCInst TmpInst;
6301 // Shuffle the operands around so the lane index operand is in the
6302 // right place.
6303 unsigned Spacing;
6304 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6305 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6306 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6307 Spacing));
6308 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6309 Spacing * 2));
6310 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6311 Spacing * 3));
6312 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6313 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6314 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6315 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6316 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6317 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6318 Spacing));
6319 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6320 Spacing * 2));
6321 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6322 Spacing * 3));
6323 TmpInst.addOperand(Inst.getOperand(1)); // lane
6324 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6325 TmpInst.addOperand(Inst.getOperand(6));
6326 Inst = TmpInst;
6327 return true;
6328 }
6329
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006330 case ARM::VLD1LNdWB_fixed_Asm_8:
6331 case ARM::VLD1LNdWB_fixed_Asm_16:
6332 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006333 MCInst TmpInst;
6334 // Shuffle the operands around so the lane index operand is in the
6335 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006336 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006337 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006338 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6339 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6340 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6341 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6342 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6343 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6344 TmpInst.addOperand(Inst.getOperand(1)); // lane
6345 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6346 TmpInst.addOperand(Inst.getOperand(5));
6347 Inst = TmpInst;
6348 return true;
6349 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006350
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006351 case ARM::VLD2LNdWB_fixed_Asm_8:
6352 case ARM::VLD2LNdWB_fixed_Asm_16:
6353 case ARM::VLD2LNdWB_fixed_Asm_32:
6354 case ARM::VLD2LNqWB_fixed_Asm_16:
6355 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006356 MCInst TmpInst;
6357 // Shuffle the operands around so the lane index operand is in the
6358 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006359 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006360 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006361 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6363 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006364 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6365 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6366 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6367 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6368 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006369 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6370 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006371 TmpInst.addOperand(Inst.getOperand(1)); // lane
6372 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6373 TmpInst.addOperand(Inst.getOperand(5));
6374 Inst = TmpInst;
6375 return true;
6376 }
6377
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006378 case ARM::VLD3LNdWB_fixed_Asm_8:
6379 case ARM::VLD3LNdWB_fixed_Asm_16:
6380 case ARM::VLD3LNdWB_fixed_Asm_32:
6381 case ARM::VLD3LNqWB_fixed_Asm_16:
6382 case ARM::VLD3LNqWB_fixed_Asm_32: {
6383 MCInst TmpInst;
6384 // Shuffle the operands around so the lane index operand is in the
6385 // right place.
6386 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006387 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006388 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6389 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6390 Spacing));
6391 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006392 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006393 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6394 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6395 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6396 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6397 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6399 Spacing));
6400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006401 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006402 TmpInst.addOperand(Inst.getOperand(1)); // lane
6403 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6404 TmpInst.addOperand(Inst.getOperand(5));
6405 Inst = TmpInst;
6406 return true;
6407 }
6408
Jim Grosbach14952a02012-01-24 18:37:25 +00006409 case ARM::VLD4LNdWB_fixed_Asm_8:
6410 case ARM::VLD4LNdWB_fixed_Asm_16:
6411 case ARM::VLD4LNdWB_fixed_Asm_32:
6412 case ARM::VLD4LNqWB_fixed_Asm_16:
6413 case ARM::VLD4LNqWB_fixed_Asm_32: {
6414 MCInst TmpInst;
6415 // Shuffle the operands around so the lane index operand is in the
6416 // right place.
6417 unsigned Spacing;
6418 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6419 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6421 Spacing));
6422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6423 Spacing * 2));
6424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6425 Spacing * 3));
6426 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6427 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6428 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6429 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6430 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6431 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6432 Spacing));
6433 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6434 Spacing * 2));
6435 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6436 Spacing * 3));
6437 TmpInst.addOperand(Inst.getOperand(1)); // lane
6438 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6439 TmpInst.addOperand(Inst.getOperand(5));
6440 Inst = TmpInst;
6441 return true;
6442 }
6443
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006444 case ARM::VLD1LNdAsm_8:
6445 case ARM::VLD1LNdAsm_16:
6446 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006447 MCInst TmpInst;
6448 // Shuffle the operands around so the lane index operand is in the
6449 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006450 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006451 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006452 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6453 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6454 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6455 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6456 TmpInst.addOperand(Inst.getOperand(1)); // lane
6457 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6458 TmpInst.addOperand(Inst.getOperand(5));
6459 Inst = TmpInst;
6460 return true;
6461 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006462
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006463 case ARM::VLD2LNdAsm_8:
6464 case ARM::VLD2LNdAsm_16:
6465 case ARM::VLD2LNdAsm_32:
6466 case ARM::VLD2LNqAsm_16:
6467 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006468 MCInst TmpInst;
6469 // Shuffle the operands around so the lane index operand is in the
6470 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006471 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006472 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006473 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006474 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6475 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006476 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6477 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6478 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6480 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006481 TmpInst.addOperand(Inst.getOperand(1)); // lane
6482 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6483 TmpInst.addOperand(Inst.getOperand(5));
6484 Inst = TmpInst;
6485 return true;
6486 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006487
6488 case ARM::VLD3LNdAsm_8:
6489 case ARM::VLD3LNdAsm_16:
6490 case ARM::VLD3LNdAsm_32:
6491 case ARM::VLD3LNqAsm_16:
6492 case ARM::VLD3LNqAsm_32: {
6493 MCInst TmpInst;
6494 // Shuffle the operands around so the lane index operand is in the
6495 // right place.
6496 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006497 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006498 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6500 Spacing));
6501 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006502 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006503 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6504 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6505 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6506 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6507 Spacing));
6508 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006509 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006510 TmpInst.addOperand(Inst.getOperand(1)); // lane
6511 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6512 TmpInst.addOperand(Inst.getOperand(5));
6513 Inst = TmpInst;
6514 return true;
6515 }
6516
Jim Grosbach14952a02012-01-24 18:37:25 +00006517 case ARM::VLD4LNdAsm_8:
6518 case ARM::VLD4LNdAsm_16:
6519 case ARM::VLD4LNdAsm_32:
6520 case ARM::VLD4LNqAsm_16:
6521 case ARM::VLD4LNqAsm_32: {
6522 MCInst TmpInst;
6523 // Shuffle the operands around so the lane index operand is in the
6524 // right place.
6525 unsigned Spacing;
6526 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6527 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6529 Spacing));
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6531 Spacing * 2));
6532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6533 Spacing * 3));
6534 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6535 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6536 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 Spacing));
6539 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6540 Spacing * 2));
6541 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6542 Spacing * 3));
6543 TmpInst.addOperand(Inst.getOperand(1)); // lane
6544 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6545 TmpInst.addOperand(Inst.getOperand(5));
6546 Inst = TmpInst;
6547 return true;
6548 }
6549
Jim Grosbachb78403c2012-01-24 23:47:04 +00006550 // VLD3DUP single 3-element structure to all lanes instructions.
6551 case ARM::VLD3DUPdAsm_8:
6552 case ARM::VLD3DUPdAsm_16:
6553 case ARM::VLD3DUPdAsm_32:
6554 case ARM::VLD3DUPqAsm_8:
6555 case ARM::VLD3DUPqAsm_16:
6556 case ARM::VLD3DUPqAsm_32: {
6557 MCInst TmpInst;
6558 unsigned Spacing;
6559 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6560 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6562 Spacing));
6563 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6564 Spacing * 2));
6565 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6566 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6567 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6568 TmpInst.addOperand(Inst.getOperand(4));
6569 Inst = TmpInst;
6570 return true;
6571 }
6572
6573 case ARM::VLD3DUPdWB_fixed_Asm_8:
6574 case ARM::VLD3DUPdWB_fixed_Asm_16:
6575 case ARM::VLD3DUPdWB_fixed_Asm_32:
6576 case ARM::VLD3DUPqWB_fixed_Asm_8:
6577 case ARM::VLD3DUPqWB_fixed_Asm_16:
6578 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6579 MCInst TmpInst;
6580 unsigned Spacing;
6581 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6582 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6583 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6584 Spacing));
6585 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6586 Spacing * 2));
6587 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6588 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6589 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6590 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6591 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6592 TmpInst.addOperand(Inst.getOperand(4));
6593 Inst = TmpInst;
6594 return true;
6595 }
6596
6597 case ARM::VLD3DUPdWB_register_Asm_8:
6598 case ARM::VLD3DUPdWB_register_Asm_16:
6599 case ARM::VLD3DUPdWB_register_Asm_32:
6600 case ARM::VLD3DUPqWB_register_Asm_8:
6601 case ARM::VLD3DUPqWB_register_Asm_16:
6602 case ARM::VLD3DUPqWB_register_Asm_32: {
6603 MCInst TmpInst;
6604 unsigned Spacing;
6605 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6606 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6607 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6608 Spacing));
6609 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6610 Spacing * 2));
6611 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6612 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6613 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6614 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6615 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6616 TmpInst.addOperand(Inst.getOperand(5));
6617 Inst = TmpInst;
6618 return true;
6619 }
6620
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006621 // VLD3 multiple 3-element structure instructions.
6622 case ARM::VLD3dAsm_8:
6623 case ARM::VLD3dAsm_16:
6624 case ARM::VLD3dAsm_32:
6625 case ARM::VLD3qAsm_8:
6626 case ARM::VLD3qAsm_16:
6627 case ARM::VLD3qAsm_32: {
6628 MCInst TmpInst;
6629 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006630 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006631 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6632 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 Spacing));
6634 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6635 Spacing * 2));
6636 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6637 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6638 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6639 TmpInst.addOperand(Inst.getOperand(4));
6640 Inst = TmpInst;
6641 return true;
6642 }
6643
6644 case ARM::VLD3dWB_fixed_Asm_8:
6645 case ARM::VLD3dWB_fixed_Asm_16:
6646 case ARM::VLD3dWB_fixed_Asm_32:
6647 case ARM::VLD3qWB_fixed_Asm_8:
6648 case ARM::VLD3qWB_fixed_Asm_16:
6649 case ARM::VLD3qWB_fixed_Asm_32: {
6650 MCInst TmpInst;
6651 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006652 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006653 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6654 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6655 Spacing));
6656 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6657 Spacing * 2));
6658 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6659 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6660 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6661 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6662 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6663 TmpInst.addOperand(Inst.getOperand(4));
6664 Inst = TmpInst;
6665 return true;
6666 }
6667
6668 case ARM::VLD3dWB_register_Asm_8:
6669 case ARM::VLD3dWB_register_Asm_16:
6670 case ARM::VLD3dWB_register_Asm_32:
6671 case ARM::VLD3qWB_register_Asm_8:
6672 case ARM::VLD3qWB_register_Asm_16:
6673 case ARM::VLD3qWB_register_Asm_32: {
6674 MCInst TmpInst;
6675 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006676 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006677 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6678 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6679 Spacing));
6680 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6681 Spacing * 2));
6682 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6683 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6684 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6685 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6686 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6687 TmpInst.addOperand(Inst.getOperand(5));
6688 Inst = TmpInst;
6689 return true;
6690 }
6691
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006692 // VLD4DUP single 3-element structure to all lanes instructions.
6693 case ARM::VLD4DUPdAsm_8:
6694 case ARM::VLD4DUPdAsm_16:
6695 case ARM::VLD4DUPdAsm_32:
6696 case ARM::VLD4DUPqAsm_8:
6697 case ARM::VLD4DUPqAsm_16:
6698 case ARM::VLD4DUPqAsm_32: {
6699 MCInst TmpInst;
6700 unsigned Spacing;
6701 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6702 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6703 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6704 Spacing));
6705 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6706 Spacing * 2));
6707 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6708 Spacing * 3));
6709 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6710 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6711 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6712 TmpInst.addOperand(Inst.getOperand(4));
6713 Inst = TmpInst;
6714 return true;
6715 }
6716
6717 case ARM::VLD4DUPdWB_fixed_Asm_8:
6718 case ARM::VLD4DUPdWB_fixed_Asm_16:
6719 case ARM::VLD4DUPdWB_fixed_Asm_32:
6720 case ARM::VLD4DUPqWB_fixed_Asm_8:
6721 case ARM::VLD4DUPqWB_fixed_Asm_16:
6722 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6723 MCInst TmpInst;
6724 unsigned Spacing;
6725 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6726 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6727 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6728 Spacing));
6729 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6730 Spacing * 2));
6731 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6732 Spacing * 3));
6733 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6734 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6735 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6736 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6737 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6738 TmpInst.addOperand(Inst.getOperand(4));
6739 Inst = TmpInst;
6740 return true;
6741 }
6742
6743 case ARM::VLD4DUPdWB_register_Asm_8:
6744 case ARM::VLD4DUPdWB_register_Asm_16:
6745 case ARM::VLD4DUPdWB_register_Asm_32:
6746 case ARM::VLD4DUPqWB_register_Asm_8:
6747 case ARM::VLD4DUPqWB_register_Asm_16:
6748 case ARM::VLD4DUPqWB_register_Asm_32: {
6749 MCInst TmpInst;
6750 unsigned Spacing;
6751 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6752 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6754 Spacing));
6755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6756 Spacing * 2));
6757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6758 Spacing * 3));
6759 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6760 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6761 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6762 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6763 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6764 TmpInst.addOperand(Inst.getOperand(5));
6765 Inst = TmpInst;
6766 return true;
6767 }
6768
6769 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006770 case ARM::VLD4dAsm_8:
6771 case ARM::VLD4dAsm_16:
6772 case ARM::VLD4dAsm_32:
6773 case ARM::VLD4qAsm_8:
6774 case ARM::VLD4qAsm_16:
6775 case ARM::VLD4qAsm_32: {
6776 MCInst TmpInst;
6777 unsigned Spacing;
6778 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6779 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6780 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6781 Spacing));
6782 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6783 Spacing * 2));
6784 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6785 Spacing * 3));
6786 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6787 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6788 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6789 TmpInst.addOperand(Inst.getOperand(4));
6790 Inst = TmpInst;
6791 return true;
6792 }
6793
6794 case ARM::VLD4dWB_fixed_Asm_8:
6795 case ARM::VLD4dWB_fixed_Asm_16:
6796 case ARM::VLD4dWB_fixed_Asm_32:
6797 case ARM::VLD4qWB_fixed_Asm_8:
6798 case ARM::VLD4qWB_fixed_Asm_16:
6799 case ARM::VLD4qWB_fixed_Asm_32: {
6800 MCInst TmpInst;
6801 unsigned Spacing;
6802 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6803 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6804 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6805 Spacing));
6806 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6807 Spacing * 2));
6808 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6809 Spacing * 3));
6810 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6811 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6812 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6813 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6814 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6815 TmpInst.addOperand(Inst.getOperand(4));
6816 Inst = TmpInst;
6817 return true;
6818 }
6819
6820 case ARM::VLD4dWB_register_Asm_8:
6821 case ARM::VLD4dWB_register_Asm_16:
6822 case ARM::VLD4dWB_register_Asm_32:
6823 case ARM::VLD4qWB_register_Asm_8:
6824 case ARM::VLD4qWB_register_Asm_16:
6825 case ARM::VLD4qWB_register_Asm_32: {
6826 MCInst TmpInst;
6827 unsigned Spacing;
6828 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6829 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6830 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6831 Spacing));
6832 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6833 Spacing * 2));
6834 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6835 Spacing * 3));
6836 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6837 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6838 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6839 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6840 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6841 TmpInst.addOperand(Inst.getOperand(5));
6842 Inst = TmpInst;
6843 return true;
6844 }
6845
Jim Grosbach1a747242012-01-23 23:45:44 +00006846 // VST3 multiple 3-element structure instructions.
6847 case ARM::VST3dAsm_8:
6848 case ARM::VST3dAsm_16:
6849 case ARM::VST3dAsm_32:
6850 case ARM::VST3qAsm_8:
6851 case ARM::VST3qAsm_16:
6852 case ARM::VST3qAsm_32: {
6853 MCInst TmpInst;
6854 unsigned Spacing;
6855 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6856 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6857 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6858 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6859 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6860 Spacing));
6861 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6862 Spacing * 2));
6863 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6864 TmpInst.addOperand(Inst.getOperand(4));
6865 Inst = TmpInst;
6866 return true;
6867 }
6868
6869 case ARM::VST3dWB_fixed_Asm_8:
6870 case ARM::VST3dWB_fixed_Asm_16:
6871 case ARM::VST3dWB_fixed_Asm_32:
6872 case ARM::VST3qWB_fixed_Asm_8:
6873 case ARM::VST3qWB_fixed_Asm_16:
6874 case ARM::VST3qWB_fixed_Asm_32: {
6875 MCInst TmpInst;
6876 unsigned Spacing;
6877 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6878 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6879 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6880 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6881 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6882 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6883 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6884 Spacing));
6885 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6886 Spacing * 2));
6887 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6888 TmpInst.addOperand(Inst.getOperand(4));
6889 Inst = TmpInst;
6890 return true;
6891 }
6892
6893 case ARM::VST3dWB_register_Asm_8:
6894 case ARM::VST3dWB_register_Asm_16:
6895 case ARM::VST3dWB_register_Asm_32:
6896 case ARM::VST3qWB_register_Asm_8:
6897 case ARM::VST3qWB_register_Asm_16:
6898 case ARM::VST3qWB_register_Asm_32: {
6899 MCInst TmpInst;
6900 unsigned Spacing;
6901 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6902 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6903 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6904 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6905 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6906 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6907 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6908 Spacing));
6909 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6910 Spacing * 2));
6911 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6912 TmpInst.addOperand(Inst.getOperand(5));
6913 Inst = TmpInst;
6914 return true;
6915 }
6916
Jim Grosbachda70eac2012-01-24 00:58:13 +00006917 // VST4 multiple 3-element structure instructions.
6918 case ARM::VST4dAsm_8:
6919 case ARM::VST4dAsm_16:
6920 case ARM::VST4dAsm_32:
6921 case ARM::VST4qAsm_8:
6922 case ARM::VST4qAsm_16:
6923 case ARM::VST4qAsm_32: {
6924 MCInst TmpInst;
6925 unsigned Spacing;
6926 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6927 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6928 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6929 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6930 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6931 Spacing));
6932 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6933 Spacing * 2));
6934 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6935 Spacing * 3));
6936 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6937 TmpInst.addOperand(Inst.getOperand(4));
6938 Inst = TmpInst;
6939 return true;
6940 }
6941
6942 case ARM::VST4dWB_fixed_Asm_8:
6943 case ARM::VST4dWB_fixed_Asm_16:
6944 case ARM::VST4dWB_fixed_Asm_32:
6945 case ARM::VST4qWB_fixed_Asm_8:
6946 case ARM::VST4qWB_fixed_Asm_16:
6947 case ARM::VST4qWB_fixed_Asm_32: {
6948 MCInst TmpInst;
6949 unsigned Spacing;
6950 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6951 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6952 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6953 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6954 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6955 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6956 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6957 Spacing));
6958 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6959 Spacing * 2));
6960 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6961 Spacing * 3));
6962 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6963 TmpInst.addOperand(Inst.getOperand(4));
6964 Inst = TmpInst;
6965 return true;
6966 }
6967
6968 case ARM::VST4dWB_register_Asm_8:
6969 case ARM::VST4dWB_register_Asm_16:
6970 case ARM::VST4dWB_register_Asm_32:
6971 case ARM::VST4qWB_register_Asm_8:
6972 case ARM::VST4qWB_register_Asm_16:
6973 case ARM::VST4qWB_register_Asm_32: {
6974 MCInst TmpInst;
6975 unsigned Spacing;
6976 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6977 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6978 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6979 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6980 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6981 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6982 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6983 Spacing));
6984 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6985 Spacing * 2));
6986 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6987 Spacing * 3));
6988 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6989 TmpInst.addOperand(Inst.getOperand(5));
6990 Inst = TmpInst;
6991 return true;
6992 }
6993
Jim Grosbachad66de12012-04-11 00:15:16 +00006994 // Handle encoding choice for the shift-immediate instructions.
6995 case ARM::t2LSLri:
6996 case ARM::t2LSRri:
6997 case ARM::t2ASRri: {
6998 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6999 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7000 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7001 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7002 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7003 unsigned NewOpc;
7004 switch (Inst.getOpcode()) {
7005 default: llvm_unreachable("unexpected opcode");
7006 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7007 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7008 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7009 }
7010 // The Thumb1 operands aren't in the same order. Awesome, eh?
7011 MCInst TmpInst;
7012 TmpInst.setOpcode(NewOpc);
7013 TmpInst.addOperand(Inst.getOperand(0));
7014 TmpInst.addOperand(Inst.getOperand(5));
7015 TmpInst.addOperand(Inst.getOperand(1));
7016 TmpInst.addOperand(Inst.getOperand(2));
7017 TmpInst.addOperand(Inst.getOperand(3));
7018 TmpInst.addOperand(Inst.getOperand(4));
7019 Inst = TmpInst;
7020 return true;
7021 }
7022 return false;
7023 }
7024
Jim Grosbach485e5622011-12-13 22:45:11 +00007025 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007026 case ARM::t2MOVsr:
7027 case ARM::t2MOVSsr: {
7028 // Which instruction to expand to depends on the CCOut operand and
7029 // whether we're in an IT block if the register operands are low
7030 // registers.
7031 bool isNarrow = false;
7032 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7033 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7034 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7035 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7036 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7037 isNarrow = true;
7038 MCInst TmpInst;
7039 unsigned newOpc;
7040 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7041 default: llvm_unreachable("unexpected opcode!");
7042 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7043 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7044 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7045 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7046 }
7047 TmpInst.setOpcode(newOpc);
7048 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7049 if (isNarrow)
7050 TmpInst.addOperand(MCOperand::CreateReg(
7051 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7052 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7053 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7054 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7055 TmpInst.addOperand(Inst.getOperand(5));
7056 if (!isNarrow)
7057 TmpInst.addOperand(MCOperand::CreateReg(
7058 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7059 Inst = TmpInst;
7060 return true;
7061 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007062 case ARM::t2MOVsi:
7063 case ARM::t2MOVSsi: {
7064 // Which instruction to expand to depends on the CCOut operand and
7065 // whether we're in an IT block if the register operands are low
7066 // registers.
7067 bool isNarrow = false;
7068 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7069 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7070 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7071 isNarrow = true;
7072 MCInst TmpInst;
7073 unsigned newOpc;
7074 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7075 default: llvm_unreachable("unexpected opcode!");
7076 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7077 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7078 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7079 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007080 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007081 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007082 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7083 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007084 TmpInst.setOpcode(newOpc);
7085 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7086 if (isNarrow)
7087 TmpInst.addOperand(MCOperand::CreateReg(
7088 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7089 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007090 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007091 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007092 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7093 TmpInst.addOperand(Inst.getOperand(4));
7094 if (!isNarrow)
7095 TmpInst.addOperand(MCOperand::CreateReg(
7096 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7097 Inst = TmpInst;
7098 return true;
7099 }
7100 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007101 case ARM::ASRr:
7102 case ARM::LSRr:
7103 case ARM::LSLr:
7104 case ARM::RORr: {
7105 ARM_AM::ShiftOpc ShiftTy;
7106 switch(Inst.getOpcode()) {
7107 default: llvm_unreachable("unexpected opcode!");
7108 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7109 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7110 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7111 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7112 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007113 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7114 MCInst TmpInst;
7115 TmpInst.setOpcode(ARM::MOVsr);
7116 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7117 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7118 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7119 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7120 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7121 TmpInst.addOperand(Inst.getOperand(4));
7122 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7123 Inst = TmpInst;
7124 return true;
7125 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007126 case ARM::ASRi:
7127 case ARM::LSRi:
7128 case ARM::LSLi:
7129 case ARM::RORi: {
7130 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007131 switch(Inst.getOpcode()) {
7132 default: llvm_unreachable("unexpected opcode!");
7133 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7134 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7135 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7136 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7137 }
7138 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007139 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007140 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007141 // A shift by 32 should be encoded as 0 when permitted
7142 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7143 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007144 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007145 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007146 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007147 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7148 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007149 if (Opc == ARM::MOVsi)
7150 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007151 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7152 TmpInst.addOperand(Inst.getOperand(4));
7153 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7154 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007155 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007156 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007157 case ARM::RRXi: {
7158 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7159 MCInst TmpInst;
7160 TmpInst.setOpcode(ARM::MOVsi);
7161 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7162 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7163 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7164 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7165 TmpInst.addOperand(Inst.getOperand(3));
7166 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7167 Inst = TmpInst;
7168 return true;
7169 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007170 case ARM::t2LDMIA_UPD: {
7171 // If this is a load of a single register, then we should use
7172 // a post-indexed LDR instruction instead, per the ARM ARM.
7173 if (Inst.getNumOperands() != 5)
7174 return false;
7175 MCInst TmpInst;
7176 TmpInst.setOpcode(ARM::t2LDR_POST);
7177 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7178 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7179 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7180 TmpInst.addOperand(MCOperand::CreateImm(4));
7181 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7182 TmpInst.addOperand(Inst.getOperand(3));
7183 Inst = TmpInst;
7184 return true;
7185 }
7186 case ARM::t2STMDB_UPD: {
7187 // If this is a store of a single register, then we should use
7188 // a pre-indexed STR instruction instead, per the ARM ARM.
7189 if (Inst.getNumOperands() != 5)
7190 return false;
7191 MCInst TmpInst;
7192 TmpInst.setOpcode(ARM::t2STR_PRE);
7193 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7194 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7195 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7196 TmpInst.addOperand(MCOperand::CreateImm(-4));
7197 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7198 TmpInst.addOperand(Inst.getOperand(3));
7199 Inst = TmpInst;
7200 return true;
7201 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007202 case ARM::LDMIA_UPD:
7203 // If this is a load of a single register via a 'pop', then we should use
7204 // a post-indexed LDR instruction instead, per the ARM ARM.
7205 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7206 Inst.getNumOperands() == 5) {
7207 MCInst TmpInst;
7208 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7209 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7210 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7211 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7212 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7213 TmpInst.addOperand(MCOperand::CreateImm(4));
7214 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7215 TmpInst.addOperand(Inst.getOperand(3));
7216 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007217 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007218 }
7219 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007220 case ARM::STMDB_UPD:
7221 // If this is a store of a single register via a 'push', then we should use
7222 // a pre-indexed STR instruction instead, per the ARM ARM.
7223 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7224 Inst.getNumOperands() == 5) {
7225 MCInst TmpInst;
7226 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7227 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7228 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7229 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7230 TmpInst.addOperand(MCOperand::CreateImm(-4));
7231 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7232 TmpInst.addOperand(Inst.getOperand(3));
7233 Inst = TmpInst;
7234 }
7235 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007236 case ARM::t2ADDri12:
7237 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7238 // mnemonic was used (not "addw"), encoding T3 is preferred.
7239 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7240 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7241 break;
7242 Inst.setOpcode(ARM::t2ADDri);
7243 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7244 break;
7245 case ARM::t2SUBri12:
7246 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7247 // mnemonic was used (not "subw"), encoding T3 is preferred.
7248 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7249 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7250 break;
7251 Inst.setOpcode(ARM::t2SUBri);
7252 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7253 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007254 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007255 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007256 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7257 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7258 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007259 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007260 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007261 return true;
7262 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007263 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007264 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007265 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007266 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7267 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7268 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007269 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007270 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007271 return true;
7272 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007273 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007274 case ARM::t2ADDri:
7275 case ARM::t2SUBri: {
7276 // If the destination and first source operand are the same, and
7277 // the flags are compatible with the current IT status, use encoding T2
7278 // instead of T3. For compatibility with the system 'as'. Make sure the
7279 // wide encoding wasn't explicit.
7280 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007281 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007282 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7283 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7284 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7285 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7286 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7287 break;
7288 MCInst TmpInst;
7289 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7290 ARM::tADDi8 : ARM::tSUBi8);
7291 TmpInst.addOperand(Inst.getOperand(0));
7292 TmpInst.addOperand(Inst.getOperand(5));
7293 TmpInst.addOperand(Inst.getOperand(0));
7294 TmpInst.addOperand(Inst.getOperand(2));
7295 TmpInst.addOperand(Inst.getOperand(3));
7296 TmpInst.addOperand(Inst.getOperand(4));
7297 Inst = TmpInst;
7298 return true;
7299 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007300 case ARM::t2ADDrr: {
7301 // If the destination and first source operand are the same, and
7302 // there's no setting of the flags, use encoding T2 instead of T3.
7303 // Note that this is only for ADD, not SUB. This mirrors the system
7304 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7305 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7306 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007307 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7308 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007309 break;
7310 MCInst TmpInst;
7311 TmpInst.setOpcode(ARM::tADDhirr);
7312 TmpInst.addOperand(Inst.getOperand(0));
7313 TmpInst.addOperand(Inst.getOperand(0));
7314 TmpInst.addOperand(Inst.getOperand(2));
7315 TmpInst.addOperand(Inst.getOperand(3));
7316 TmpInst.addOperand(Inst.getOperand(4));
7317 Inst = TmpInst;
7318 return true;
7319 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007320 case ARM::tADDrSP: {
7321 // If the non-SP source operand and the destination operand are not the
7322 // same, we need to use the 32-bit encoding if it's available.
7323 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7324 Inst.setOpcode(ARM::t2ADDrr);
7325 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7326 return true;
7327 }
7328 break;
7329 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007330 case ARM::tB:
7331 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007332 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007333 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007334 return true;
7335 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007336 break;
7337 case ARM::t2B:
7338 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007339 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007340 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007341 return true;
7342 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007343 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007344 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007345 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007346 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007347 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007348 return true;
7349 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007350 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007351 case ARM::tBcc:
7352 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007353 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007354 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007355 return true;
7356 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007357 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007358 case ARM::tLDMIA: {
7359 // If the register list contains any high registers, or if the writeback
7360 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7361 // instead if we're in Thumb2. Otherwise, this should have generated
7362 // an error in validateInstruction().
7363 unsigned Rn = Inst.getOperand(0).getReg();
7364 bool hasWritebackToken =
7365 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7366 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7367 bool listContainsBase;
7368 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7369 (!listContainsBase && !hasWritebackToken) ||
7370 (listContainsBase && hasWritebackToken)) {
7371 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7372 assert (isThumbTwo());
7373 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7374 // If we're switching to the updating version, we need to insert
7375 // the writeback tied operand.
7376 if (hasWritebackToken)
7377 Inst.insert(Inst.begin(),
7378 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007379 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007380 }
7381 break;
7382 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007383 case ARM::tSTMIA_UPD: {
7384 // If the register list contains any high registers, we need to use
7385 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7386 // should have generated an error in validateInstruction().
7387 unsigned Rn = Inst.getOperand(0).getReg();
7388 bool listContainsBase;
7389 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7390 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7391 assert (isThumbTwo());
7392 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007393 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007394 }
7395 break;
7396 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007397 case ARM::tPOP: {
7398 bool listContainsBase;
7399 // If the register list contains any high registers, we need to use
7400 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7401 // should have generated an error in validateInstruction().
7402 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007403 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007404 assert (isThumbTwo());
7405 Inst.setOpcode(ARM::t2LDMIA_UPD);
7406 // Add the base register and writeback operands.
7407 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7408 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007409 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007410 }
7411 case ARM::tPUSH: {
7412 bool listContainsBase;
7413 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007414 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007415 assert (isThumbTwo());
7416 Inst.setOpcode(ARM::t2STMDB_UPD);
7417 // Add the base register and writeback operands.
7418 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7419 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007420 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007421 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007422 case ARM::t2MOVi: {
7423 // If we can use the 16-bit encoding and the user didn't explicitly
7424 // request the 32-bit variant, transform it here.
7425 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007426 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007427 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7428 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7429 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007430 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7431 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7432 // The operands aren't in the same order for tMOVi8...
7433 MCInst TmpInst;
7434 TmpInst.setOpcode(ARM::tMOVi8);
7435 TmpInst.addOperand(Inst.getOperand(0));
7436 TmpInst.addOperand(Inst.getOperand(4));
7437 TmpInst.addOperand(Inst.getOperand(1));
7438 TmpInst.addOperand(Inst.getOperand(2));
7439 TmpInst.addOperand(Inst.getOperand(3));
7440 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007441 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007442 }
7443 break;
7444 }
7445 case ARM::t2MOVr: {
7446 // If we can use the 16-bit encoding and the user didn't explicitly
7447 // request the 32-bit variant, transform it here.
7448 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7449 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7450 Inst.getOperand(2).getImm() == ARMCC::AL &&
7451 Inst.getOperand(4).getReg() == ARM::CPSR &&
7452 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7453 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7454 // The operands aren't the same for tMOV[S]r... (no cc_out)
7455 MCInst TmpInst;
7456 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7457 TmpInst.addOperand(Inst.getOperand(0));
7458 TmpInst.addOperand(Inst.getOperand(1));
7459 TmpInst.addOperand(Inst.getOperand(2));
7460 TmpInst.addOperand(Inst.getOperand(3));
7461 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007462 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007463 }
7464 break;
7465 }
Jim Grosbach82213192011-09-19 20:29:33 +00007466 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007467 case ARM::t2SXTB:
7468 case ARM::t2UXTH:
7469 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007470 // If we can use the 16-bit encoding and the user didn't explicitly
7471 // request the 32-bit variant, transform it here.
7472 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7473 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7474 Inst.getOperand(2).getImm() == 0 &&
7475 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7476 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007477 unsigned NewOpc;
7478 switch (Inst.getOpcode()) {
7479 default: llvm_unreachable("Illegal opcode!");
7480 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7481 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7482 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7483 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7484 }
Jim Grosbach82213192011-09-19 20:29:33 +00007485 // The operands aren't the same for thumb1 (no rotate operand).
7486 MCInst TmpInst;
7487 TmpInst.setOpcode(NewOpc);
7488 TmpInst.addOperand(Inst.getOperand(0));
7489 TmpInst.addOperand(Inst.getOperand(1));
7490 TmpInst.addOperand(Inst.getOperand(3));
7491 TmpInst.addOperand(Inst.getOperand(4));
7492 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007493 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007494 }
7495 break;
7496 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007497 case ARM::MOVsi: {
7498 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007499 // rrx shifts and asr/lsr of #32 is encoded as 0
7500 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7501 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007502 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7503 // Shifting by zero is accepted as a vanilla 'MOVr'
7504 MCInst TmpInst;
7505 TmpInst.setOpcode(ARM::MOVr);
7506 TmpInst.addOperand(Inst.getOperand(0));
7507 TmpInst.addOperand(Inst.getOperand(1));
7508 TmpInst.addOperand(Inst.getOperand(3));
7509 TmpInst.addOperand(Inst.getOperand(4));
7510 TmpInst.addOperand(Inst.getOperand(5));
7511 Inst = TmpInst;
7512 return true;
7513 }
7514 return false;
7515 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007516 case ARM::ANDrsi:
7517 case ARM::ORRrsi:
7518 case ARM::EORrsi:
7519 case ARM::BICrsi:
7520 case ARM::SUBrsi:
7521 case ARM::ADDrsi: {
7522 unsigned newOpc;
7523 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7524 if (SOpc == ARM_AM::rrx) return false;
7525 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007526 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007527 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7528 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7529 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7530 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7531 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7532 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7533 }
7534 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007535 // The exception is for right shifts, where 0 == 32
7536 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7537 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007538 MCInst TmpInst;
7539 TmpInst.setOpcode(newOpc);
7540 TmpInst.addOperand(Inst.getOperand(0));
7541 TmpInst.addOperand(Inst.getOperand(1));
7542 TmpInst.addOperand(Inst.getOperand(2));
7543 TmpInst.addOperand(Inst.getOperand(4));
7544 TmpInst.addOperand(Inst.getOperand(5));
7545 TmpInst.addOperand(Inst.getOperand(6));
7546 Inst = TmpInst;
7547 return true;
7548 }
7549 return false;
7550 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007551 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007552 case ARM::t2IT: {
7553 // The mask bits for all but the first condition are represented as
7554 // the low bit of the condition code value implies 't'. We currently
7555 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007556 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007557 MCOperand &MO = Inst.getOperand(1);
7558 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007559 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007560 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007561 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007562 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007563 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007564 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007565 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007566
7567 // Set up the IT block state according to the IT instruction we just
7568 // matched.
7569 assert(!inITBlock() && "nested IT blocks?!");
7570 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7571 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7572 ITState.CurPosition = 0;
7573 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007574 break;
7575 }
Richard Bartona39625e2012-07-09 16:12:24 +00007576 case ARM::t2LSLrr:
7577 case ARM::t2LSRrr:
7578 case ARM::t2ASRrr:
7579 case ARM::t2SBCrr:
7580 case ARM::t2RORrr:
7581 case ARM::t2BICrr:
7582 {
Richard Bartond5660372012-07-09 16:14:28 +00007583 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007584 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7585 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7586 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007587 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7588 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007589 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7590 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7591 unsigned NewOpc;
7592 switch (Inst.getOpcode()) {
7593 default: llvm_unreachable("unexpected opcode");
7594 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7595 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7596 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7597 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7598 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7599 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7600 }
7601 MCInst TmpInst;
7602 TmpInst.setOpcode(NewOpc);
7603 TmpInst.addOperand(Inst.getOperand(0));
7604 TmpInst.addOperand(Inst.getOperand(5));
7605 TmpInst.addOperand(Inst.getOperand(1));
7606 TmpInst.addOperand(Inst.getOperand(2));
7607 TmpInst.addOperand(Inst.getOperand(3));
7608 TmpInst.addOperand(Inst.getOperand(4));
7609 Inst = TmpInst;
7610 return true;
7611 }
7612 return false;
7613 }
7614 case ARM::t2ANDrr:
7615 case ARM::t2EORrr:
7616 case ARM::t2ADCrr:
7617 case ARM::t2ORRrr:
7618 {
Richard Bartond5660372012-07-09 16:14:28 +00007619 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007620 // These instructions are special in that they are commutable, so shorter encodings
7621 // are available more often.
7622 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7623 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7624 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7625 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007626 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7627 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007628 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7629 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7630 unsigned NewOpc;
7631 switch (Inst.getOpcode()) {
7632 default: llvm_unreachable("unexpected opcode");
7633 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7634 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7635 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7636 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7637 }
7638 MCInst TmpInst;
7639 TmpInst.setOpcode(NewOpc);
7640 TmpInst.addOperand(Inst.getOperand(0));
7641 TmpInst.addOperand(Inst.getOperand(5));
7642 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7643 TmpInst.addOperand(Inst.getOperand(1));
7644 TmpInst.addOperand(Inst.getOperand(2));
7645 } else {
7646 TmpInst.addOperand(Inst.getOperand(2));
7647 TmpInst.addOperand(Inst.getOperand(1));
7648 }
7649 TmpInst.addOperand(Inst.getOperand(3));
7650 TmpInst.addOperand(Inst.getOperand(4));
7651 Inst = TmpInst;
7652 return true;
7653 }
7654 return false;
7655 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007656 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007657 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007658}
7659
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007660unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7661 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7662 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007663 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007664 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007665 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7666 assert(MCID.hasOptionalDef() &&
7667 "optionally flag setting instruction missing optional def operand");
7668 assert(MCID.NumOperands == Inst.getNumOperands() &&
7669 "operand count mismatch!");
7670 // Find the optional-def operand (cc_out).
7671 unsigned OpNo;
7672 for (OpNo = 0;
7673 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7674 ++OpNo)
7675 ;
7676 // If we're parsing Thumb1, reject it completely.
7677 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7678 return Match_MnemonicFail;
7679 // If we're parsing Thumb2, which form is legal depends on whether we're
7680 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007681 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7682 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007683 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007684 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7685 inITBlock())
7686 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007687 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007688 // Some high-register supporting Thumb1 encodings only allow both registers
7689 // to be from r0-r7 when in Thumb2.
7690 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7691 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7692 isARMLowRegister(Inst.getOperand(2).getReg()))
7693 return Match_RequiresThumb2;
7694 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007695 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007696 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7697 isARMLowRegister(Inst.getOperand(1).getReg()))
7698 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007699 return Match_Success;
7700}
7701
Jim Grosbach5117ef72012-04-24 22:40:08 +00007702static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007703bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007704MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007705 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007706 MCStreamer &Out, unsigned &ErrorInfo,
7707 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007708 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007709 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007710
Chad Rosier2f480a82012-10-12 22:53:36 +00007711 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007712 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007713 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007714 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007715 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007716 // Context sensitive operand constraints aren't handled by the matcher,
7717 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007718 if (validateInstruction(Inst, Operands)) {
7719 // Still progress the IT block, otherwise one wrong condition causes
7720 // nasty cascading errors.
7721 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007722 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007723 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007724
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007725 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007726 // encoding is selected. Loop on it while changes happen so the
7727 // individual transformations can chain off each other. E.g.,
7728 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7729 while (processInstruction(Inst, Operands))
7730 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007731
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007732 // Only move forward at the very end so that everything in validate
7733 // and process gets a consistent answer about whether we're in an IT
7734 // block.
7735 forwardITPosition();
7736
Jim Grosbach82f76d12012-01-25 19:52:01 +00007737 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7738 // doesn't actually encode.
7739 if (Inst.getOpcode() == ARM::ITasm)
7740 return false;
7741
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007742 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007743 Out.EmitInstruction(Inst);
7744 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007745 case Match_MissingFeature: {
7746 assert(ErrorInfo && "Unknown missing feature!");
7747 // Special case the error message for the very common case where only
7748 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7749 std::string Msg = "instruction requires:";
7750 unsigned Mask = 1;
7751 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7752 if (ErrorInfo & Mask) {
7753 Msg += " ";
7754 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7755 }
7756 Mask <<= 1;
7757 }
7758 return Error(IDLoc, Msg);
7759 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007760 case Match_InvalidOperand: {
7761 SMLoc ErrorLoc = IDLoc;
7762 if (ErrorInfo != ~0U) {
7763 if (ErrorInfo >= Operands.size())
7764 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007765
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007766 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7767 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7768 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007769
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007770 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007771 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007772 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007773 return Error(IDLoc, "invalid instruction",
7774 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007775 case Match_RequiresNotITBlock:
7776 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007777 case Match_RequiresITBlock:
7778 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007779 case Match_RequiresV6:
7780 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7781 case Match_RequiresThumb2:
7782 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007783 case Match_ImmRange0_4: {
7784 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7785 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7786 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7787 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007788 case Match_ImmRange0_15: {
7789 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7790 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7791 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7792 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007793 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007794
Eric Christopher91d7b902010-10-29 09:26:59 +00007795 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007796}
7797
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007798/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007799bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7800 StringRef IDVal = DirectiveID.getIdentifier();
7801 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007802 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007803 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007804 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007805 else if (IDVal == ".arm")
7806 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007807 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007808 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007809 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007810 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007811 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007812 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007813 else if (IDVal == ".unreq")
7814 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007815 else if (IDVal == ".arch")
7816 return parseDirectiveArch(DirectiveID.getLoc());
7817 else if (IDVal == ".eabi_attribute")
7818 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007819 else if (IDVal == ".fnstart")
7820 return parseDirectiveFnStart(DirectiveID.getLoc());
7821 else if (IDVal == ".fnend")
7822 return parseDirectiveFnEnd(DirectiveID.getLoc());
7823 else if (IDVal == ".cantunwind")
7824 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7825 else if (IDVal == ".personality")
7826 return parseDirectivePersonality(DirectiveID.getLoc());
7827 else if (IDVal == ".handlerdata")
7828 return parseDirectiveHandlerData(DirectiveID.getLoc());
7829 else if (IDVal == ".setfp")
7830 return parseDirectiveSetFP(DirectiveID.getLoc());
7831 else if (IDVal == ".pad")
7832 return parseDirectivePad(DirectiveID.getLoc());
7833 else if (IDVal == ".save")
7834 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7835 else if (IDVal == ".vsave")
7836 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007837 return true;
7838}
7839
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007840/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007841/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007842bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007843 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7844 for (;;) {
7845 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007846 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007847 return true;
7848
Eric Christopherbf7bc492013-01-09 03:52:05 +00007849 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007850
7851 if (getLexer().is(AsmToken::EndOfStatement))
7852 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007853
Kevin Enderbyccab3172009-09-15 00:27:25 +00007854 // FIXME: Improve diagnostic.
7855 if (getLexer().isNot(AsmToken::Comma))
7856 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007857 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007858 }
7859 }
7860
Sean Callanana83fd7d2010-01-19 20:27:46 +00007861 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007862 return false;
7863}
7864
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007865/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007866/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007867bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007868 if (getLexer().isNot(AsmToken::EndOfStatement))
7869 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007870 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007871
Tim Northovera2292d02013-06-10 23:20:58 +00007872 if (!hasThumb())
7873 return Error(L, "target does not support Thumb mode");
7874
Jim Grosbach7f882392011-12-07 18:04:19 +00007875 if (!isThumb())
7876 SwitchMode();
7877 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7878 return false;
7879}
7880
7881/// parseDirectiveARM
7882/// ::= .arm
7883bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7884 if (getLexer().isNot(AsmToken::EndOfStatement))
7885 return Error(L, "unexpected token in directive");
7886 Parser.Lex();
7887
Tim Northovera2292d02013-06-10 23:20:58 +00007888 if (!hasARM())
7889 return Error(L, "target does not support ARM mode");
7890
Jim Grosbach7f882392011-12-07 18:04:19 +00007891 if (isThumb())
7892 SwitchMode();
7893 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007894 return false;
7895}
7896
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007897/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007898/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007899bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007900 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7901 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007902 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007903 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007904
Jim Grosbach1152cc02011-12-21 22:30:16 +00007905 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007906 // ELF doesn't
7907 if (isMachO) {
7908 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007909 if (Tok.isNot(AsmToken::EndOfStatement)) {
7910 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7911 return Error(L, "unexpected token in .thumb_func directive");
7912 Name = Tok.getIdentifier();
7913 Parser.Lex(); // Consume the identifier token.
7914 needFuncName = false;
7915 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007916 }
7917
Jim Grosbach1152cc02011-12-21 22:30:16 +00007918 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007919 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007920
7921 // Eat the end of statement and any blank lines that follow.
7922 while (getLexer().is(AsmToken::EndOfStatement))
7923 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007924
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007925 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007926 // We really should be checking the next symbol definition even if there's
7927 // stuff in between.
7928 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007929 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007930 }
7931
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007932 // Mark symbol as a thumb symbol.
7933 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7934 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007935 return false;
7936}
7937
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007938/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007939/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007940bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007941 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007942 if (Tok.isNot(AsmToken::Identifier))
7943 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007944 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007945 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007946 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007947 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007948 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007949 else
7950 return Error(L, "unrecognized syntax mode in .syntax directive");
7951
7952 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007953 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007954 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007955
7956 // TODO tell the MC streamer the mode
7957 // getParser().getStreamer().Emit???();
7958 return false;
7959}
7960
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007961/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007962/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007963bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007964 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007965 if (Tok.isNot(AsmToken::Integer))
7966 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007967 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007968 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007969 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007970 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007971 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007972 else
7973 return Error(L, "invalid operand to .code directive");
7974
7975 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007976 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007977 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007978
Evan Cheng284b4672011-07-08 22:36:29 +00007979 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007980 if (!hasThumb())
7981 return Error(L, "target does not support Thumb mode");
7982
Jim Grosbachf471ac32011-09-06 18:46:23 +00007983 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007984 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007985 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007986 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007987 if (!hasARM())
7988 return Error(L, "target does not support ARM mode");
7989
Jim Grosbachf471ac32011-09-06 18:46:23 +00007990 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007991 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007992 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007993 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007994
Kevin Enderby146dcf22009-10-15 20:48:48 +00007995 return false;
7996}
7997
Jim Grosbachab5830e2011-12-14 02:16:11 +00007998/// parseDirectiveReq
7999/// ::= name .req registername
8000bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8001 Parser.Lex(); // Eat the '.req' token.
8002 unsigned Reg;
8003 SMLoc SRegLoc, ERegLoc;
8004 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008005 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008006 return Error(SRegLoc, "register name expected");
8007 }
8008
8009 // Shouldn't be anything else.
8010 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008011 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008012 return Error(Parser.getTok().getLoc(),
8013 "unexpected input in .req directive.");
8014 }
8015
8016 Parser.Lex(); // Consume the EndOfStatement
8017
8018 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
8019 return Error(SRegLoc, "redefinition of '" + Name +
8020 "' does not match original.");
8021
8022 return false;
8023}
8024
8025/// parseDirectiveUneq
8026/// ::= .unreq registername
8027bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8028 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008029 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008030 return Error(L, "unexpected input in .unreq directive.");
8031 }
8032 RegisterReqs.erase(Parser.getTok().getIdentifier());
8033 Parser.Lex(); // Eat the identifier.
8034 return false;
8035}
8036
Jason W Kim135d2442011-12-20 17:38:12 +00008037/// parseDirectiveArch
8038/// ::= .arch token
8039bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8040 return true;
8041}
8042
8043/// parseDirectiveEabiAttr
8044/// ::= .eabi_attribute int, int
8045bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8046 return true;
8047}
8048
Logan Chien4ea23b52013-05-10 16:17:24 +00008049/// parseDirectiveFnStart
8050/// ::= .fnstart
8051bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8052 if (FnStartLoc.isValid()) {
8053 Error(L, ".fnstart starts before the end of previous one");
8054 Error(FnStartLoc, "previous .fnstart starts here");
8055 return true;
8056 }
8057
8058 FnStartLoc = L;
8059 getParser().getStreamer().EmitFnStart();
8060 return false;
8061}
8062
8063/// parseDirectiveFnEnd
8064/// ::= .fnend
8065bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8066 // Check the ordering of unwind directives
8067 if (!FnStartLoc.isValid())
8068 return Error(L, ".fnstart must precede .fnend directive");
8069
8070 // Reset the unwind directives parser state
8071 resetUnwindDirectiveParserState();
8072
8073 getParser().getStreamer().EmitFnEnd();
8074 return false;
8075}
8076
8077/// parseDirectiveCantUnwind
8078/// ::= .cantunwind
8079bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8080 // Check the ordering of unwind directives
8081 CantUnwindLoc = L;
8082 if (!FnStartLoc.isValid())
8083 return Error(L, ".fnstart must precede .cantunwind directive");
8084 if (HandlerDataLoc.isValid()) {
8085 Error(L, ".cantunwind can't be used with .handlerdata directive");
8086 Error(HandlerDataLoc, ".handlerdata was specified here");
8087 return true;
8088 }
8089 if (PersonalityLoc.isValid()) {
8090 Error(L, ".cantunwind can't be used with .personality directive");
8091 Error(PersonalityLoc, ".personality was specified here");
8092 return true;
8093 }
8094
8095 getParser().getStreamer().EmitCantUnwind();
8096 return false;
8097}
8098
8099/// parseDirectivePersonality
8100/// ::= .personality name
8101bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8102 // Check the ordering of unwind directives
8103 PersonalityLoc = L;
8104 if (!FnStartLoc.isValid())
8105 return Error(L, ".fnstart must precede .personality directive");
8106 if (CantUnwindLoc.isValid()) {
8107 Error(L, ".personality can't be used with .cantunwind directive");
8108 Error(CantUnwindLoc, ".cantunwind was specified here");
8109 return true;
8110 }
8111 if (HandlerDataLoc.isValid()) {
8112 Error(L, ".personality must precede .handlerdata directive");
8113 Error(HandlerDataLoc, ".handlerdata was specified here");
8114 return true;
8115 }
8116
8117 // Parse the name of the personality routine
8118 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8119 Parser.eatToEndOfStatement();
8120 return Error(L, "unexpected input in .personality directive.");
8121 }
8122 StringRef Name(Parser.getTok().getIdentifier());
8123 Parser.Lex();
8124
8125 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8126 getParser().getStreamer().EmitPersonality(PR);
8127 return false;
8128}
8129
8130/// parseDirectiveHandlerData
8131/// ::= .handlerdata
8132bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8133 // Check the ordering of unwind directives
8134 HandlerDataLoc = L;
8135 if (!FnStartLoc.isValid())
8136 return Error(L, ".fnstart must precede .personality directive");
8137 if (CantUnwindLoc.isValid()) {
8138 Error(L, ".handlerdata can't be used with .cantunwind directive");
8139 Error(CantUnwindLoc, ".cantunwind was specified here");
8140 return true;
8141 }
8142
8143 getParser().getStreamer().EmitHandlerData();
8144 return false;
8145}
8146
8147/// parseDirectiveSetFP
8148/// ::= .setfp fpreg, spreg [, offset]
8149bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8150 // Check the ordering of unwind directives
8151 if (!FnStartLoc.isValid())
8152 return Error(L, ".fnstart must precede .setfp directive");
8153 if (HandlerDataLoc.isValid())
8154 return Error(L, ".setfp must precede .handlerdata directive");
8155
8156 // Parse fpreg
8157 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8158 int NewFPReg = tryParseRegister();
8159 if (NewFPReg == -1)
8160 return Error(NewFPRegLoc, "frame pointer register expected");
8161
8162 // Consume comma
8163 if (!Parser.getTok().is(AsmToken::Comma))
8164 return Error(Parser.getTok().getLoc(), "comma expected");
8165 Parser.Lex(); // skip comma
8166
8167 // Parse spreg
8168 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8169 int NewSPReg = tryParseRegister();
8170 if (NewSPReg == -1)
8171 return Error(NewSPRegLoc, "stack pointer register expected");
8172
8173 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8174 return Error(NewSPRegLoc,
8175 "register should be either $sp or the latest fp register");
8176
8177 // Update the frame pointer register
8178 FPReg = NewFPReg;
8179
8180 // Parse offset
8181 int64_t Offset = 0;
8182 if (Parser.getTok().is(AsmToken::Comma)) {
8183 Parser.Lex(); // skip comma
8184
8185 if (Parser.getTok().isNot(AsmToken::Hash) &&
8186 Parser.getTok().isNot(AsmToken::Dollar)) {
8187 return Error(Parser.getTok().getLoc(), "'#' expected");
8188 }
8189 Parser.Lex(); // skip hash token.
8190
8191 const MCExpr *OffsetExpr;
8192 SMLoc ExLoc = Parser.getTok().getLoc();
8193 SMLoc EndLoc;
8194 if (getParser().parseExpression(OffsetExpr, EndLoc))
8195 return Error(ExLoc, "malformed setfp offset");
8196 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8197 if (!CE)
8198 return Error(ExLoc, "setfp offset must be an immediate");
8199
8200 Offset = CE->getValue();
8201 }
8202
8203 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8204 static_cast<unsigned>(NewSPReg),
8205 Offset);
8206 return false;
8207}
8208
8209/// parseDirective
8210/// ::= .pad offset
8211bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8212 // Check the ordering of unwind directives
8213 if (!FnStartLoc.isValid())
8214 return Error(L, ".fnstart must precede .pad directive");
8215 if (HandlerDataLoc.isValid())
8216 return Error(L, ".pad must precede .handlerdata directive");
8217
8218 // Parse the offset
8219 if (Parser.getTok().isNot(AsmToken::Hash) &&
8220 Parser.getTok().isNot(AsmToken::Dollar)) {
8221 return Error(Parser.getTok().getLoc(), "'#' expected");
8222 }
8223 Parser.Lex(); // skip hash token.
8224
8225 const MCExpr *OffsetExpr;
8226 SMLoc ExLoc = Parser.getTok().getLoc();
8227 SMLoc EndLoc;
8228 if (getParser().parseExpression(OffsetExpr, EndLoc))
8229 return Error(ExLoc, "malformed pad offset");
8230 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8231 if (!CE)
8232 return Error(ExLoc, "pad offset must be an immediate");
8233
8234 getParser().getStreamer().EmitPad(CE->getValue());
8235 return false;
8236}
8237
8238/// parseDirectiveRegSave
8239/// ::= .save { registers }
8240/// ::= .vsave { registers }
8241bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8242 // Check the ordering of unwind directives
8243 if (!FnStartLoc.isValid())
8244 return Error(L, ".fnstart must precede .save or .vsave directives");
8245 if (HandlerDataLoc.isValid())
8246 return Error(L, ".save or .vsave must precede .handlerdata directive");
8247
8248 // Parse the register list
8249 SmallVector<MCParsedAsmOperand*, 1> Operands;
8250 if (parseRegisterList(Operands))
8251 return true;
8252 ARMOperand *Op = (ARMOperand*)Operands[0];
8253 if (!IsVector && !Op->isRegList())
8254 return Error(L, ".save expects GPR registers");
8255 if (IsVector && !Op->isDPRRegList())
8256 return Error(L, ".vsave expects DPR registers");
8257
8258 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8259 return false;
8260}
8261
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008262/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008263extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008264 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8265 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008266}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008267
Chris Lattner3e4582a2010-09-06 19:11:01 +00008268#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008269#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008270#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008271#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008272
8273// Define this matcher function after the auto-generated include so we
8274// have the match class enum definitions.
8275unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8276 unsigned Kind) {
8277 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8278 // If the kind is a token for a literal immediate, check if our asm
8279 // operand matches. This is for InstAliases which have a fixed-value
8280 // immediate in the syntax.
8281 if (Kind == MCK__35_0 && Op->isImm()) {
8282 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8283 if (!CE)
8284 return Match_InvalidOperand;
8285 if (CE->getValue() == 0)
8286 return Match_Success;
8287 }
8288 return Match_InvalidOperand;
8289}