blob: 6d6255f2cc2c891cc361afaffc594aaf5d34ebdf [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"
Joey Gouly0e76fa72013-09-12 10:28:05 +000027#include "llvm/MC/MCInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000028#include "llvm/MC/MCParser/MCAsmLexer.h"
29#include "llvm/MC/MCParser/MCAsmParser.h"
30#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
31#include "llvm/MC/MCRegisterInfo.h"
32#include "llvm/MC/MCStreamer.h"
33#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000034#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000035#include "llvm/Support/MathExtras.h"
36#include "llvm/Support/SourceMgr.h"
37#include "llvm/Support/TargetRegistry.h"
38#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000039
Kevin Enderbyccab3172009-09-15 00:27:25 +000040using namespace llvm;
41
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000042namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000043
44class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000045
Jim Grosbach04945c42011-12-02 00:35:16 +000046enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000047
Evan Cheng11424442011-07-26 00:24:13 +000048class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000049 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000050 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +000051 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000052 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000053
Logan Chien4ea23b52013-05-10 16:17:24 +000054 // Unwind directives state
55 SMLoc FnStartLoc;
56 SMLoc CantUnwindLoc;
57 SMLoc PersonalityLoc;
58 SMLoc HandlerDataLoc;
59 int FPReg;
60 void resetUnwindDirectiveParserState() {
61 FnStartLoc = SMLoc();
62 CantUnwindLoc = SMLoc();
63 PersonalityLoc = SMLoc();
64 HandlerDataLoc = SMLoc();
65 FPReg = -1;
66 }
67
Jim Grosbachab5830e2011-12-14 02:16:11 +000068 // Map of register aliases registers via the .req directive.
69 StringMap<unsigned> RegisterReqs;
70
Jim Grosbached16ec42011-08-29 22:24:09 +000071 struct {
72 ARMCC::CondCodes Cond; // Condition for IT block.
73 unsigned Mask:4; // Condition mask for instructions.
74 // Starting at first 1 (from lsb).
75 // '1' condition as indicated in IT.
76 // '0' inverse of condition (else).
77 // Count of instructions in IT block is
78 // 4 - trailingzeroes(mask)
79
80 bool FirstCond; // Explicit flag for when we're parsing the
81 // First instruction in the IT block. It's
82 // implied in the mask, so needs special
83 // handling.
84
85 unsigned CurPosition; // Current position in parsing of IT
86 // block. In range [0,3]. Initialized
87 // according to count of instructions in block.
88 // ~0U if no active IT block.
89 } ITState;
90 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000091 void forwardITPosition() {
92 if (!inITBlock()) return;
93 // Move to the next instruction in the IT block, if there is one. If not,
94 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +000095 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +000096 if (++ITState.CurPosition == 5 - TZ)
97 ITState.CurPosition = ~0U; // Done with the IT block after this.
98 }
Jim Grosbached16ec42011-08-29 22:24:09 +000099
100
Kevin Enderbyccab3172009-09-15 00:27:25 +0000101 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000102 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
103
Benjamin Kramer673824b2012-04-15 17:04:27 +0000104 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000105 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000106 return Parser.Warning(L, Msg, Ranges);
107 }
108 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000109 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000110 return Parser.Error(L, Msg, Ranges);
111 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000112
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000113 int tryParseRegister();
114 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000115 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000116 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000117 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000118 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
119 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000120 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
121 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000122 bool parseDirectiveWord(unsigned Size, SMLoc L);
123 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000124 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000125 bool parseDirectiveThumbFunc(SMLoc L);
126 bool parseDirectiveCode(SMLoc L);
127 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000128 bool parseDirectiveReq(StringRef Name, SMLoc L);
129 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000130 bool parseDirectiveArch(SMLoc L);
131 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000132 bool parseDirectiveFnStart(SMLoc L);
133 bool parseDirectiveFnEnd(SMLoc L);
134 bool parseDirectiveCantUnwind(SMLoc L);
135 bool parseDirectivePersonality(SMLoc L);
136 bool parseDirectiveHandlerData(SMLoc L);
137 bool parseDirectiveSetFP(SMLoc L);
138 bool parseDirectivePad(SMLoc L);
139 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000140
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000141 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000142 bool &CarrySetting, unsigned &ProcessorIMod,
143 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000144 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
145 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000146 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000147
Evan Cheng4d1ca962011-07-08 01:53:10 +0000148 bool isThumb() const {
149 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000150 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000151 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000152 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000154 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000155 bool isThumbTwo() const {
156 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
157 }
Tim Northovera2292d02013-06-10 23:20:58 +0000158 bool hasThumb() const {
159 return STI.getFeatureBits() & ARM::HasV4TOps;
160 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000161 bool hasV6Ops() const {
162 return STI.getFeatureBits() & ARM::HasV6Ops;
163 }
James Molloy21efa7d2011-09-28 14:21:38 +0000164 bool hasV7Ops() const {
165 return STI.getFeatureBits() & ARM::HasV7Ops;
166 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000167 bool hasV8Ops() const {
168 return STI.getFeatureBits() & ARM::HasV8Ops;
169 }
Tim Northovera2292d02013-06-10 23:20:58 +0000170 bool hasARM() const {
171 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
172 }
173
Evan Cheng284b4672011-07-08 22:36:29 +0000174 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000175 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
176 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000177 }
James Molloy21efa7d2011-09-28 14:21:38 +0000178 bool isMClass() const {
179 return STI.getFeatureBits() & ARM::FeatureMClass;
180 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000181
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000182 /// @name Auto-generated Match Functions
183 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000184
Chris Lattner3e4582a2010-09-06 19:11:01 +0000185#define GET_ASSEMBLER_HEADER
186#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000187
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000188 /// }
189
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000190 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000191 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000192 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000193 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000194 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000195 OperandMatchResultTy parseCoprocOptionOperand(
196 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000197 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000198 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000199 OperandMatchResultTy parseInstSyncBarrierOptOperand(
200 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000201 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000202 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000203 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000204 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000205 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
206 StringRef Op, int Low, int High);
207 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "lsl", 0, 31);
209 }
210 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
211 return parsePKHImm(O, "asr", 1, 32);
212 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000213 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000214 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000215 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000216 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000217 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000218 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000219 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000220 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000221 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
222 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000223
224 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000225 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000226 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000227 void cvtThumbBranches(MCInst &Inst,
228 const SmallVectorImpl<MCParsedAsmOperand*> &);
229
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000230 bool validateInstruction(MCInst &Inst,
231 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000232 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000233 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000234 bool shouldOmitCCOutOperand(StringRef Mnemonic,
235 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000236 bool shouldOmitPredicateOperand(StringRef Mnemonic,
237 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000238public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000239 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000240 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000241 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000242 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000243 Match_RequiresThumb2,
244#define GET_OPERAND_DIAGNOSTIC_TYPES
245#include "ARMGenAsmMatcher.inc"
246
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000247 };
248
Joey Gouly0e76fa72013-09-12 10:28:05 +0000249 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
250 const MCInstrInfo &MII)
251 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000252 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000253
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000254 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000255 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000256
Evan Cheng4d1ca962011-07-08 01:53:10 +0000257 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000258 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000259
260 // Not in an ITBlock to start with.
261 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000262
263 // Set ELF header flags.
264 // FIXME: This should eventually end up somewhere else where more
265 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000266 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
267 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
268 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000269 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000270
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000271 // Implementation of the MCTargetAsmParser interface:
272 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000273 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
274 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000275 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000276 bool ParseDirective(AsmToken DirectiveID);
277
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000278 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000279 unsigned checkTargetMatchPredicate(MCInst &Inst);
280
Chad Rosier49963552012-10-13 00:26:04 +0000281 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000282 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000283 MCStreamer &Out, unsigned &ErrorInfo,
284 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000285};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000286} // end anonymous namespace
287
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000288namespace {
289
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000290/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000291/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000292class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000293 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000294 k_CondCode,
295 k_CCOut,
296 k_ITCondMask,
297 k_CoprocNum,
298 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000299 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000300 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000301 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000302 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000303 k_Memory,
304 k_PostIndexRegister,
305 k_MSRMask,
306 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000307 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000308 k_Register,
309 k_RegisterList,
310 k_DPRRegisterList,
311 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000312 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000313 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000314 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000315 k_ShiftedRegister,
316 k_ShiftedImmediate,
317 k_ShifterImmediate,
318 k_RotateImmediate,
319 k_BitfieldDescriptor,
320 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000321 } Kind;
322
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000323 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000324 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000325
Eric Christopher8996c5d2013-03-15 00:42:55 +0000326 struct CCOp {
327 ARMCC::CondCodes Val;
328 };
329
330 struct CopOp {
331 unsigned Val;
332 };
333
334 struct CoprocOptionOp {
335 unsigned Val;
336 };
337
338 struct ITMaskOp {
339 unsigned Mask:4;
340 };
341
342 struct MBOptOp {
343 ARM_MB::MemBOpt Val;
344 };
345
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000346 struct ISBOptOp {
347 ARM_ISB::InstSyncBOpt Val;
348 };
349
Eric Christopher8996c5d2013-03-15 00:42:55 +0000350 struct IFlagsOp {
351 ARM_PROC::IFlags Val;
352 };
353
354 struct MMaskOp {
355 unsigned Val;
356 };
357
358 struct TokOp {
359 const char *Data;
360 unsigned Length;
361 };
362
363 struct RegOp {
364 unsigned RegNum;
365 };
366
367 // A vector register list is a sequential list of 1 to 4 registers.
368 struct VectorListOp {
369 unsigned RegNum;
370 unsigned Count;
371 unsigned LaneIndex;
372 bool isDoubleSpaced;
373 };
374
375 struct VectorIndexOp {
376 unsigned Val;
377 };
378
379 struct ImmOp {
380 const MCExpr *Val;
381 };
382
383 /// Combined record for all forms of ARM address expressions.
384 struct MemoryOp {
385 unsigned BaseRegNum;
386 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
387 // was specified.
388 const MCConstantExpr *OffsetImm; // Offset immediate value
389 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
390 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
391 unsigned ShiftImm; // shift for OffsetReg.
392 unsigned Alignment; // 0 = no alignment specified
393 // n = alignment in bytes (2, 4, 8, 16, or 32)
394 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
395 };
396
397 struct PostIdxRegOp {
398 unsigned RegNum;
399 bool isAdd;
400 ARM_AM::ShiftOpc ShiftTy;
401 unsigned ShiftImm;
402 };
403
404 struct ShifterImmOp {
405 bool isASR;
406 unsigned Imm;
407 };
408
409 struct RegShiftedRegOp {
410 ARM_AM::ShiftOpc ShiftTy;
411 unsigned SrcReg;
412 unsigned ShiftReg;
413 unsigned ShiftImm;
414 };
415
416 struct RegShiftedImmOp {
417 ARM_AM::ShiftOpc ShiftTy;
418 unsigned SrcReg;
419 unsigned ShiftImm;
420 };
421
422 struct RotImmOp {
423 unsigned Imm;
424 };
425
426 struct BitfieldOp {
427 unsigned LSB;
428 unsigned Width;
429 };
430
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000431 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000432 struct CCOp CC;
433 struct CopOp Cop;
434 struct CoprocOptionOp CoprocOption;
435 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000436 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000437 struct ITMaskOp ITMask;
438 struct IFlagsOp IFlags;
439 struct MMaskOp MMask;
440 struct TokOp Tok;
441 struct RegOp Reg;
442 struct VectorListOp VectorList;
443 struct VectorIndexOp VectorIndex;
444 struct ImmOp Imm;
445 struct MemoryOp Memory;
446 struct PostIdxRegOp PostIdxReg;
447 struct ShifterImmOp ShifterImm;
448 struct RegShiftedRegOp RegShiftedReg;
449 struct RegShiftedImmOp RegShiftedImm;
450 struct RotImmOp RotImm;
451 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000452 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000453
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000454 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
455public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000456 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
457 Kind = o.Kind;
458 StartLoc = o.StartLoc;
459 EndLoc = o.EndLoc;
460 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000461 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000462 CC = o.CC;
463 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000464 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000465 ITMask = o.ITMask;
466 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000467 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000468 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000469 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000470 case k_CCOut:
471 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000472 Reg = o.Reg;
473 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000474 case k_RegisterList:
475 case k_DPRRegisterList:
476 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000477 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000478 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000479 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000480 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000481 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000482 VectorList = o.VectorList;
483 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000484 case k_CoprocNum:
485 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000486 Cop = o.Cop;
487 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000488 case k_CoprocOption:
489 CoprocOption = o.CoprocOption;
490 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000491 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000492 Imm = o.Imm;
493 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000494 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000495 MBOpt = o.MBOpt;
496 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000497 case k_InstSyncBarrierOpt:
498 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000499 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000500 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000501 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000502 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000503 PostIdxReg = o.PostIdxReg;
504 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000505 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000506 MMask = o.MMask;
507 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000508 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000509 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000510 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000511 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000512 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000513 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000514 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000515 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000516 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000517 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000518 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000519 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000520 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000521 RotImm = o.RotImm;
522 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000523 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000524 Bitfield = o.Bitfield;
525 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000526 case k_VectorIndex:
527 VectorIndex = o.VectorIndex;
528 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000529 }
530 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000531
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000532 /// getStartLoc - Get the location of the first token of this operand.
533 SMLoc getStartLoc() const { return StartLoc; }
534 /// getEndLoc - Get the location of the last token of this operand.
535 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000536 /// getLocRange - Get the range between the first and last token of this
537 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000538 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
539
Daniel Dunbard8042b72010-08-11 06:36:53 +0000540 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000541 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000542 return CC.Val;
543 }
544
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000545 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000546 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000547 return Cop.Val;
548 }
549
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000550 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000551 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000552 return StringRef(Tok.Data, Tok.Length);
553 }
554
555 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000556 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000557 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000558 }
559
Bill Wendlingbed94652010-11-09 23:28:44 +0000560 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000561 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
562 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000563 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000564 }
565
Kevin Enderbyf5079942009-10-13 22:19:02 +0000566 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000567 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000568 return Imm.Val;
569 }
570
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000571 unsigned getVectorIndex() const {
572 assert(Kind == k_VectorIndex && "Invalid access!");
573 return VectorIndex.Val;
574 }
575
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000576 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000577 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000578 return MBOpt.Val;
579 }
580
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000581 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
582 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
583 return ISBOpt.Val;
584 }
585
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000586 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000587 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000588 return IFlags.Val;
589 }
590
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000591 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000592 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000593 return MMask.Val;
594 }
595
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000596 bool isCoprocNum() const { return Kind == k_CoprocNum; }
597 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000598 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000599 bool isCondCode() const { return Kind == k_CondCode; }
600 bool isCCOut() const { return Kind == k_CCOut; }
601 bool isITMask() const { return Kind == k_ITCondMask; }
602 bool isITCondCode() const { return Kind == k_CondCode; }
603 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000604 // checks whether this operand is an unsigned offset which fits is a field
605 // of specified width and scaled by a specific number of bits
606 template<unsigned width, unsigned scale>
607 bool isUnsignedOffset() const {
608 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000609 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000610 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
611 int64_t Val = CE->getValue();
612 int64_t Align = 1LL << scale;
613 int64_t Max = Align * ((1LL << width) - 1);
614 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
615 }
616 return false;
617 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000618 // checks whether this operand is an signed offset which fits is a field
619 // of specified width and scaled by a specific number of bits
620 template<unsigned width, unsigned scale>
621 bool isSignedOffset() const {
622 if (!isImm()) return false;
623 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
624 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
625 int64_t Val = CE->getValue();
626 int64_t Align = 1LL << scale;
627 int64_t Max = Align * ((1LL << (width-1)) - 1);
628 int64_t Min = -Align * (1LL << (width-1));
629 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
630 }
631 return false;
632 }
633
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000634 // checks whether this operand is a memory operand computed as an offset
635 // applied to PC. the offset may have 8 bits of magnitude and is represented
636 // with two bits of shift. textually it may be either [pc, #imm], #imm or
637 // relocable expression...
638 bool isThumbMemPC() const {
639 int64_t Val = 0;
640 if (isImm()) {
641 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
643 if (!CE) return false;
644 Val = CE->getValue();
645 }
646 else if (isMem()) {
647 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
648 if(Memory.BaseRegNum != ARM::PC) return false;
649 Val = Memory.OffsetImm->getValue();
650 }
651 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000652 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000653 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000654 bool isFPImm() const {
655 if (!isImm()) return false;
656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
657 if (!CE) return false;
658 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
659 return Val != -1;
660 }
Jim Grosbachea231912011-12-22 22:19:05 +0000661 bool isFBits16() const {
662 if (!isImm()) return false;
663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
664 if (!CE) return false;
665 int64_t Value = CE->getValue();
666 return Value >= 0 && Value <= 16;
667 }
668 bool isFBits32() const {
669 if (!isImm()) return false;
670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
671 if (!CE) return false;
672 int64_t Value = CE->getValue();
673 return Value >= 1 && Value <= 32;
674 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000675 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000676 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000677 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
678 if (!CE) return false;
679 int64_t Value = CE->getValue();
680 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
681 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000682 bool isImm0_4() const {
683 if (!isImm()) return false;
684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
685 if (!CE) return false;
686 int64_t Value = CE->getValue();
687 return Value >= 0 && Value < 5;
688 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000689 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000690 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
692 if (!CE) return false;
693 int64_t Value = CE->getValue();
694 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
695 }
696 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000697 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
699 if (!CE) return false;
700 int64_t Value = CE->getValue();
701 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
702 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000703 bool isImm0_508s4Neg() const {
704 if (!isImm()) return false;
705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
706 if (!CE) return false;
707 int64_t Value = -CE->getValue();
708 // explicitly exclude zero. we want that to use the normal 0_508 version.
709 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
710 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000711 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000712 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
714 if (!CE) return false;
715 int64_t Value = CE->getValue();
716 return Value >= 0 && Value < 256;
717 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000718 bool isImm0_4095() const {
719 if (!isImm()) return false;
720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
721 if (!CE) return false;
722 int64_t Value = CE->getValue();
723 return Value >= 0 && Value < 4096;
724 }
725 bool isImm0_4095Neg() const {
726 if (!isImm()) return false;
727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
728 if (!CE) return false;
729 int64_t Value = -CE->getValue();
730 return Value > 0 && Value < 4096;
731 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000732 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000733 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
735 if (!CE) return false;
736 int64_t Value = CE->getValue();
737 return Value >= 0 && Value < 2;
738 }
739 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000740 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000741 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
742 if (!CE) return false;
743 int64_t Value = CE->getValue();
744 return Value >= 0 && Value < 4;
745 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000746 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000747 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
749 if (!CE) return false;
750 int64_t Value = CE->getValue();
751 return Value >= 0 && Value < 8;
752 }
753 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000754 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
756 if (!CE) return false;
757 int64_t Value = CE->getValue();
758 return Value >= 0 && Value < 16;
759 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000760 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000761 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
763 if (!CE) return false;
764 int64_t Value = CE->getValue();
765 return Value >= 0 && Value < 32;
766 }
Jim Grosbach00326402011-12-08 01:30:04 +0000767 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000768 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
770 if (!CE) return false;
771 int64_t Value = CE->getValue();
772 return Value >= 0 && Value < 64;
773 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000774 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000775 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
777 if (!CE) return false;
778 int64_t Value = CE->getValue();
779 return Value == 8;
780 }
781 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000782 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
784 if (!CE) return false;
785 int64_t Value = CE->getValue();
786 return Value == 16;
787 }
788 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000789 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
791 if (!CE) return false;
792 int64_t Value = CE->getValue();
793 return Value == 32;
794 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000795 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000796 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000797 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
798 if (!CE) return false;
799 int64_t Value = CE->getValue();
800 return Value > 0 && Value <= 8;
801 }
802 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000803 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
805 if (!CE) return false;
806 int64_t Value = CE->getValue();
807 return Value > 0 && Value <= 16;
808 }
809 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000810 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
812 if (!CE) return false;
813 int64_t Value = CE->getValue();
814 return Value > 0 && Value <= 32;
815 }
816 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000817 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
819 if (!CE) return false;
820 int64_t Value = CE->getValue();
821 return Value > 0 && Value <= 64;
822 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000823 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000824 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
826 if (!CE) return false;
827 int64_t Value = CE->getValue();
828 return Value > 0 && Value < 8;
829 }
830 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000831 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
833 if (!CE) return false;
834 int64_t Value = CE->getValue();
835 return Value > 0 && Value < 16;
836 }
837 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000838 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000839 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
840 if (!CE) return false;
841 int64_t Value = CE->getValue();
842 return Value > 0 && Value < 32;
843 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000844 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000845 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000846 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
847 if (!CE) return false;
848 int64_t Value = CE->getValue();
849 return Value > 0 && Value < 17;
850 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000851 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000852 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
854 if (!CE) return false;
855 int64_t Value = CE->getValue();
856 return Value > 0 && Value < 33;
857 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000858 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000859 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
861 if (!CE) return false;
862 int64_t Value = CE->getValue();
863 return Value >= 0 && Value < 33;
864 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000865 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000866 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000867 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
868 if (!CE) return false;
869 int64_t Value = CE->getValue();
870 return Value >= 0 && Value < 65536;
871 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000872 bool isImm256_65535Expr() const {
873 if (!isImm()) return false;
874 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
875 // If it's not a constant expression, it'll generate a fixup and be
876 // handled later.
877 if (!CE) return true;
878 int64_t Value = CE->getValue();
879 return Value >= 256 && Value < 65536;
880 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000881 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000882 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 // If it's not a constant expression, it'll generate a fixup and be
885 // handled later.
886 if (!CE) return true;
887 int64_t Value = CE->getValue();
888 return Value >= 0 && Value < 65536;
889 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000890 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000891 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
893 if (!CE) return false;
894 int64_t Value = CE->getValue();
895 return Value >= 0 && Value <= 0xffffff;
896 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000897 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000898 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000899 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
900 if (!CE) return false;
901 int64_t Value = CE->getValue();
902 return Value > 0 && Value < 33;
903 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000904 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000905 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
907 if (!CE) return false;
908 int64_t Value = CE->getValue();
909 return Value >= 0 && Value < 32;
910 }
911 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000912 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
914 if (!CE) return false;
915 int64_t Value = CE->getValue();
916 return Value > 0 && Value <= 32;
917 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000918 bool isAdrLabel() const {
919 // If we have an immediate that's not a constant, treat it as a label
920 // reference needing a fixup. If it is a constant, but it can't fit
921 // into shift immediate encoding, we reject it.
922 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
923 else return (isARMSOImm() || isARMSOImmNeg());
924 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000925 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000926 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
928 if (!CE) return false;
929 int64_t Value = CE->getValue();
930 return ARM_AM::getSOImmVal(Value) != -1;
931 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000932 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000933 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
935 if (!CE) return false;
936 int64_t Value = CE->getValue();
937 return ARM_AM::getSOImmVal(~Value) != -1;
938 }
Jim Grosbach30506252011-12-08 00:31:07 +0000939 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000940 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000941 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
942 if (!CE) return false;
943 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000944 // Only use this when not representable as a plain so_imm.
945 return ARM_AM::getSOImmVal(Value) == -1 &&
946 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000947 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000948 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000949 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000950 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
951 if (!CE) return false;
952 int64_t Value = CE->getValue();
953 return ARM_AM::getT2SOImmVal(Value) != -1;
954 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000955 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000956 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000957 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
958 if (!CE) return false;
959 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +0000960 return ARM_AM::getT2SOImmVal(Value) == -1 &&
961 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +0000962 }
Jim Grosbach30506252011-12-08 00:31:07 +0000963 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000964 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000965 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
966 if (!CE) return false;
967 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000968 // Only use this when not representable as a plain so_imm.
969 return ARM_AM::getT2SOImmVal(Value) == -1 &&
970 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000971 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000972 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000973 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000974 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
975 if (!CE) return false;
976 int64_t Value = CE->getValue();
977 return Value == 1 || Value == 0;
978 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000979 bool isReg() const { return Kind == k_Register; }
980 bool isRegList() const { return Kind == k_RegisterList; }
981 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
982 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
983 bool isToken() const { return Kind == k_Token; }
984 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000985 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000986 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000987 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
988 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
989 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
990 bool isRotImm() const { return Kind == k_RotateImmediate; }
991 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
992 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000993 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000994 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000995 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000996 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000997 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000998 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000999 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +00001000 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1001 (alignOK || Memory.Alignment == 0);
1002 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001003 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001004 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001005 return false;
1006 // Base register must be PC.
1007 if (Memory.BaseRegNum != ARM::PC)
1008 return false;
1009 // Immediate offset in range [-4095, 4095].
1010 if (!Memory.OffsetImm) return true;
1011 int64_t Val = Memory.OffsetImm->getValue();
1012 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1013 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001014 bool isAlignedMemory() const {
1015 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001016 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001017 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001018 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001019 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001020 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001021 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001022 if (!Memory.OffsetImm) return true;
1023 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001024 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001025 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001026 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001027 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001028 // Immediate offset in range [-4095, 4095].
1029 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1030 if (!CE) return false;
1031 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001032 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001033 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001034 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001035 // If we have an immediate that's not a constant, treat it as a label
1036 // reference needing a fixup. If it is a constant, it's something else
1037 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001038 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001039 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001040 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001041 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001042 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001043 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001044 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001045 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001046 if (!Memory.OffsetImm) return true;
1047 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001048 // The #-0 offset is encoded as INT32_MIN, and we have to check
1049 // for this too.
1050 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001051 }
1052 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001053 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001054 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001055 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001056 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1057 // Immediate offset in range [-255, 255].
1058 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1059 if (!CE) return false;
1060 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001061 // Special case, #-0 is INT32_MIN.
1062 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001063 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001064 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001065 // If we have an immediate that's not a constant, treat it as a label
1066 // reference needing a fixup. If it is a constant, it's something else
1067 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001068 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001069 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001070 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001071 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001072 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001073 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001074 if (!Memory.OffsetImm) return true;
1075 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001076 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001077 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001078 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001079 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001080 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001081 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001082 return false;
1083 return true;
1084 }
1085 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001086 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001087 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1088 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001089 return false;
1090 return true;
1091 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001092 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001093 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001094 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001095 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001096 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001097 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001098 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001099 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001100 return false;
1101 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001102 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001103 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001104 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001105 return false;
1106 return true;
1107 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001108 bool isMemThumbRR() const {
1109 // Thumb reg+reg addressing is simple. Just two registers, a base and
1110 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001111 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001112 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001113 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001114 return isARMLowRegister(Memory.BaseRegNum) &&
1115 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001116 }
1117 bool isMemThumbRIs4() 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 Grosbach3fe94e32011-08-19 17:55:24 +00001120 return false;
1121 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001122 if (!Memory.OffsetImm) return true;
1123 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001124 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1125 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001126 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001127 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001128 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001129 return false;
1130 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001131 if (!Memory.OffsetImm) return true;
1132 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001133 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1134 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001135 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001136 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001137 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001138 return false;
1139 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001140 if (!Memory.OffsetImm) return true;
1141 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001142 return Val >= 0 && Val <= 31;
1143 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001144 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001145 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001146 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001147 return false;
1148 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001149 if (!Memory.OffsetImm) return true;
1150 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001151 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001152 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001153 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001154 // If we have an immediate that's not a constant, treat it as a label
1155 // reference needing a fixup. If it is a constant, it's something else
1156 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001157 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001158 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001159 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001160 return false;
1161 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001162 if (!Memory.OffsetImm) return true;
1163 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001164 // Special case, #-0 is INT32_MIN.
1165 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001166 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001167 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001168 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001169 return false;
1170 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001171 if (!Memory.OffsetImm) return true;
1172 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001173 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1174 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001175 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001176 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +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 Grosbachd3595712011-08-03 23:50:40 +00001180 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001181 if (!Memory.OffsetImm) return true;
1182 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001183 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001184 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001185 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001186 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001187 return false;
1188 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001189 if (!Memory.OffsetImm) return true;
1190 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001191 return Val >= 0 && Val < 256;
1192 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001193 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001194 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001195 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001196 // Base reg of PC isn't allowed for these encodings.
1197 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001198 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001199 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001200 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001201 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001202 }
1203 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001204 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001205 return false;
1206 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001207 if (!Memory.OffsetImm) return true;
1208 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001209 return (Val >= 0 && Val < 4096);
1210 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001211 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001212 // If we have an immediate that's not a constant, treat it as a label
1213 // reference needing a fixup. If it is a constant, it's something else
1214 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001215 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001216 return true;
1217
Chad Rosier41099832012-09-11 23:02:35 +00001218 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001219 return false;
1220 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001221 if (!Memory.OffsetImm) return true;
1222 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001223 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001224 }
1225 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001226 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001227 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1228 if (!CE) return false;
1229 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001230 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001231 }
Jim Grosbach93981412011-10-11 21:55:36 +00001232 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001233 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001234 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1235 if (!CE) return false;
1236 int64_t Val = CE->getValue();
1237 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1238 (Val == INT32_MIN);
1239 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001240
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001241 bool isMSRMask() const { return Kind == k_MSRMask; }
1242 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001243
Jim Grosbach741cd732011-10-17 22:26:03 +00001244 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001245 bool isSingleSpacedVectorList() const {
1246 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1247 }
1248 bool isDoubleSpacedVectorList() const {
1249 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1250 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001251 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001252 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001253 return VectorList.Count == 1;
1254 }
1255
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001256 bool isVecListDPair() const {
1257 if (!isSingleSpacedVectorList()) return false;
1258 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1259 .contains(VectorList.RegNum));
1260 }
1261
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001262 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001263 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001264 return VectorList.Count == 3;
1265 }
1266
Jim Grosbach846bcff2011-10-21 20:35:01 +00001267 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001268 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001269 return VectorList.Count == 4;
1270 }
1271
Jim Grosbache5307f92012-03-05 21:43:40 +00001272 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001273 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001274 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1275 .contains(VectorList.RegNum));
1276 }
1277
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001278 bool isVecListThreeQ() const {
1279 if (!isDoubleSpacedVectorList()) return false;
1280 return VectorList.Count == 3;
1281 }
1282
Jim Grosbach1e946a42012-01-24 00:43:12 +00001283 bool isVecListFourQ() const {
1284 if (!isDoubleSpacedVectorList()) return false;
1285 return VectorList.Count == 4;
1286 }
1287
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001288 bool isSingleSpacedVectorAllLanes() const {
1289 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1290 }
1291 bool isDoubleSpacedVectorAllLanes() const {
1292 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1293 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001294 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001295 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001296 return VectorList.Count == 1;
1297 }
1298
Jim Grosbach13a292c2012-03-06 22:01:44 +00001299 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001300 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001301 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1302 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001303 }
1304
Jim Grosbached428bc2012-03-06 23:10:38 +00001305 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001306 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001307 return VectorList.Count == 2;
1308 }
1309
Jim Grosbachb78403c2012-01-24 23:47:04 +00001310 bool isVecListThreeDAllLanes() const {
1311 if (!isSingleSpacedVectorAllLanes()) return false;
1312 return VectorList.Count == 3;
1313 }
1314
1315 bool isVecListThreeQAllLanes() const {
1316 if (!isDoubleSpacedVectorAllLanes()) return false;
1317 return VectorList.Count == 3;
1318 }
1319
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001320 bool isVecListFourDAllLanes() const {
1321 if (!isSingleSpacedVectorAllLanes()) return false;
1322 return VectorList.Count == 4;
1323 }
1324
1325 bool isVecListFourQAllLanes() const {
1326 if (!isDoubleSpacedVectorAllLanes()) return false;
1327 return VectorList.Count == 4;
1328 }
1329
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001330 bool isSingleSpacedVectorIndexed() const {
1331 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1332 }
1333 bool isDoubleSpacedVectorIndexed() const {
1334 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1335 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001336 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001337 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001338 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1339 }
1340
Jim Grosbachda511042011-12-14 23:35:06 +00001341 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001342 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001343 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1344 }
1345
1346 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001347 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001348 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1349 }
1350
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001351 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001352 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001353 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1354 }
1355
Jim Grosbachda511042011-12-14 23:35:06 +00001356 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001357 if (!isSingleSpacedVectorIndexed()) return false;
1358 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1359 }
1360
1361 bool isVecListTwoQWordIndexed() const {
1362 if (!isDoubleSpacedVectorIndexed()) return false;
1363 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1364 }
1365
1366 bool isVecListTwoQHWordIndexed() const {
1367 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001368 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1369 }
1370
1371 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001372 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001373 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1374 }
1375
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001376 bool isVecListThreeDByteIndexed() const {
1377 if (!isSingleSpacedVectorIndexed()) return false;
1378 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1379 }
1380
1381 bool isVecListThreeDHWordIndexed() const {
1382 if (!isSingleSpacedVectorIndexed()) return false;
1383 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1384 }
1385
1386 bool isVecListThreeQWordIndexed() const {
1387 if (!isDoubleSpacedVectorIndexed()) return false;
1388 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1389 }
1390
1391 bool isVecListThreeQHWordIndexed() const {
1392 if (!isDoubleSpacedVectorIndexed()) return false;
1393 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1394 }
1395
1396 bool isVecListThreeDWordIndexed() const {
1397 if (!isSingleSpacedVectorIndexed()) return false;
1398 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1399 }
1400
Jim Grosbach14952a02012-01-24 18:37:25 +00001401 bool isVecListFourDByteIndexed() const {
1402 if (!isSingleSpacedVectorIndexed()) return false;
1403 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1404 }
1405
1406 bool isVecListFourDHWordIndexed() const {
1407 if (!isSingleSpacedVectorIndexed()) return false;
1408 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1409 }
1410
1411 bool isVecListFourQWordIndexed() const {
1412 if (!isDoubleSpacedVectorIndexed()) return false;
1413 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1414 }
1415
1416 bool isVecListFourQHWordIndexed() const {
1417 if (!isDoubleSpacedVectorIndexed()) return false;
1418 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1419 }
1420
1421 bool isVecListFourDWordIndexed() const {
1422 if (!isSingleSpacedVectorIndexed()) return false;
1423 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1424 }
1425
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001426 bool isVectorIndex8() const {
1427 if (Kind != k_VectorIndex) return false;
1428 return VectorIndex.Val < 8;
1429 }
1430 bool isVectorIndex16() const {
1431 if (Kind != k_VectorIndex) return false;
1432 return VectorIndex.Val < 4;
1433 }
1434 bool isVectorIndex32() const {
1435 if (Kind != k_VectorIndex) return false;
1436 return VectorIndex.Val < 2;
1437 }
1438
Jim Grosbach741cd732011-10-17 22:26:03 +00001439 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001440 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001441 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1442 // Must be a constant.
1443 if (!CE) return false;
1444 int64_t Value = CE->getValue();
1445 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1446 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001447 return Value >= 0 && Value < 256;
1448 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001449
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001450 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001451 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001452 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1453 // Must be a constant.
1454 if (!CE) return false;
1455 int64_t Value = CE->getValue();
1456 // i16 value in the range [0,255] or [0x0100, 0xff00]
1457 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1458 }
1459
Jim Grosbach8211c052011-10-18 00:22:00 +00001460 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001461 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001462 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1463 // Must be a constant.
1464 if (!CE) return false;
1465 int64_t Value = CE->getValue();
1466 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1467 return (Value >= 0 && Value < 256) ||
1468 (Value >= 0x0100 && Value <= 0xff00) ||
1469 (Value >= 0x010000 && Value <= 0xff0000) ||
1470 (Value >= 0x01000000 && Value <= 0xff000000);
1471 }
1472
1473 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001474 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1476 // Must be a constant.
1477 if (!CE) return false;
1478 int64_t Value = CE->getValue();
1479 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1480 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1481 return (Value >= 0 && Value < 256) ||
1482 (Value >= 0x0100 && Value <= 0xff00) ||
1483 (Value >= 0x010000 && Value <= 0xff0000) ||
1484 (Value >= 0x01000000 && Value <= 0xff000000) ||
1485 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1486 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1487 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001488 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001489 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001490 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1491 // Must be a constant.
1492 if (!CE) return false;
1493 int64_t Value = ~CE->getValue();
1494 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1495 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1496 return (Value >= 0 && Value < 256) ||
1497 (Value >= 0x0100 && Value <= 0xff00) ||
1498 (Value >= 0x010000 && Value <= 0xff0000) ||
1499 (Value >= 0x01000000 && Value <= 0xff000000) ||
1500 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1501 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1502 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001503
Jim Grosbache4454e02011-10-18 16:18:11 +00001504 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001505 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001506 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1507 // Must be a constant.
1508 if (!CE) return false;
1509 uint64_t Value = CE->getValue();
1510 // i64 value with each byte being either 0 or 0xff.
1511 for (unsigned i = 0; i < 8; ++i)
1512 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1513 return true;
1514 }
1515
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001516 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001517 // Add as immediates when possible. Null MCExpr = 0.
1518 if (Expr == 0)
1519 Inst.addOperand(MCOperand::CreateImm(0));
1520 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001521 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1522 else
1523 Inst.addOperand(MCOperand::CreateExpr(Expr));
1524 }
1525
Daniel Dunbard8042b72010-08-11 06:36:53 +00001526 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001527 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001528 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001529 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1530 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001531 }
1532
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001533 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1534 assert(N == 1 && "Invalid number of operands!");
1535 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1536 }
1537
Jim Grosbach48399582011-10-12 17:34:41 +00001538 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1539 assert(N == 1 && "Invalid number of operands!");
1540 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1541 }
1542
1543 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1544 assert(N == 1 && "Invalid number of operands!");
1545 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1546 }
1547
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001548 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1549 assert(N == 1 && "Invalid number of operands!");
1550 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1551 }
1552
1553 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1556 }
1557
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001558 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1559 assert(N == 1 && "Invalid number of operands!");
1560 Inst.addOperand(MCOperand::CreateReg(getReg()));
1561 }
1562
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001563 void addRegOperands(MCInst &Inst, unsigned N) const {
1564 assert(N == 1 && "Invalid number of operands!");
1565 Inst.addOperand(MCOperand::CreateReg(getReg()));
1566 }
1567
Jim Grosbachac798e12011-07-25 20:49:51 +00001568 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001569 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001570 assert(isRegShiftedReg() &&
1571 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001572 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1573 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001574 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001575 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001576 }
1577
Jim Grosbachac798e12011-07-25 20:49:51 +00001578 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001579 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001580 assert(isRegShiftedImm() &&
1581 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001582 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001583 // Shift of #32 is encoded as 0 where permitted
1584 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001585 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001586 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001587 }
1588
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001589 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001590 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001591 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1592 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001593 }
1594
Bill Wendling8d2aa032010-11-08 23:49:57 +00001595 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001596 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001597 const SmallVectorImpl<unsigned> &RegList = getRegList();
1598 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001599 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1600 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001601 }
1602
Bill Wendling9898ac92010-11-17 04:32:08 +00001603 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1604 addRegListOperands(Inst, N);
1605 }
1606
1607 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1608 addRegListOperands(Inst, N);
1609 }
1610
Jim Grosbach833b9d32011-07-27 20:15:40 +00001611 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1612 assert(N == 1 && "Invalid number of operands!");
1613 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1614 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1615 }
1616
Jim Grosbach864b6092011-07-28 21:34:26 +00001617 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1618 assert(N == 1 && "Invalid number of operands!");
1619 // Munge the lsb/width into a bitfield mask.
1620 unsigned lsb = Bitfield.LSB;
1621 unsigned width = Bitfield.Width;
1622 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1623 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1624 (32 - (lsb + width)));
1625 Inst.addOperand(MCOperand::CreateImm(Mask));
1626 }
1627
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001628 void addImmOperands(MCInst &Inst, unsigned N) const {
1629 assert(N == 1 && "Invalid number of operands!");
1630 addExpr(Inst, getImm());
1631 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001632
Jim Grosbachea231912011-12-22 22:19:05 +00001633 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1634 assert(N == 1 && "Invalid number of operands!");
1635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1636 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1637 }
1638
1639 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1640 assert(N == 1 && "Invalid number of operands!");
1641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1642 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1643 }
1644
Jim Grosbache7fbce72011-10-03 23:38:36 +00001645 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1648 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1649 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001650 }
1651
Jim Grosbach7db8d692011-09-08 22:07:06 +00001652 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1653 assert(N == 1 && "Invalid number of operands!");
1654 // FIXME: We really want to scale the value here, but the LDRD/STRD
1655 // instruction don't encode operands that way yet.
1656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1657 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1658 }
1659
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001660 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1661 assert(N == 1 && "Invalid number of operands!");
1662 // The immediate is scaled by four in the encoding and is stored
1663 // in the MCInst as such. Lop off the low two bits here.
1664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1665 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1666 }
1667
Jim Grosbach930f2f62012-04-05 20:57:13 +00001668 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1669 assert(N == 1 && "Invalid number of operands!");
1670 // The immediate is scaled by four in the encoding and is stored
1671 // in the MCInst as such. Lop off the low two bits here.
1672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1673 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1674 }
1675
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001676 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1677 assert(N == 1 && "Invalid number of operands!");
1678 // The immediate is scaled by four in the encoding and is stored
1679 // in the MCInst as such. Lop off the low two bits here.
1680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1681 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1682 }
1683
Jim Grosbach475c6db2011-07-25 23:09:14 +00001684 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1685 assert(N == 1 && "Invalid number of operands!");
1686 // The constant encodes as the immediate-1, and we store in the instruction
1687 // the bits as encoded, so subtract off one here.
1688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1689 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1690 }
1691
Jim Grosbach801e0a32011-07-22 23:16:18 +00001692 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1693 assert(N == 1 && "Invalid number of operands!");
1694 // The constant encodes as the immediate-1, and we store in the instruction
1695 // the bits as encoded, so subtract off one here.
1696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1697 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1698 }
1699
Jim Grosbach46dd4132011-08-17 21:51:27 +00001700 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1701 assert(N == 1 && "Invalid number of operands!");
1702 // The constant encodes as the immediate, except for 32, which encodes as
1703 // zero.
1704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1705 unsigned Imm = CE->getValue();
1706 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1707 }
1708
Jim Grosbach27c1e252011-07-21 17:23:04 +00001709 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1710 assert(N == 1 && "Invalid number of operands!");
1711 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1712 // the instruction as well.
1713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1714 int Val = CE->getValue();
1715 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1716 }
1717
Jim Grosbachb009a872011-10-28 22:36:30 +00001718 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1719 assert(N == 1 && "Invalid number of operands!");
1720 // The operand is actually a t2_so_imm, but we have its bitwise
1721 // negation in the assembly source, so twiddle it here.
1722 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1723 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1724 }
1725
Jim Grosbach30506252011-12-08 00:31:07 +00001726 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1727 assert(N == 1 && "Invalid number of operands!");
1728 // The operand is actually a t2_so_imm, but we have its
1729 // negation in the assembly source, so twiddle it here.
1730 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1731 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1732 }
1733
Jim Grosbach930f2f62012-04-05 20:57:13 +00001734 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1735 assert(N == 1 && "Invalid number of operands!");
1736 // The operand is actually an imm0_4095, but we have its
1737 // negation in the assembly source, so twiddle it here.
1738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1739 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1740 }
1741
Mihai Popad36cbaa2013-07-03 09:21:44 +00001742 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1743 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1744 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1745 return;
1746 }
1747
1748 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1749 assert(SR && "Unknown value type!");
1750 Inst.addOperand(MCOperand::CreateExpr(SR));
1751 }
1752
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001753 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1754 assert(N == 1 && "Invalid number of operands!");
1755 if (isImm()) {
1756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1757 if (CE) {
1758 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1759 return;
1760 }
1761
1762 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1763 assert(SR && "Unknown value type!");
1764 Inst.addOperand(MCOperand::CreateExpr(SR));
1765 return;
1766 }
1767
1768 assert(isMem() && "Unknown value type!");
1769 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1770 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1771 }
1772
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001773 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1774 assert(N == 1 && "Invalid number of operands!");
1775 // The operand is actually a so_imm, but we have its bitwise
1776 // negation in the assembly source, so twiddle it here.
1777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1778 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1779 }
1780
Jim Grosbach30506252011-12-08 00:31:07 +00001781 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1782 assert(N == 1 && "Invalid number of operands!");
1783 // The operand is actually a so_imm, but we have its
1784 // negation in the assembly source, so twiddle it here.
1785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1786 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1787 }
1788
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001789 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1790 assert(N == 1 && "Invalid number of operands!");
1791 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1792 }
1793
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001794 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 1 && "Invalid number of operands!");
1796 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1797 }
1798
Jim Grosbachd3595712011-08-03 23:50:40 +00001799 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1800 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001801 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001802 }
1803
Jim Grosbach94298a92012-01-18 22:46:46 +00001804 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1805 assert(N == 1 && "Invalid number of operands!");
1806 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001807 Inst.addOperand(MCOperand::CreateImm(Imm));
1808 }
1809
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001810 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1811 assert(N == 1 && "Invalid number of operands!");
1812 assert(isImm() && "Not an immediate!");
1813
1814 // If we have an immediate that's not a constant, treat it as a label
1815 // reference needing a fixup.
1816 if (!isa<MCConstantExpr>(getImm())) {
1817 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1818 return;
1819 }
1820
1821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1822 int Val = CE->getValue();
1823 Inst.addOperand(MCOperand::CreateImm(Val));
1824 }
1825
Jim Grosbacha95ec992011-10-11 17:29:55 +00001826 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1827 assert(N == 2 && "Invalid number of operands!");
1828 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1829 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1830 }
1831
Jim Grosbachd3595712011-08-03 23:50:40 +00001832 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1833 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001834 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1835 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001836 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1837 // Special case for #-0
1838 if (Val == INT32_MIN) Val = 0;
1839 if (Val < 0) Val = -Val;
1840 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1841 } else {
1842 // For register offset, we encode the shift type and negation flag
1843 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001844 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1845 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001846 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001847 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1848 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001849 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001850 }
1851
Jim Grosbachcd17c122011-08-04 23:01:30 +00001852 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1853 assert(N == 2 && "Invalid number of operands!");
1854 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1855 assert(CE && "non-constant AM2OffsetImm operand!");
1856 int32_t Val = CE->getValue();
1857 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1858 // Special case for #-0
1859 if (Val == INT32_MIN) Val = 0;
1860 if (Val < 0) Val = -Val;
1861 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1862 Inst.addOperand(MCOperand::CreateReg(0));
1863 Inst.addOperand(MCOperand::CreateImm(Val));
1864 }
1865
Jim Grosbach5b96b802011-08-10 20:29:19 +00001866 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1867 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001868 // If we have an immediate that's not a constant, treat it as a label
1869 // reference needing a fixup. If it is a constant, it's something else
1870 // and we reject it.
1871 if (isImm()) {
1872 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1873 Inst.addOperand(MCOperand::CreateReg(0));
1874 Inst.addOperand(MCOperand::CreateImm(0));
1875 return;
1876 }
1877
Jim Grosbach871dff72011-10-11 15:59:20 +00001878 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1879 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001880 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1881 // Special case for #-0
1882 if (Val == INT32_MIN) Val = 0;
1883 if (Val < 0) Val = -Val;
1884 Val = ARM_AM::getAM3Opc(AddSub, Val);
1885 } else {
1886 // For register offset, we encode the shift type and negation flag
1887 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001888 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001889 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001890 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1891 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001892 Inst.addOperand(MCOperand::CreateImm(Val));
1893 }
1894
1895 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1896 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001897 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001898 int32_t Val =
1899 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1900 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1901 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001902 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001903 }
1904
1905 // Constant offset.
1906 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1907 int32_t Val = CE->getValue();
1908 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1909 // Special case for #-0
1910 if (Val == INT32_MIN) Val = 0;
1911 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001912 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001913 Inst.addOperand(MCOperand::CreateReg(0));
1914 Inst.addOperand(MCOperand::CreateImm(Val));
1915 }
1916
Jim Grosbachd3595712011-08-03 23:50:40 +00001917 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1918 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001919 // If we have an immediate that's not a constant, treat it as a label
1920 // reference needing a fixup. If it is a constant, it's something else
1921 // and we reject it.
1922 if (isImm()) {
1923 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1924 Inst.addOperand(MCOperand::CreateImm(0));
1925 return;
1926 }
1927
Jim Grosbachd3595712011-08-03 23:50:40 +00001928 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001929 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001930 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1931 // Special case for #-0
1932 if (Val == INT32_MIN) Val = 0;
1933 if (Val < 0) Val = -Val;
1934 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001935 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001936 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001937 }
1938
Jim Grosbach7db8d692011-09-08 22:07:06 +00001939 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1940 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001941 // If we have an immediate that's not a constant, treat it as a label
1942 // reference needing a fixup. If it is a constant, it's something else
1943 // and we reject it.
1944 if (isImm()) {
1945 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1946 Inst.addOperand(MCOperand::CreateImm(0));
1947 return;
1948 }
1949
Jim Grosbach871dff72011-10-11 15:59:20 +00001950 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1951 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001952 Inst.addOperand(MCOperand::CreateImm(Val));
1953 }
1954
Jim Grosbacha05627e2011-09-09 18:37:27 +00001955 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1956 assert(N == 2 && "Invalid number of operands!");
1957 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001958 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1959 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001960 Inst.addOperand(MCOperand::CreateImm(Val));
1961 }
1962
Jim Grosbachd3595712011-08-03 23:50:40 +00001963 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1964 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001965 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1966 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001967 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001968 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001969
Jim Grosbach2392c532011-09-07 23:39:14 +00001970 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1971 addMemImm8OffsetOperands(Inst, N);
1972 }
1973
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001974 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001975 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001976 }
1977
1978 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1979 assert(N == 2 && "Invalid number of operands!");
1980 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001981 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001982 addExpr(Inst, getImm());
1983 Inst.addOperand(MCOperand::CreateImm(0));
1984 return;
1985 }
1986
1987 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001988 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1989 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001990 Inst.addOperand(MCOperand::CreateImm(Val));
1991 }
1992
Jim Grosbachd3595712011-08-03 23:50:40 +00001993 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1994 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001995 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001996 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001997 addExpr(Inst, getImm());
1998 Inst.addOperand(MCOperand::CreateImm(0));
1999 return;
2000 }
2001
2002 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002003 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2004 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002005 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002006 }
Bill Wendling811c9362010-11-30 07:44:32 +00002007
Jim Grosbach05541f42011-09-19 22:21:13 +00002008 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002010 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2011 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002012 }
2013
2014 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2015 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002016 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2017 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002018 }
2019
Jim Grosbachd3595712011-08-03 23:50:40 +00002020 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2021 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002022 unsigned Val =
2023 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2024 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002025 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2026 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002027 Inst.addOperand(MCOperand::CreateImm(Val));
2028 }
2029
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002030 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2031 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002032 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2033 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2034 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002035 }
2036
Jim Grosbachd3595712011-08-03 23:50:40 +00002037 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2038 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002039 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2040 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002041 }
2042
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002043 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2044 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002045 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2046 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002047 Inst.addOperand(MCOperand::CreateImm(Val));
2048 }
2049
Jim Grosbach26d35872011-08-19 18:55:51 +00002050 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2051 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002052 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2053 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002054 Inst.addOperand(MCOperand::CreateImm(Val));
2055 }
2056
Jim Grosbacha32c7532011-08-19 18:49:59 +00002057 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2058 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002059 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2060 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002061 Inst.addOperand(MCOperand::CreateImm(Val));
2062 }
2063
Jim Grosbach23983d62011-08-19 18:13:48 +00002064 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2065 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002066 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2067 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002068 Inst.addOperand(MCOperand::CreateImm(Val));
2069 }
2070
Jim Grosbachd3595712011-08-03 23:50:40 +00002071 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2072 assert(N == 1 && "Invalid number of operands!");
2073 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2074 assert(CE && "non-constant post-idx-imm8 operand!");
2075 int Imm = CE->getValue();
2076 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002077 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002078 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2079 Inst.addOperand(MCOperand::CreateImm(Imm));
2080 }
2081
Jim Grosbach93981412011-10-11 21:55:36 +00002082 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2083 assert(N == 1 && "Invalid number of operands!");
2084 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2085 assert(CE && "non-constant post-idx-imm8s4 operand!");
2086 int Imm = CE->getValue();
2087 bool isAdd = Imm >= 0;
2088 if (Imm == INT32_MIN) Imm = 0;
2089 // Immediate is scaled by 4.
2090 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2091 Inst.addOperand(MCOperand::CreateImm(Imm));
2092 }
2093
Jim Grosbachd3595712011-08-03 23:50:40 +00002094 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2095 assert(N == 2 && "Invalid number of operands!");
2096 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002097 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2098 }
2099
2100 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2101 assert(N == 2 && "Invalid number of operands!");
2102 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2103 // The sign, shift type, and shift amount are encoded in a single operand
2104 // using the AM2 encoding helpers.
2105 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2106 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2107 PostIdxReg.ShiftTy);
2108 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002109 }
2110
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002111 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 1 && "Invalid number of operands!");
2113 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2114 }
2115
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002116 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2117 assert(N == 1 && "Invalid number of operands!");
2118 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2119 }
2120
Jim Grosbach182b6a02011-11-29 23:51:09 +00002121 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002122 assert(N == 1 && "Invalid number of operands!");
2123 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2124 }
2125
Jim Grosbach04945c42011-12-02 00:35:16 +00002126 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2127 assert(N == 2 && "Invalid number of operands!");
2128 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2129 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2130 }
2131
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002132 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2133 assert(N == 1 && "Invalid number of operands!");
2134 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2135 }
2136
2137 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2138 assert(N == 1 && "Invalid number of operands!");
2139 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2140 }
2141
2142 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2143 assert(N == 1 && "Invalid number of operands!");
2144 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2145 }
2146
Jim Grosbach741cd732011-10-17 22:26:03 +00002147 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2148 assert(N == 1 && "Invalid number of operands!");
2149 // The immediate encodes the type of constant as well as the value.
2150 // Mask in that this is an i8 splat.
2151 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2152 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2153 }
2154
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002155 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2156 assert(N == 1 && "Invalid number of operands!");
2157 // The immediate encodes the type of constant as well as the value.
2158 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2159 unsigned Value = CE->getValue();
2160 if (Value >= 256)
2161 Value = (Value >> 8) | 0xa00;
2162 else
2163 Value |= 0x800;
2164 Inst.addOperand(MCOperand::CreateImm(Value));
2165 }
2166
Jim Grosbach8211c052011-10-18 00:22:00 +00002167 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2168 assert(N == 1 && "Invalid number of operands!");
2169 // The immediate encodes the type of constant as well as the value.
2170 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2171 unsigned Value = CE->getValue();
2172 if (Value >= 256 && Value <= 0xff00)
2173 Value = (Value >> 8) | 0x200;
2174 else if (Value > 0xffff && Value <= 0xff0000)
2175 Value = (Value >> 16) | 0x400;
2176 else if (Value > 0xffffff)
2177 Value = (Value >> 24) | 0x600;
2178 Inst.addOperand(MCOperand::CreateImm(Value));
2179 }
2180
2181 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2182 assert(N == 1 && "Invalid number of operands!");
2183 // The immediate encodes the type of constant as well as the value.
2184 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2185 unsigned Value = CE->getValue();
2186 if (Value >= 256 && Value <= 0xffff)
2187 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2188 else if (Value > 0xffff && Value <= 0xffffff)
2189 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2190 else if (Value > 0xffffff)
2191 Value = (Value >> 24) | 0x600;
2192 Inst.addOperand(MCOperand::CreateImm(Value));
2193 }
2194
Jim Grosbach045b6c72011-12-19 23:51:07 +00002195 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2196 assert(N == 1 && "Invalid number of operands!");
2197 // The immediate encodes the type of constant as well as the value.
2198 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2199 unsigned Value = ~CE->getValue();
2200 if (Value >= 256 && Value <= 0xffff)
2201 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2202 else if (Value > 0xffff && Value <= 0xffffff)
2203 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2204 else if (Value > 0xffffff)
2205 Value = (Value >> 24) | 0x600;
2206 Inst.addOperand(MCOperand::CreateImm(Value));
2207 }
2208
Jim Grosbache4454e02011-10-18 16:18:11 +00002209 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2210 assert(N == 1 && "Invalid number of operands!");
2211 // The immediate encodes the type of constant as well as the value.
2212 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2213 uint64_t Value = CE->getValue();
2214 unsigned Imm = 0;
2215 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2216 Imm |= (Value & 1) << i;
2217 }
2218 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2219 }
2220
Jim Grosbach602aa902011-07-13 15:34:57 +00002221 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002222
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002223 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002224 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002225 Op->ITMask.Mask = Mask;
2226 Op->StartLoc = S;
2227 Op->EndLoc = S;
2228 return Op;
2229 }
2230
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002231 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002232 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002233 Op->CC.Val = CC;
2234 Op->StartLoc = S;
2235 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002236 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002237 }
2238
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002239 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002240 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002241 Op->Cop.Val = CopVal;
2242 Op->StartLoc = S;
2243 Op->EndLoc = S;
2244 return Op;
2245 }
2246
2247 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002248 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002249 Op->Cop.Val = CopVal;
2250 Op->StartLoc = S;
2251 Op->EndLoc = S;
2252 return Op;
2253 }
2254
Jim Grosbach48399582011-10-12 17:34:41 +00002255 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2256 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2257 Op->Cop.Val = Val;
2258 Op->StartLoc = S;
2259 Op->EndLoc = E;
2260 return Op;
2261 }
2262
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002263 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002264 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002265 Op->Reg.RegNum = RegNum;
2266 Op->StartLoc = S;
2267 Op->EndLoc = S;
2268 return Op;
2269 }
2270
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002271 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002272 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002273 Op->Tok.Data = Str.data();
2274 Op->Tok.Length = Str.size();
2275 Op->StartLoc = S;
2276 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002277 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002278 }
2279
Bill Wendling2063b842010-11-18 23:43:05 +00002280 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002281 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002282 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002283 Op->StartLoc = S;
2284 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002285 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002286 }
2287
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002288 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2289 unsigned SrcReg,
2290 unsigned ShiftReg,
2291 unsigned ShiftImm,
2292 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002293 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002294 Op->RegShiftedReg.ShiftTy = ShTy;
2295 Op->RegShiftedReg.SrcReg = SrcReg;
2296 Op->RegShiftedReg.ShiftReg = ShiftReg;
2297 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002298 Op->StartLoc = S;
2299 Op->EndLoc = E;
2300 return Op;
2301 }
2302
Owen Andersonb595ed02011-07-21 18:54:16 +00002303 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2304 unsigned SrcReg,
2305 unsigned ShiftImm,
2306 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002307 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002308 Op->RegShiftedImm.ShiftTy = ShTy;
2309 Op->RegShiftedImm.SrcReg = SrcReg;
2310 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002311 Op->StartLoc = S;
2312 Op->EndLoc = E;
2313 return Op;
2314 }
2315
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002316 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002317 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002318 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002319 Op->ShifterImm.isASR = isASR;
2320 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002321 Op->StartLoc = S;
2322 Op->EndLoc = E;
2323 return Op;
2324 }
2325
Jim Grosbach833b9d32011-07-27 20:15:40 +00002326 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002327 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002328 Op->RotImm.Imm = Imm;
2329 Op->StartLoc = S;
2330 Op->EndLoc = E;
2331 return Op;
2332 }
2333
Jim Grosbach864b6092011-07-28 21:34:26 +00002334 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2335 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002336 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002337 Op->Bitfield.LSB = LSB;
2338 Op->Bitfield.Width = Width;
2339 Op->StartLoc = S;
2340 Op->EndLoc = E;
2341 return Op;
2342 }
2343
Bill Wendling2cae3272010-11-09 22:44:22 +00002344 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002345 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002346 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002347 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002348 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002349
Chad Rosierfa705ee2013-07-01 20:49:23 +00002350 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002351 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002352 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002353 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002354 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002355
Chad Rosierfa705ee2013-07-01 20:49:23 +00002356 // Sort based on the register encoding values.
2357 array_pod_sort(Regs.begin(), Regs.end());
2358
Bill Wendling9898ac92010-11-17 04:32:08 +00002359 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002360 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002361 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002362 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002363 Op->StartLoc = StartLoc;
2364 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002365 return Op;
2366 }
2367
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002368 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002369 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002370 ARMOperand *Op = new ARMOperand(k_VectorList);
2371 Op->VectorList.RegNum = RegNum;
2372 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002373 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002374 Op->StartLoc = S;
2375 Op->EndLoc = E;
2376 return Op;
2377 }
2378
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002379 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002380 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002381 SMLoc S, SMLoc E) {
2382 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2383 Op->VectorList.RegNum = RegNum;
2384 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002385 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002386 Op->StartLoc = S;
2387 Op->EndLoc = E;
2388 return Op;
2389 }
2390
Jim Grosbach04945c42011-12-02 00:35:16 +00002391 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002392 unsigned Index,
2393 bool isDoubleSpaced,
2394 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002395 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2396 Op->VectorList.RegNum = RegNum;
2397 Op->VectorList.Count = Count;
2398 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002399 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002400 Op->StartLoc = S;
2401 Op->EndLoc = E;
2402 return Op;
2403 }
2404
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002405 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2406 MCContext &Ctx) {
2407 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2408 Op->VectorIndex.Val = Idx;
2409 Op->StartLoc = S;
2410 Op->EndLoc = E;
2411 return Op;
2412 }
2413
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002414 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002415 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002416 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002417 Op->StartLoc = S;
2418 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002419 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002420 }
2421
Jim Grosbachd3595712011-08-03 23:50:40 +00002422 static ARMOperand *CreateMem(unsigned BaseRegNum,
2423 const MCConstantExpr *OffsetImm,
2424 unsigned OffsetRegNum,
2425 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002426 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002427 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002428 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002429 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002430 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002431 Op->Memory.BaseRegNum = BaseRegNum;
2432 Op->Memory.OffsetImm = OffsetImm;
2433 Op->Memory.OffsetRegNum = OffsetRegNum;
2434 Op->Memory.ShiftType = ShiftType;
2435 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002436 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002437 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002438 Op->StartLoc = S;
2439 Op->EndLoc = E;
2440 return Op;
2441 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002442
Jim Grosbachc320c852011-08-05 21:28:30 +00002443 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2444 ARM_AM::ShiftOpc ShiftTy,
2445 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002446 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002447 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002448 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002449 Op->PostIdxReg.isAdd = isAdd;
2450 Op->PostIdxReg.ShiftTy = ShiftTy;
2451 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002452 Op->StartLoc = S;
2453 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002454 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002455 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002456
2457 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002458 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002459 Op->MBOpt.Val = Opt;
2460 Op->StartLoc = S;
2461 Op->EndLoc = S;
2462 return Op;
2463 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002464
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002465 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2466 SMLoc S) {
2467 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2468 Op->ISBOpt.Val = Opt;
2469 Op->StartLoc = S;
2470 Op->EndLoc = S;
2471 return Op;
2472 }
2473
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002474 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002475 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002476 Op->IFlags.Val = IFlags;
2477 Op->StartLoc = S;
2478 Op->EndLoc = S;
2479 return Op;
2480 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002481
2482 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002483 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002484 Op->MMask.Val = MMask;
2485 Op->StartLoc = S;
2486 Op->EndLoc = S;
2487 return Op;
2488 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002489};
2490
2491} // end anonymous namespace.
2492
Jim Grosbach602aa902011-07-13 15:34:57 +00002493void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002494 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002495 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002496 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002497 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002498 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002499 OS << "<ccout " << getReg() << ">";
2500 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002501 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002502 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002503 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2504 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2505 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002506 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2507 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2508 break;
2509 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002510 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002511 OS << "<coprocessor number: " << getCoproc() << ">";
2512 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002513 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002514 OS << "<coprocessor register: " << getCoproc() << ">";
2515 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002516 case k_CoprocOption:
2517 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2518 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002519 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002520 OS << "<mask: " << getMSRMask() << ">";
2521 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002522 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002523 getImm()->print(OS);
2524 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002525 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002526 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002527 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002528 case k_InstSyncBarrierOpt:
2529 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2530 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002531 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002532 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002533 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002534 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002535 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002536 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002537 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2538 << PostIdxReg.RegNum;
2539 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2540 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2541 << PostIdxReg.ShiftImm;
2542 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002543 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002544 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002545 OS << "<ARM_PROC::";
2546 unsigned IFlags = getProcIFlags();
2547 for (int i=2; i >= 0; --i)
2548 if (IFlags & (1 << i))
2549 OS << ARM_PROC::IFlagsToString(1 << i);
2550 OS << ">";
2551 break;
2552 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002553 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002554 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002555 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002556 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002557 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2558 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002559 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002560 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002561 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002562 << RegShiftedReg.SrcReg << " "
2563 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2564 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002565 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002566 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002567 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002568 << RegShiftedImm.SrcReg << " "
2569 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2570 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002571 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002572 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002573 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2574 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002575 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002576 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2577 << ", width: " << Bitfield.Width << ">";
2578 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002579 case k_RegisterList:
2580 case k_DPRRegisterList:
2581 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002582 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002583
Bill Wendlingbed94652010-11-09 23:28:44 +00002584 const SmallVectorImpl<unsigned> &RegList = getRegList();
2585 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002586 I = RegList.begin(), E = RegList.end(); I != E; ) {
2587 OS << *I;
2588 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002589 }
2590
2591 OS << ">";
2592 break;
2593 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002594 case k_VectorList:
2595 OS << "<vector_list " << VectorList.Count << " * "
2596 << VectorList.RegNum << ">";
2597 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002598 case k_VectorListAllLanes:
2599 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2600 << VectorList.RegNum << ">";
2601 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002602 case k_VectorListIndexed:
2603 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2604 << VectorList.Count << " * " << VectorList.RegNum << ">";
2605 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002606 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002607 OS << "'" << getToken() << "'";
2608 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002609 case k_VectorIndex:
2610 OS << "<vectorindex " << getVectorIndex() << ">";
2611 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002612 }
2613}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002614
2615/// @name Auto-generated Match Functions
2616/// {
2617
2618static unsigned MatchRegisterName(StringRef Name);
2619
2620/// }
2621
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002622bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2623 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002624 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002625 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002626 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002627
2628 return (RegNo == (unsigned)-1);
2629}
2630
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002631/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002632/// and if it is a register name the token is eaten and the register number is
2633/// returned. Otherwise return -1.
2634///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002635int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002636 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002637 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002638
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002639 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002640 unsigned RegNum = MatchRegisterName(lowerCase);
2641 if (!RegNum) {
2642 RegNum = StringSwitch<unsigned>(lowerCase)
2643 .Case("r13", ARM::SP)
2644 .Case("r14", ARM::LR)
2645 .Case("r15", ARM::PC)
2646 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002647 // Additional register name aliases for 'gas' compatibility.
2648 .Case("a1", ARM::R0)
2649 .Case("a2", ARM::R1)
2650 .Case("a3", ARM::R2)
2651 .Case("a4", ARM::R3)
2652 .Case("v1", ARM::R4)
2653 .Case("v2", ARM::R5)
2654 .Case("v3", ARM::R6)
2655 .Case("v4", ARM::R7)
2656 .Case("v5", ARM::R8)
2657 .Case("v6", ARM::R9)
2658 .Case("v7", ARM::R10)
2659 .Case("v8", ARM::R11)
2660 .Case("sb", ARM::R9)
2661 .Case("sl", ARM::R10)
2662 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002663 .Default(0);
2664 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002665 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002666 // Check for aliases registered via .req. Canonicalize to lower case.
2667 // That's more consistent since register names are case insensitive, and
2668 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2669 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002670 // If no match, return failure.
2671 if (Entry == RegisterReqs.end())
2672 return -1;
2673 Parser.Lex(); // Eat identifier token.
2674 return Entry->getValue();
2675 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002676
Chris Lattner44e5981c2010-10-30 04:09:10 +00002677 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002678
Chris Lattner44e5981c2010-10-30 04:09:10 +00002679 return RegNum;
2680}
Jim Grosbach99710a82010-11-01 16:44:21 +00002681
Jim Grosbachbb24c592011-07-13 18:49:30 +00002682// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2683// If a recoverable error occurs, return 1. If an irrecoverable error
2684// occurs, return -1. An irrecoverable error is one where tokens have been
2685// consumed in the process of trying to parse the shifter (i.e., when it is
2686// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002687int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002688 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2689 SMLoc S = Parser.getTok().getLoc();
2690 const AsmToken &Tok = Parser.getTok();
2691 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2692
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002693 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002694 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002695 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002696 .Case("lsl", ARM_AM::lsl)
2697 .Case("lsr", ARM_AM::lsr)
2698 .Case("asr", ARM_AM::asr)
2699 .Case("ror", ARM_AM::ror)
2700 .Case("rrx", ARM_AM::rrx)
2701 .Default(ARM_AM::no_shift);
2702
2703 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002704 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002705
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002706 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002707
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002708 // The source register for the shift has already been added to the
2709 // operand list, so we need to pop it off and combine it into the shifted
2710 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002711 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002712 if (!PrevOp->isReg())
2713 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2714 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002715
2716 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002717 int64_t Imm = 0;
2718 int ShiftReg = 0;
2719 if (ShiftTy == ARM_AM::rrx) {
2720 // RRX Doesn't have an explicit shift amount. The encoder expects
2721 // the shift register to be the same as the source register. Seems odd,
2722 // but OK.
2723 ShiftReg = SrcReg;
2724 } else {
2725 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002726 if (Parser.getTok().is(AsmToken::Hash) ||
2727 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002728 Parser.Lex(); // Eat hash.
2729 SMLoc ImmLoc = Parser.getTok().getLoc();
2730 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002731 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002732 Error(ImmLoc, "invalid immediate shift value");
2733 return -1;
2734 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002735 // The expression must be evaluatable as an immediate.
2736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002737 if (!CE) {
2738 Error(ImmLoc, "invalid immediate shift value");
2739 return -1;
2740 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002741 // Range check the immediate.
2742 // lsl, ror: 0 <= imm <= 31
2743 // lsr, asr: 0 <= imm <= 32
2744 Imm = CE->getValue();
2745 if (Imm < 0 ||
2746 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2747 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002748 Error(ImmLoc, "immediate shift value out of range");
2749 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002750 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002751 // shift by zero is a nop. Always send it through as lsl.
2752 // ('as' compatibility)
2753 if (Imm == 0)
2754 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002755 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002756 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002757 EndLoc = Parser.getTok().getEndLoc();
2758 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002759 if (ShiftReg == -1) {
2760 Error (L, "expected immediate or register in shift operand");
2761 return -1;
2762 }
2763 } else {
2764 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002765 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002766 return -1;
2767 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002768 }
2769
Owen Andersonb595ed02011-07-21 18:54:16 +00002770 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2771 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002772 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002773 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002774 else
2775 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002776 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002777
Jim Grosbachbb24c592011-07-13 18:49:30 +00002778 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002779}
2780
2781
Bill Wendling2063b842010-11-18 23:43:05 +00002782/// Try to parse a register name. The token must be an Identifier when called.
2783/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2784/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002785///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002786/// TODO this is likely to change to allow different register types and or to
2787/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002788bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002789tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002790 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002791 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002792 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002793 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002794
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002795 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2796 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002797
Chris Lattner44e5981c2010-10-30 04:09:10 +00002798 const AsmToken &ExclaimTok = Parser.getTok();
2799 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002800 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2801 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002802 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002803 return false;
2804 }
2805
2806 // Also check for an index operand. This is only legal for vector registers,
2807 // but that'll get caught OK in operand matching, so we don't need to
2808 // explicitly filter everything else out here.
2809 if (Parser.getTok().is(AsmToken::LBrac)) {
2810 SMLoc SIdx = Parser.getTok().getLoc();
2811 Parser.Lex(); // Eat left bracket token.
2812
2813 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002814 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002815 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002816 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002817 if (!MCE)
2818 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002819
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002820 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002821 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002822
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002823 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002824 Parser.Lex(); // Eat right bracket token.
2825
2826 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2827 SIdx, E,
2828 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002829 }
2830
Bill Wendling2063b842010-11-18 23:43:05 +00002831 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002832}
2833
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002834/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2835/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2836/// "c5", ...
2837static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002838 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2839 // but efficient.
2840 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002841 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002842 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002843 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002844 return -1;
2845 switch (Name[1]) {
2846 default: return -1;
2847 case '0': return 0;
2848 case '1': return 1;
2849 case '2': return 2;
2850 case '3': return 3;
2851 case '4': return 4;
2852 case '5': return 5;
2853 case '6': return 6;
2854 case '7': return 7;
2855 case '8': return 8;
2856 case '9': return 9;
2857 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002858 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002859 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002860 return -1;
2861 switch (Name[2]) {
2862 default: return -1;
2863 case '0': return 10;
2864 case '1': return 11;
2865 case '2': return 12;
2866 case '3': return 13;
2867 case '4': return 14;
2868 case '5': return 15;
2869 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002870 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002871}
2872
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002873/// parseITCondCode - Try to parse a condition code for an IT instruction.
2874ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2875parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2876 SMLoc S = Parser.getTok().getLoc();
2877 const AsmToken &Tok = Parser.getTok();
2878 if (!Tok.is(AsmToken::Identifier))
2879 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002880 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002881 .Case("eq", ARMCC::EQ)
2882 .Case("ne", ARMCC::NE)
2883 .Case("hs", ARMCC::HS)
2884 .Case("cs", ARMCC::HS)
2885 .Case("lo", ARMCC::LO)
2886 .Case("cc", ARMCC::LO)
2887 .Case("mi", ARMCC::MI)
2888 .Case("pl", ARMCC::PL)
2889 .Case("vs", ARMCC::VS)
2890 .Case("vc", ARMCC::VC)
2891 .Case("hi", ARMCC::HI)
2892 .Case("ls", ARMCC::LS)
2893 .Case("ge", ARMCC::GE)
2894 .Case("lt", ARMCC::LT)
2895 .Case("gt", ARMCC::GT)
2896 .Case("le", ARMCC::LE)
2897 .Case("al", ARMCC::AL)
2898 .Default(~0U);
2899 if (CC == ~0U)
2900 return MatchOperand_NoMatch;
2901 Parser.Lex(); // Eat the token.
2902
2903 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2904
2905 return MatchOperand_Success;
2906}
2907
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002908/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002909/// token must be an Identifier when called, and if it is a coprocessor
2910/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002911ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002912parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002913 SMLoc S = Parser.getTok().getLoc();
2914 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002915 if (Tok.isNot(AsmToken::Identifier))
2916 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002917
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002918 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002919 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002920 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002921
2922 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002923 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002924 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002925}
2926
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002927/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002928/// token must be an Identifier when called, and if it is a coprocessor
2929/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002930ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002931parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002932 SMLoc S = Parser.getTok().getLoc();
2933 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002934 if (Tok.isNot(AsmToken::Identifier))
2935 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002936
2937 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2938 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002939 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002940
2941 Parser.Lex(); // Eat identifier token.
2942 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002943 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002944}
2945
Jim Grosbach48399582011-10-12 17:34:41 +00002946/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2947/// coproc_option : '{' imm0_255 '}'
2948ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2949parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2950 SMLoc S = Parser.getTok().getLoc();
2951
2952 // If this isn't a '{', this isn't a coprocessor immediate operand.
2953 if (Parser.getTok().isNot(AsmToken::LCurly))
2954 return MatchOperand_NoMatch;
2955 Parser.Lex(); // Eat the '{'
2956
2957 const MCExpr *Expr;
2958 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002959 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002960 Error(Loc, "illegal expression");
2961 return MatchOperand_ParseFail;
2962 }
2963 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2964 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2965 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2966 return MatchOperand_ParseFail;
2967 }
2968 int Val = CE->getValue();
2969
2970 // Check for and consume the closing '}'
2971 if (Parser.getTok().isNot(AsmToken::RCurly))
2972 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002973 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002974 Parser.Lex(); // Eat the '}'
2975
2976 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2977 return MatchOperand_Success;
2978}
2979
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002980// For register list parsing, we need to map from raw GPR register numbering
2981// to the enumeration values. The enumeration values aren't sorted by
2982// register number due to our using "sp", "lr" and "pc" as canonical names.
2983static unsigned getNextRegister(unsigned Reg) {
2984 // If this is a GPR, we need to do it manually, otherwise we can rely
2985 // on the sort ordering of the enumeration since the other reg-classes
2986 // are sane.
2987 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2988 return Reg + 1;
2989 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002990 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002991 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2992 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2993 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2994 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2995 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2996 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2997 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2998 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2999 }
3000}
3001
Jim Grosbach85a23432011-11-11 21:27:40 +00003002// Return the low-subreg of a given Q register.
3003static unsigned getDRegFromQReg(unsigned QReg) {
3004 switch (QReg) {
3005 default: llvm_unreachable("expected a Q register!");
3006 case ARM::Q0: return ARM::D0;
3007 case ARM::Q1: return ARM::D2;
3008 case ARM::Q2: return ARM::D4;
3009 case ARM::Q3: return ARM::D6;
3010 case ARM::Q4: return ARM::D8;
3011 case ARM::Q5: return ARM::D10;
3012 case ARM::Q6: return ARM::D12;
3013 case ARM::Q7: return ARM::D14;
3014 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003015 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003016 case ARM::Q10: return ARM::D20;
3017 case ARM::Q11: return ARM::D22;
3018 case ARM::Q12: return ARM::D24;
3019 case ARM::Q13: return ARM::D26;
3020 case ARM::Q14: return ARM::D28;
3021 case ARM::Q15: return ARM::D30;
3022 }
3023}
3024
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003025/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003026bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003027parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003028 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003029 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003030 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003031 Parser.Lex(); // Eat '{' token.
3032 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003033
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003034 // Check the first register in the list to see what register class
3035 // this is a list of.
3036 int Reg = tryParseRegister();
3037 if (Reg == -1)
3038 return Error(RegLoc, "register expected");
3039
Jim Grosbach85a23432011-11-11 21:27:40 +00003040 // The reglist instructions have at most 16 registers, so reserve
3041 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003042 int EReg = 0;
3043 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003044
3045 // Allow Q regs and just interpret them as the two D sub-registers.
3046 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3047 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003048 EReg = MRI->getEncodingValue(Reg);
3049 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003050 ++Reg;
3051 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003052 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003053 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3054 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3055 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3056 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3057 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3058 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3059 else
3060 return Error(RegLoc, "invalid register in register list");
3061
Jim Grosbach85a23432011-11-11 21:27:40 +00003062 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003063 EReg = MRI->getEncodingValue(Reg);
3064 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003065
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003066 // This starts immediately after the first register token in the list,
3067 // so we can see either a comma or a minus (range separator) as a legal
3068 // next token.
3069 while (Parser.getTok().is(AsmToken::Comma) ||
3070 Parser.getTok().is(AsmToken::Minus)) {
3071 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003072 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003073 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003074 int EndReg = tryParseRegister();
3075 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003076 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003077 // Allow Q regs and just interpret them as the two D sub-registers.
3078 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3079 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003080 // If the register is the same as the start reg, there's nothing
3081 // more to do.
3082 if (Reg == EndReg)
3083 continue;
3084 // The register must be in the same register class as the first.
3085 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003086 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003087 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003088 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003089 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003090
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003091 // Add all the registers in the range to the register list.
3092 while (Reg != EndReg) {
3093 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003094 EReg = MRI->getEncodingValue(Reg);
3095 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003096 }
3097 continue;
3098 }
3099 Parser.Lex(); // Eat the comma.
3100 RegLoc = Parser.getTok().getLoc();
3101 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003102 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003103 Reg = tryParseRegister();
3104 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003105 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003106 // Allow Q regs and just interpret them as the two D sub-registers.
3107 bool isQReg = false;
3108 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3109 Reg = getDRegFromQReg(Reg);
3110 isQReg = true;
3111 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003112 // The register must be in the same register class as the first.
3113 if (!RC->contains(Reg))
3114 return Error(RegLoc, "invalid register in register list");
3115 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003116 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003117 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3118 Warning(RegLoc, "register list not in ascending order");
3119 else
3120 return Error(RegLoc, "register list not in ascending order");
3121 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003122 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003123 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3124 ") in register list");
3125 continue;
3126 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003127 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003128 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3129 Reg != OldReg + 1)
3130 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003131 EReg = MRI->getEncodingValue(Reg);
3132 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3133 if (isQReg) {
3134 EReg = MRI->getEncodingValue(++Reg);
3135 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3136 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003137 }
3138
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003139 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003140 return Error(Parser.getTok().getLoc(), "'}' expected");
3141 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003142 Parser.Lex(); // Eat '}' token.
3143
Jim Grosbach18bf3632011-12-13 21:48:29 +00003144 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003145 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003146
3147 // The ARM system instruction variants for LDM/STM have a '^' token here.
3148 if (Parser.getTok().is(AsmToken::Caret)) {
3149 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3150 Parser.Lex(); // Eat '^' token.
3151 }
3152
Bill Wendling2063b842010-11-18 23:43:05 +00003153 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003154}
3155
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003156// Helper function to parse the lane index for vector lists.
3157ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003158parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003159 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003160 if (Parser.getTok().is(AsmToken::LBrac)) {
3161 Parser.Lex(); // Eat the '['.
3162 if (Parser.getTok().is(AsmToken::RBrac)) {
3163 // "Dn[]" is the 'all lanes' syntax.
3164 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003165 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003166 Parser.Lex(); // Eat the ']'.
3167 return MatchOperand_Success;
3168 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003169
3170 // There's an optional '#' token here. Normally there wouldn't be, but
3171 // inline assemble puts one in, and it's friendly to accept that.
3172 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003173 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003174
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003175 const MCExpr *LaneIndex;
3176 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003177 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003178 Error(Loc, "illegal expression");
3179 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003180 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003181 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3182 if (!CE) {
3183 Error(Loc, "lane index must be empty or an integer");
3184 return MatchOperand_ParseFail;
3185 }
3186 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3187 Error(Parser.getTok().getLoc(), "']' expected");
3188 return MatchOperand_ParseFail;
3189 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003190 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003191 Parser.Lex(); // Eat the ']'.
3192 int64_t Val = CE->getValue();
3193
3194 // FIXME: Make this range check context sensitive for .8, .16, .32.
3195 if (Val < 0 || Val > 7) {
3196 Error(Parser.getTok().getLoc(), "lane index out of range");
3197 return MatchOperand_ParseFail;
3198 }
3199 Index = Val;
3200 LaneKind = IndexedLane;
3201 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003202 }
3203 LaneKind = NoLanes;
3204 return MatchOperand_Success;
3205}
3206
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003207// parse a vector register list
3208ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3209parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003210 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003211 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003212 SMLoc S = Parser.getTok().getLoc();
3213 // As an extension (to match gas), support a plain D register or Q register
3214 // (without encosing curly braces) as a single or double entry list,
3215 // respectively.
3216 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003217 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003218 int Reg = tryParseRegister();
3219 if (Reg == -1)
3220 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003221 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003222 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003223 if (Res != MatchOperand_Success)
3224 return Res;
3225 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003226 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003227 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003228 break;
3229 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003230 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3231 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003232 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003233 case IndexedLane:
3234 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003235 LaneIndex,
3236 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003237 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003238 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003239 return MatchOperand_Success;
3240 }
3241 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3242 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003243 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003244 if (Res != MatchOperand_Success)
3245 return Res;
3246 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003247 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003248 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003249 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003250 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003251 break;
3252 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003253 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3254 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003255 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3256 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003257 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003258 case IndexedLane:
3259 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003260 LaneIndex,
3261 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003262 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003263 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003264 return MatchOperand_Success;
3265 }
3266 Error(S, "vector register expected");
3267 return MatchOperand_ParseFail;
3268 }
3269
3270 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003271 return MatchOperand_NoMatch;
3272
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003273 Parser.Lex(); // Eat '{' token.
3274 SMLoc RegLoc = Parser.getTok().getLoc();
3275
3276 int Reg = tryParseRegister();
3277 if (Reg == -1) {
3278 Error(RegLoc, "register expected");
3279 return MatchOperand_ParseFail;
3280 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003281 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003282 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003283 unsigned FirstReg = Reg;
3284 // The list is of D registers, but we also allow Q regs and just interpret
3285 // them as the two D sub-registers.
3286 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3287 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003288 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3289 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003290 ++Reg;
3291 ++Count;
3292 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003293
3294 SMLoc E;
3295 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003296 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003297
Jim Grosbache891fe82011-11-15 23:19:15 +00003298 while (Parser.getTok().is(AsmToken::Comma) ||
3299 Parser.getTok().is(AsmToken::Minus)) {
3300 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003301 if (!Spacing)
3302 Spacing = 1; // Register range implies a single spaced list.
3303 else if (Spacing == 2) {
3304 Error(Parser.getTok().getLoc(),
3305 "sequential registers in double spaced list");
3306 return MatchOperand_ParseFail;
3307 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003308 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003309 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003310 int EndReg = tryParseRegister();
3311 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003312 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003313 return MatchOperand_ParseFail;
3314 }
3315 // Allow Q regs and just interpret them as the two D sub-registers.
3316 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3317 EndReg = getDRegFromQReg(EndReg) + 1;
3318 // If the register is the same as the start reg, there's nothing
3319 // more to do.
3320 if (Reg == EndReg)
3321 continue;
3322 // The register must be in the same register class as the first.
3323 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003324 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003325 return MatchOperand_ParseFail;
3326 }
3327 // Ranges must go from low to high.
3328 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003329 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003330 return MatchOperand_ParseFail;
3331 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003332 // Parse the lane specifier if present.
3333 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003334 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003335 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3336 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003337 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003338 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003339 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003340 return MatchOperand_ParseFail;
3341 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003342
3343 // Add all the registers in the range to the register list.
3344 Count += EndReg - Reg;
3345 Reg = EndReg;
3346 continue;
3347 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003348 Parser.Lex(); // Eat the comma.
3349 RegLoc = Parser.getTok().getLoc();
3350 int OldReg = Reg;
3351 Reg = tryParseRegister();
3352 if (Reg == -1) {
3353 Error(RegLoc, "register expected");
3354 return MatchOperand_ParseFail;
3355 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003356 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003357 // It's OK to use the enumeration values directly here rather, as the
3358 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003359 //
3360 // The list is of D registers, but we also allow Q regs and just interpret
3361 // them as the two D sub-registers.
3362 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003363 if (!Spacing)
3364 Spacing = 1; // Register range implies a single spaced list.
3365 else if (Spacing == 2) {
3366 Error(RegLoc,
3367 "invalid register in double-spaced list (must be 'D' register')");
3368 return MatchOperand_ParseFail;
3369 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003370 Reg = getDRegFromQReg(Reg);
3371 if (Reg != OldReg + 1) {
3372 Error(RegLoc, "non-contiguous register range");
3373 return MatchOperand_ParseFail;
3374 }
3375 ++Reg;
3376 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003377 // Parse the lane specifier if present.
3378 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003379 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003380 SMLoc LaneLoc = Parser.getTok().getLoc();
3381 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3382 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003383 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003384 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003385 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003386 return MatchOperand_ParseFail;
3387 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003388 continue;
3389 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003390 // Normal D register.
3391 // Figure out the register spacing (single or double) of the list if
3392 // we don't know it already.
3393 if (!Spacing)
3394 Spacing = 1 + (Reg == OldReg + 2);
3395
3396 // Just check that it's contiguous and keep going.
3397 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003398 Error(RegLoc, "non-contiguous register range");
3399 return MatchOperand_ParseFail;
3400 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003401 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003402 // Parse the lane specifier if present.
3403 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003404 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003405 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003406 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003407 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003408 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003409 Error(EndLoc, "mismatched lane index in register list");
3410 return MatchOperand_ParseFail;
3411 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003412 }
3413
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003414 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003415 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003416 return MatchOperand_ParseFail;
3417 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003418 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003419 Parser.Lex(); // Eat '}' token.
3420
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003421 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003422 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003423 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003424 // composite register classes.
3425 if (Count == 2) {
3426 const MCRegisterClass *RC = (Spacing == 1) ?
3427 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3428 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3429 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3430 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003431
Jim Grosbach2f50e922011-12-15 21:44:33 +00003432 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3433 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003434 break;
3435 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003436 // Two-register operands have been converted to the
3437 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003438 if (Count == 2) {
3439 const MCRegisterClass *RC = (Spacing == 1) ?
3440 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3441 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003442 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3443 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003444 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003445 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003446 S, E));
3447 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003448 case IndexedLane:
3449 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003450 LaneIndex,
3451 (Spacing == 2),
3452 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003453 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003454 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003455 return MatchOperand_Success;
3456}
3457
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003458/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003459ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003460parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003461 SMLoc S = Parser.getTok().getLoc();
3462 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003463 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003464
Jiangning Liu288e1af2012-08-02 08:21:27 +00003465 if (Tok.is(AsmToken::Identifier)) {
3466 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003467
Jiangning Liu288e1af2012-08-02 08:21:27 +00003468 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3469 .Case("sy", ARM_MB::SY)
3470 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003471 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003472 .Case("sh", ARM_MB::ISH)
3473 .Case("ish", ARM_MB::ISH)
3474 .Case("shst", ARM_MB::ISHST)
3475 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003476 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003477 .Case("nsh", ARM_MB::NSH)
3478 .Case("un", ARM_MB::NSH)
3479 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003480 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003481 .Case("unst", ARM_MB::NSHST)
3482 .Case("osh", ARM_MB::OSH)
3483 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003484 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003485 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003486
Joey Gouly926d3f52013-09-05 15:35:24 +00003487 // ishld, oshld, nshld and ld are only available from ARMv8.
3488 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3489 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3490 Opt = ~0U;
3491
Jiangning Liu288e1af2012-08-02 08:21:27 +00003492 if (Opt == ~0U)
3493 return MatchOperand_NoMatch;
3494
3495 Parser.Lex(); // Eat identifier token.
3496 } else if (Tok.is(AsmToken::Hash) ||
3497 Tok.is(AsmToken::Dollar) ||
3498 Tok.is(AsmToken::Integer)) {
3499 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003500 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003501 SMLoc Loc = Parser.getTok().getLoc();
3502
3503 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003504 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003505 Error(Loc, "illegal expression");
3506 return MatchOperand_ParseFail;
3507 }
3508
3509 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3510 if (!CE) {
3511 Error(Loc, "constant expression expected");
3512 return MatchOperand_ParseFail;
3513 }
3514
3515 int Val = CE->getValue();
3516 if (Val & ~0xf) {
3517 Error(Loc, "immediate value out of range");
3518 return MatchOperand_ParseFail;
3519 }
3520
3521 Opt = ARM_MB::RESERVED_0 + Val;
3522 } else
3523 return MatchOperand_ParseFail;
3524
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003525 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003526 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003527}
3528
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003529/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3530ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3531parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3532 SMLoc S = Parser.getTok().getLoc();
3533 const AsmToken &Tok = Parser.getTok();
3534 unsigned Opt;
3535
3536 if (Tok.is(AsmToken::Identifier)) {
3537 StringRef OptStr = Tok.getString();
3538
3539 if (OptStr.lower() == "sy")
3540 Opt = ARM_ISB::SY;
3541 else
3542 return MatchOperand_NoMatch;
3543
3544 Parser.Lex(); // Eat identifier token.
3545 } else if (Tok.is(AsmToken::Hash) ||
3546 Tok.is(AsmToken::Dollar) ||
3547 Tok.is(AsmToken::Integer)) {
3548 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003549 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003550 SMLoc Loc = Parser.getTok().getLoc();
3551
3552 const MCExpr *ISBarrierID;
3553 if (getParser().parseExpression(ISBarrierID)) {
3554 Error(Loc, "illegal expression");
3555 return MatchOperand_ParseFail;
3556 }
3557
3558 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3559 if (!CE) {
3560 Error(Loc, "constant expression expected");
3561 return MatchOperand_ParseFail;
3562 }
3563
3564 int Val = CE->getValue();
3565 if (Val & ~0xf) {
3566 Error(Loc, "immediate value out of range");
3567 return MatchOperand_ParseFail;
3568 }
3569
3570 Opt = ARM_ISB::RESERVED_0 + Val;
3571 } else
3572 return MatchOperand_ParseFail;
3573
3574 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3575 (ARM_ISB::InstSyncBOpt)Opt, S));
3576 return MatchOperand_Success;
3577}
3578
3579
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003580/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003581ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003582parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003583 SMLoc S = Parser.getTok().getLoc();
3584 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003585 if (!Tok.is(AsmToken::Identifier))
3586 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003587 StringRef IFlagsStr = Tok.getString();
3588
Owen Anderson10c5b122011-10-05 17:16:40 +00003589 // An iflags string of "none" is interpreted to mean that none of the AIF
3590 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003591 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003592 if (IFlagsStr != "none") {
3593 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3594 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3595 .Case("a", ARM_PROC::A)
3596 .Case("i", ARM_PROC::I)
3597 .Case("f", ARM_PROC::F)
3598 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003599
Owen Anderson10c5b122011-10-05 17:16:40 +00003600 // If some specific iflag is already set, it means that some letter is
3601 // present more than once, this is not acceptable.
3602 if (Flag == ~0U || (IFlags & Flag))
3603 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003604
Owen Anderson10c5b122011-10-05 17:16:40 +00003605 IFlags |= Flag;
3606 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003607 }
3608
3609 Parser.Lex(); // Eat identifier token.
3610 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3611 return MatchOperand_Success;
3612}
3613
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003614/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003615ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003616parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003617 SMLoc S = Parser.getTok().getLoc();
3618 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003619 if (!Tok.is(AsmToken::Identifier))
3620 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003621 StringRef Mask = Tok.getString();
3622
James Molloy21efa7d2011-09-28 14:21:38 +00003623 if (isMClass()) {
3624 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003625 std::string Name = Mask.lower();
3626 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003627 // Note: in the documentation:
3628 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3629 // for MSR APSR_nzcvq.
3630 // but we do make it an alias here. This is so to get the "mask encoding"
3631 // bits correct on MSR APSR writes.
3632 //
3633 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3634 // should really only be allowed when writing a special register. Note
3635 // they get dropped in the MRS instruction reading a special register as
3636 // the SYSm field is only 8 bits.
3637 //
3638 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3639 // includes the DSP extension but that is not checked.
3640 .Case("apsr", 0x800)
3641 .Case("apsr_nzcvq", 0x800)
3642 .Case("apsr_g", 0x400)
3643 .Case("apsr_nzcvqg", 0xc00)
3644 .Case("iapsr", 0x801)
3645 .Case("iapsr_nzcvq", 0x801)
3646 .Case("iapsr_g", 0x401)
3647 .Case("iapsr_nzcvqg", 0xc01)
3648 .Case("eapsr", 0x802)
3649 .Case("eapsr_nzcvq", 0x802)
3650 .Case("eapsr_g", 0x402)
3651 .Case("eapsr_nzcvqg", 0xc02)
3652 .Case("xpsr", 0x803)
3653 .Case("xpsr_nzcvq", 0x803)
3654 .Case("xpsr_g", 0x403)
3655 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003656 .Case("ipsr", 0x805)
3657 .Case("epsr", 0x806)
3658 .Case("iepsr", 0x807)
3659 .Case("msp", 0x808)
3660 .Case("psp", 0x809)
3661 .Case("primask", 0x810)
3662 .Case("basepri", 0x811)
3663 .Case("basepri_max", 0x812)
3664 .Case("faultmask", 0x813)
3665 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003666 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003667
James Molloy21efa7d2011-09-28 14:21:38 +00003668 if (FlagsVal == ~0U)
3669 return MatchOperand_NoMatch;
3670
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003671 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003672 // basepri, basepri_max and faultmask only valid for V7m.
3673 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003674
James Molloy21efa7d2011-09-28 14:21:38 +00003675 Parser.Lex(); // Eat identifier token.
3676 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3677 return MatchOperand_Success;
3678 }
3679
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003680 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3681 size_t Start = 0, Next = Mask.find('_');
3682 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003683 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003684 if (Next != StringRef::npos)
3685 Flags = Mask.slice(Next+1, Mask.size());
3686
3687 // FlagsVal contains the complete mask:
3688 // 3-0: Mask
3689 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3690 unsigned FlagsVal = 0;
3691
3692 if (SpecReg == "apsr") {
3693 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003694 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003695 .Case("g", 0x4) // same as CPSR_s
3696 .Case("nzcvqg", 0xc) // same as CPSR_fs
3697 .Default(~0U);
3698
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003699 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003700 if (!Flags.empty())
3701 return MatchOperand_NoMatch;
3702 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003703 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003704 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003705 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003706 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3707 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003708 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003709 for (int i = 0, e = Flags.size(); i != e; ++i) {
3710 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3711 .Case("c", 1)
3712 .Case("x", 2)
3713 .Case("s", 4)
3714 .Case("f", 8)
3715 .Default(~0U);
3716
3717 // If some specific flag is already set, it means that some letter is
3718 // present more than once, this is not acceptable.
3719 if (FlagsVal == ~0U || (FlagsVal & Flag))
3720 return MatchOperand_NoMatch;
3721 FlagsVal |= Flag;
3722 }
3723 } else // No match for special register.
3724 return MatchOperand_NoMatch;
3725
Owen Anderson03a173e2011-10-21 18:43:28 +00003726 // Special register without flags is NOT equivalent to "fc" flags.
3727 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3728 // two lines would enable gas compatibility at the expense of breaking
3729 // round-tripping.
3730 //
3731 // if (!FlagsVal)
3732 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003733
3734 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3735 if (SpecReg == "spsr")
3736 FlagsVal |= 16;
3737
3738 Parser.Lex(); // Eat identifier token.
3739 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3740 return MatchOperand_Success;
3741}
3742
Jim Grosbach27c1e252011-07-21 17:23:04 +00003743ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3744parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3745 int Low, int High) {
3746 const AsmToken &Tok = Parser.getTok();
3747 if (Tok.isNot(AsmToken::Identifier)) {
3748 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3749 return MatchOperand_ParseFail;
3750 }
3751 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003752 std::string LowerOp = Op.lower();
3753 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003754 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3755 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3756 return MatchOperand_ParseFail;
3757 }
3758 Parser.Lex(); // Eat shift type token.
3759
3760 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003761 if (Parser.getTok().isNot(AsmToken::Hash) &&
3762 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003763 Error(Parser.getTok().getLoc(), "'#' expected");
3764 return MatchOperand_ParseFail;
3765 }
3766 Parser.Lex(); // Eat hash token.
3767
3768 const MCExpr *ShiftAmount;
3769 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003770 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003771 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003772 Error(Loc, "illegal expression");
3773 return MatchOperand_ParseFail;
3774 }
3775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3776 if (!CE) {
3777 Error(Loc, "constant expression expected");
3778 return MatchOperand_ParseFail;
3779 }
3780 int Val = CE->getValue();
3781 if (Val < Low || Val > High) {
3782 Error(Loc, "immediate value out of range");
3783 return MatchOperand_ParseFail;
3784 }
3785
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003786 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003787
3788 return MatchOperand_Success;
3789}
3790
Jim Grosbach0a547702011-07-22 17:44:50 +00003791ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3792parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3793 const AsmToken &Tok = Parser.getTok();
3794 SMLoc S = Tok.getLoc();
3795 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003796 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003797 return MatchOperand_ParseFail;
3798 }
Tim Northover4d141442013-05-31 15:58:45 +00003799 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003800 .Case("be", 1)
3801 .Case("le", 0)
3802 .Default(-1);
3803 Parser.Lex(); // Eat the token.
3804
3805 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003806 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003807 return MatchOperand_ParseFail;
3808 }
3809 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3810 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003811 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003812 return MatchOperand_Success;
3813}
3814
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003815/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3816/// instructions. Legal values are:
3817/// lsl #n 'n' in [0,31]
3818/// asr #n 'n' in [1,32]
3819/// n == 32 encoded as n == 0.
3820ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3821parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3822 const AsmToken &Tok = Parser.getTok();
3823 SMLoc S = Tok.getLoc();
3824 if (Tok.isNot(AsmToken::Identifier)) {
3825 Error(S, "shift operator 'asr' or 'lsl' expected");
3826 return MatchOperand_ParseFail;
3827 }
3828 StringRef ShiftName = Tok.getString();
3829 bool isASR;
3830 if (ShiftName == "lsl" || ShiftName == "LSL")
3831 isASR = false;
3832 else if (ShiftName == "asr" || ShiftName == "ASR")
3833 isASR = true;
3834 else {
3835 Error(S, "shift operator 'asr' or 'lsl' expected");
3836 return MatchOperand_ParseFail;
3837 }
3838 Parser.Lex(); // Eat the operator.
3839
3840 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003841 if (Parser.getTok().isNot(AsmToken::Hash) &&
3842 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003843 Error(Parser.getTok().getLoc(), "'#' expected");
3844 return MatchOperand_ParseFail;
3845 }
3846 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003847 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003848
3849 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003850 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003851 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003852 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003853 return MatchOperand_ParseFail;
3854 }
3855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3856 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003857 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003858 return MatchOperand_ParseFail;
3859 }
3860
3861 int64_t Val = CE->getValue();
3862 if (isASR) {
3863 // Shift amount must be in [1,32]
3864 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003865 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003866 return MatchOperand_ParseFail;
3867 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003868 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3869 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003870 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003871 return MatchOperand_ParseFail;
3872 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003873 if (Val == 32) Val = 0;
3874 } else {
3875 // Shift amount must be in [1,32]
3876 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003877 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003878 return MatchOperand_ParseFail;
3879 }
3880 }
3881
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003882 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003883
3884 return MatchOperand_Success;
3885}
3886
Jim Grosbach833b9d32011-07-27 20:15:40 +00003887/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3888/// of instructions. Legal values are:
3889/// ror #n 'n' in {0, 8, 16, 24}
3890ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3891parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3892 const AsmToken &Tok = Parser.getTok();
3893 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003894 if (Tok.isNot(AsmToken::Identifier))
3895 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003896 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003897 if (ShiftName != "ror" && ShiftName != "ROR")
3898 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003899 Parser.Lex(); // Eat the operator.
3900
3901 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003902 if (Parser.getTok().isNot(AsmToken::Hash) &&
3903 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003904 Error(Parser.getTok().getLoc(), "'#' expected");
3905 return MatchOperand_ParseFail;
3906 }
3907 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003908 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003909
3910 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003911 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003912 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003913 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003914 return MatchOperand_ParseFail;
3915 }
3916 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3917 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003918 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003919 return MatchOperand_ParseFail;
3920 }
3921
3922 int64_t Val = CE->getValue();
3923 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3924 // normally, zero is represented in asm by omitting the rotate operand
3925 // entirely.
3926 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003927 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003928 return MatchOperand_ParseFail;
3929 }
3930
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003931 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003932
3933 return MatchOperand_Success;
3934}
3935
Jim Grosbach864b6092011-07-28 21:34:26 +00003936ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3937parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3938 SMLoc S = Parser.getTok().getLoc();
3939 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003940 if (Parser.getTok().isNot(AsmToken::Hash) &&
3941 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003942 Error(Parser.getTok().getLoc(), "'#' expected");
3943 return MatchOperand_ParseFail;
3944 }
3945 Parser.Lex(); // Eat hash token.
3946
3947 const MCExpr *LSBExpr;
3948 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003949 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003950 Error(E, "malformed immediate expression");
3951 return MatchOperand_ParseFail;
3952 }
3953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3954 if (!CE) {
3955 Error(E, "'lsb' operand must be an immediate");
3956 return MatchOperand_ParseFail;
3957 }
3958
3959 int64_t LSB = CE->getValue();
3960 // The LSB must be in the range [0,31]
3961 if (LSB < 0 || LSB > 31) {
3962 Error(E, "'lsb' operand must be in the range [0,31]");
3963 return MatchOperand_ParseFail;
3964 }
3965 E = Parser.getTok().getLoc();
3966
3967 // Expect another immediate operand.
3968 if (Parser.getTok().isNot(AsmToken::Comma)) {
3969 Error(Parser.getTok().getLoc(), "too few operands");
3970 return MatchOperand_ParseFail;
3971 }
3972 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003973 if (Parser.getTok().isNot(AsmToken::Hash) &&
3974 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003975 Error(Parser.getTok().getLoc(), "'#' expected");
3976 return MatchOperand_ParseFail;
3977 }
3978 Parser.Lex(); // Eat hash token.
3979
3980 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003981 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003982 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003983 Error(E, "malformed immediate expression");
3984 return MatchOperand_ParseFail;
3985 }
3986 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3987 if (!CE) {
3988 Error(E, "'width' operand must be an immediate");
3989 return MatchOperand_ParseFail;
3990 }
3991
3992 int64_t Width = CE->getValue();
3993 // The LSB must be in the range [1,32-lsb]
3994 if (Width < 1 || Width > 32 - LSB) {
3995 Error(E, "'width' operand must be in the range [1,32-lsb]");
3996 return MatchOperand_ParseFail;
3997 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003998
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003999 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004000
4001 return MatchOperand_Success;
4002}
4003
Jim Grosbachd3595712011-08-03 23:50:40 +00004004ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4005parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4006 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004007 // postidx_reg := '+' register {, shift}
4008 // | '-' register {, shift}
4009 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004010
4011 // This method must return MatchOperand_NoMatch without consuming any tokens
4012 // in the case where there is no match, as other alternatives take other
4013 // parse methods.
4014 AsmToken Tok = Parser.getTok();
4015 SMLoc S = Tok.getLoc();
4016 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004017 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004018 if (Tok.is(AsmToken::Plus)) {
4019 Parser.Lex(); // Eat the '+' token.
4020 haveEaten = true;
4021 } else if (Tok.is(AsmToken::Minus)) {
4022 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004023 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004024 haveEaten = true;
4025 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004026
4027 SMLoc E = Parser.getTok().getEndLoc();
4028 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004029 if (Reg == -1) {
4030 if (!haveEaten)
4031 return MatchOperand_NoMatch;
4032 Error(Parser.getTok().getLoc(), "register expected");
4033 return MatchOperand_ParseFail;
4034 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004035
Jim Grosbachc320c852011-08-05 21:28:30 +00004036 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4037 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004038 if (Parser.getTok().is(AsmToken::Comma)) {
4039 Parser.Lex(); // Eat the ','.
4040 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4041 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004042
4043 // FIXME: Only approximates end...may include intervening whitespace.
4044 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004045 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004046
4047 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4048 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004049
4050 return MatchOperand_Success;
4051}
4052
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004053ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4054parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4055 // Check for a post-index addressing register operand. Specifically:
4056 // am3offset := '+' register
4057 // | '-' register
4058 // | register
4059 // | # imm
4060 // | # + imm
4061 // | # - imm
4062
4063 // This method must return MatchOperand_NoMatch without consuming any tokens
4064 // in the case where there is no match, as other alternatives take other
4065 // parse methods.
4066 AsmToken Tok = Parser.getTok();
4067 SMLoc S = Tok.getLoc();
4068
4069 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004070 if (Parser.getTok().is(AsmToken::Hash) ||
4071 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004072 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004073 // Explicitly look for a '-', as we need to encode negative zero
4074 // differently.
4075 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4076 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004077 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004078 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004079 return MatchOperand_ParseFail;
4080 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4081 if (!CE) {
4082 Error(S, "constant expression expected");
4083 return MatchOperand_ParseFail;
4084 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004085 // Negative zero is encoded as the flag value INT32_MIN.
4086 int32_t Val = CE->getValue();
4087 if (isNegative && Val == 0)
4088 Val = INT32_MIN;
4089
4090 Operands.push_back(
4091 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4092
4093 return MatchOperand_Success;
4094 }
4095
4096
4097 bool haveEaten = false;
4098 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004099 if (Tok.is(AsmToken::Plus)) {
4100 Parser.Lex(); // Eat the '+' token.
4101 haveEaten = true;
4102 } else if (Tok.is(AsmToken::Minus)) {
4103 Parser.Lex(); // Eat the '-' token.
4104 isAdd = false;
4105 haveEaten = true;
4106 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004107
4108 Tok = Parser.getTok();
4109 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004110 if (Reg == -1) {
4111 if (!haveEaten)
4112 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004113 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004114 return MatchOperand_ParseFail;
4115 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004116
4117 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004118 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004119
4120 return MatchOperand_Success;
4121}
4122
Tim Northovereb5e4d52013-07-22 09:06:12 +00004123/// Convert parsed operands to MCInst. Needed here because this instruction
4124/// only has two register operands, but multiplication is commutative so
4125/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004126void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004127cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004128 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004129 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4130 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004131 // If we have a three-operand form, make sure to set Rn to be the operand
4132 // that isn't the same as Rd.
4133 unsigned RegOp = 4;
4134 if (Operands.size() == 6 &&
4135 ((ARMOperand*)Operands[4])->getReg() ==
4136 ((ARMOperand*)Operands[3])->getReg())
4137 RegOp = 5;
4138 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4139 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004140 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004141}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004142
Mihai Popaad18d3c2013-08-09 10:38:32 +00004143void ARMAsmParser::
4144cvtThumbBranches(MCInst &Inst,
4145 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4146 int CondOp = -1, ImmOp = -1;
4147 switch(Inst.getOpcode()) {
4148 case ARM::tB:
4149 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4150
4151 case ARM::t2B:
4152 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4153
4154 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4155 }
4156 // first decide whether or not the branch should be conditional
4157 // by looking at it's location relative to an IT block
4158 if(inITBlock()) {
4159 // inside an IT block we cannot have any conditional branches. any
4160 // such instructions needs to be converted to unconditional form
4161 switch(Inst.getOpcode()) {
4162 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4163 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4164 }
4165 } else {
4166 // outside IT blocks we can only have unconditional branches with AL
4167 // condition code or conditional branches with non-AL condition code
4168 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4169 switch(Inst.getOpcode()) {
4170 case ARM::tB:
4171 case ARM::tBcc:
4172 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4173 break;
4174 case ARM::t2B:
4175 case ARM::t2Bcc:
4176 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4177 break;
4178 }
4179 }
4180
4181 // now decide on encoding size based on branch target range
4182 switch(Inst.getOpcode()) {
4183 // classify tB as either t2B or t1B based on range of immediate operand
4184 case ARM::tB: {
4185 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4186 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4187 Inst.setOpcode(ARM::t2B);
4188 break;
4189 }
4190 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4191 case ARM::tBcc: {
4192 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4193 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4194 Inst.setOpcode(ARM::t2Bcc);
4195 break;
4196 }
4197 }
4198 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4199 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4200}
4201
Bill Wendlinge18980a2010-11-06 22:36:58 +00004202/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004203/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004204bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004205parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004206 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004207 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004208 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004209 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004210 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004211
Sean Callanan936b0d32010-01-19 21:44:56 +00004212 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004213 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004214 if (BaseRegNum == -1)
4215 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004216
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004217 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004218 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004219 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4220 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004221 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004222
Jim Grosbachd3595712011-08-03 23:50:40 +00004223 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004224 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004225 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004226
Jim Grosbachd3595712011-08-03 23:50:40 +00004227 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004228 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004229
Jim Grosbach40700e02011-09-19 18:42:21 +00004230 // If there's a pre-indexing writeback marker, '!', just add it as a token
4231 // operand. It's rather odd, but syntactically valid.
4232 if (Parser.getTok().is(AsmToken::Exclaim)) {
4233 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4234 Parser.Lex(); // Eat the '!'.
4235 }
4236
Jim Grosbachd3595712011-08-03 23:50:40 +00004237 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004238 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004239
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004240 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4241 "Lost colon or comma in memory operand?!");
4242 if (Tok.is(AsmToken::Comma)) {
4243 Parser.Lex(); // Eat the comma.
4244 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004245
Jim Grosbacha95ec992011-10-11 17:29:55 +00004246 // If we have a ':', it's an alignment specifier.
4247 if (Parser.getTok().is(AsmToken::Colon)) {
4248 Parser.Lex(); // Eat the ':'.
4249 E = Parser.getTok().getLoc();
4250
4251 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004252 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004253 return true;
4254
4255 // The expression has to be a constant. Memory references with relocations
4256 // don't come through here, as they use the <label> forms of the relevant
4257 // instructions.
4258 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4259 if (!CE)
4260 return Error (E, "constant expression expected");
4261
4262 unsigned Align = 0;
4263 switch (CE->getValue()) {
4264 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004265 return Error(E,
4266 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4267 case 16: Align = 2; break;
4268 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004269 case 64: Align = 8; break;
4270 case 128: Align = 16; break;
4271 case 256: Align = 32; break;
4272 }
4273
4274 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004275 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004276 return Error(Parser.getTok().getLoc(), "']' expected");
4277 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004278 Parser.Lex(); // Eat right bracket token.
4279
4280 // Don't worry about range checking the value here. That's handled by
4281 // the is*() predicates.
4282 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4283 ARM_AM::no_shift, 0, Align,
4284 false, S, E));
4285
4286 // If there's a pre-indexing writeback marker, '!', just add it as a token
4287 // operand.
4288 if (Parser.getTok().is(AsmToken::Exclaim)) {
4289 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4290 Parser.Lex(); // Eat the '!'.
4291 }
4292
4293 return false;
4294 }
4295
4296 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004297 // offset. Be friendly and also accept a plain integer (without a leading
4298 // hash) for gas compatibility.
4299 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004300 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004301 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004302 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004303 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004304 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004305
Owen Anderson967674d2011-08-29 19:36:44 +00004306 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004307 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004308 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004309 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004310
4311 // The expression has to be a constant. Memory references with relocations
4312 // don't come through here, as they use the <label> forms of the relevant
4313 // instructions.
4314 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4315 if (!CE)
4316 return Error (E, "constant expression expected");
4317
Owen Anderson967674d2011-08-29 19:36:44 +00004318 // If the constant was #-0, represent it as INT32_MIN.
4319 int32_t Val = CE->getValue();
4320 if (isNegative && Val == 0)
4321 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4322
Jim Grosbachd3595712011-08-03 23:50:40 +00004323 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004324 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004325 return Error(Parser.getTok().getLoc(), "']' expected");
4326 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004327 Parser.Lex(); // Eat right bracket token.
4328
4329 // Don't worry about range checking the value here. That's handled by
4330 // the is*() predicates.
4331 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004332 ARM_AM::no_shift, 0, 0,
4333 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004334
4335 // If there's a pre-indexing writeback marker, '!', just add it as a token
4336 // operand.
4337 if (Parser.getTok().is(AsmToken::Exclaim)) {
4338 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4339 Parser.Lex(); // Eat the '!'.
4340 }
4341
4342 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004343 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004344
4345 // The register offset is optionally preceded by a '+' or '-'
4346 bool isNegative = false;
4347 if (Parser.getTok().is(AsmToken::Minus)) {
4348 isNegative = true;
4349 Parser.Lex(); // Eat the '-'.
4350 } else if (Parser.getTok().is(AsmToken::Plus)) {
4351 // Nothing to do.
4352 Parser.Lex(); // Eat the '+'.
4353 }
4354
4355 E = Parser.getTok().getLoc();
4356 int OffsetRegNum = tryParseRegister();
4357 if (OffsetRegNum == -1)
4358 return Error(E, "register expected");
4359
4360 // If there's a shift operator, handle it.
4361 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004362 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004363 if (Parser.getTok().is(AsmToken::Comma)) {
4364 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004365 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004366 return true;
4367 }
4368
4369 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004370 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004371 return Error(Parser.getTok().getLoc(), "']' expected");
4372 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004373 Parser.Lex(); // Eat right bracket token.
4374
4375 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004376 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004377 S, E));
4378
Jim Grosbachc320c852011-08-05 21:28:30 +00004379 // If there's a pre-indexing writeback marker, '!', just add it as a token
4380 // operand.
4381 if (Parser.getTok().is(AsmToken::Exclaim)) {
4382 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4383 Parser.Lex(); // Eat the '!'.
4384 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004385
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004386 return false;
4387}
4388
Jim Grosbachd3595712011-08-03 23:50:40 +00004389/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004390/// ( lsl | lsr | asr | ror ) , # shift_amount
4391/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004392/// return true if it parses a shift otherwise it returns false.
4393bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4394 unsigned &Amount) {
4395 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004396 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004397 if (Tok.isNot(AsmToken::Identifier))
4398 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004399 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004400 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4401 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004402 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004403 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004404 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004405 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004406 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004407 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004408 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004409 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004410 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004411 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004412 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004413 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004414
Jim Grosbachd3595712011-08-03 23:50:40 +00004415 // rrx stands alone.
4416 Amount = 0;
4417 if (St != ARM_AM::rrx) {
4418 Loc = Parser.getTok().getLoc();
4419 // A '#' and a shift amount.
4420 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004421 if (HashTok.isNot(AsmToken::Hash) &&
4422 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004423 return Error(HashTok.getLoc(), "'#' expected");
4424 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004425
Jim Grosbachd3595712011-08-03 23:50:40 +00004426 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004427 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004428 return true;
4429 // Range check the immediate.
4430 // lsl, ror: 0 <= imm <= 31
4431 // lsr, asr: 0 <= imm <= 32
4432 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4433 if (!CE)
4434 return Error(Loc, "shift amount must be an immediate");
4435 int64_t Imm = CE->getValue();
4436 if (Imm < 0 ||
4437 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4438 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4439 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004440 // If <ShiftTy> #0, turn it into a no_shift.
4441 if (Imm == 0)
4442 St = ARM_AM::lsl;
4443 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4444 if (Imm == 32)
4445 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004446 Amount = Imm;
4447 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004448
4449 return false;
4450}
4451
Jim Grosbache7fbce72011-10-03 23:38:36 +00004452/// parseFPImm - A floating point immediate expression operand.
4453ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4454parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004455 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004456 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004457 // integer only.
4458 //
4459 // This routine still creates a generic Immediate operand, containing
4460 // a bitcast of the 64-bit floating point value. The various operands
4461 // that accept floats can check whether the value is valid for them
4462 // via the standard is*() predicates.
4463
Jim Grosbache7fbce72011-10-03 23:38:36 +00004464 SMLoc S = Parser.getTok().getLoc();
4465
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004466 if (Parser.getTok().isNot(AsmToken::Hash) &&
4467 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004468 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004469
4470 // Disambiguate the VMOV forms that can accept an FP immediate.
4471 // vmov.f32 <sreg>, #imm
4472 // vmov.f64 <dreg>, #imm
4473 // vmov.f32 <dreg>, #imm @ vector f32x2
4474 // vmov.f32 <qreg>, #imm @ vector f32x4
4475 //
4476 // There are also the NEON VMOV instructions which expect an
4477 // integer constant. Make sure we don't try to parse an FPImm
4478 // for these:
4479 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4480 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4481 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4482 TyOp->getToken() != ".f64"))
4483 return MatchOperand_NoMatch;
4484
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004485 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004486
4487 // Handle negation, as that still comes through as a separate token.
4488 bool isNegative = false;
4489 if (Parser.getTok().is(AsmToken::Minus)) {
4490 isNegative = true;
4491 Parser.Lex();
4492 }
4493 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004494 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004495 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004496 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004497 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4498 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004499 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004500 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004501 Operands.push_back(ARMOperand::CreateImm(
4502 MCConstantExpr::Create(IntVal, getContext()),
4503 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004504 return MatchOperand_Success;
4505 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004506 // Also handle plain integers. Instructions which allow floating point
4507 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004508 if (Tok.is(AsmToken::Integer)) {
4509 int64_t Val = Tok.getIntVal();
4510 Parser.Lex(); // Eat the token.
4511 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004512 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004513 return MatchOperand_ParseFail;
4514 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004515 double RealVal = ARM_AM::getFPImmFloat(Val);
4516 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4517 Operands.push_back(ARMOperand::CreateImm(
4518 MCConstantExpr::Create(Val, getContext()), S,
4519 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004520 return MatchOperand_Success;
4521 }
4522
Jim Grosbach235c8d22012-01-19 02:47:30 +00004523 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004524 return MatchOperand_ParseFail;
4525}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004526
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004527/// Parse a arm instruction operand. For now this parses the operand regardless
4528/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004529bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004530 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004531 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004532
4533 // Check if the current operand has a custom associated parser, if so, try to
4534 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004535 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4536 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004537 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004538 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4539 // there was a match, but an error occurred, in which case, just return that
4540 // the operand parsing failed.
4541 if (ResTy == MatchOperand_ParseFail)
4542 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004543
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004544 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004545 default:
4546 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004547 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004548 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004549 // If we've seen a branch mnemonic, the next operand must be a label. This
4550 // is true even if the label is a register name. So "br r1" means branch to
4551 // label "r1".
4552 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4553 if (!ExpectLabel) {
4554 if (!tryParseRegisterWithWriteBack(Operands))
4555 return false;
4556 int Res = tryParseShiftRegister(Operands);
4557 if (Res == 0) // success
4558 return false;
4559 else if (Res == -1) // irrecoverable error
4560 return true;
4561 // If this is VMRS, check for the apsr_nzcv operand.
4562 if (Mnemonic == "vmrs" &&
4563 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4564 S = Parser.getTok().getLoc();
4565 Parser.Lex();
4566 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4567 return false;
4568 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004569 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004570
4571 // Fall though for the Identifier case that is not a register or a
4572 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004573 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004574 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004575 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004576 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004577 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004578 // This was not a register so parse other operands that start with an
4579 // identifier (like labels) as expressions and create them as immediates.
4580 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004581 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004582 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004583 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004584 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004585 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4586 return false;
4587 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004588 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004589 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004590 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004591 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004592 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004593 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004594 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004595 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004596 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004597
4598 if (Parser.getTok().isNot(AsmToken::Colon)) {
4599 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4600 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004601 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004602 return true;
4603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4604 if (CE) {
4605 int32_t Val = CE->getValue();
4606 if (isNegative && Val == 0)
4607 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4608 }
4609 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4610 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004611
4612 // There can be a trailing '!' on operands that we want as a separate
4613 // '!' Token operand. Handle that here. For example, the compatibilty
4614 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4615 if (Parser.getTok().is(AsmToken::Exclaim)) {
4616 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4617 Parser.getTok().getLoc()));
4618 Parser.Lex(); // Eat exclaim token
4619 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004620 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004621 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004622 // w/ a ':' after the '#', it's just like a plain ':'.
4623 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004624 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004625 case AsmToken::Colon: {
4626 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004627 // FIXME: Check it's an expression prefix,
4628 // e.g. (FOO - :lower16:BAR) isn't legal.
4629 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004630 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004631 return true;
4632
Evan Cheng965b3c72011-01-13 07:58:56 +00004633 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004634 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004635 return true;
4636
Evan Cheng965b3c72011-01-13 07:58:56 +00004637 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004638 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004639 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004640 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004641 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004642 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004643 }
4644}
4645
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004646// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004647// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004648bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004649 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004650
4651 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004652 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004653 Parser.Lex(); // Eat ':'
4654
4655 if (getLexer().isNot(AsmToken::Identifier)) {
4656 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4657 return true;
4658 }
4659
4660 StringRef IDVal = Parser.getTok().getIdentifier();
4661 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004662 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004663 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004664 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004665 } else {
4666 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4667 return true;
4668 }
4669 Parser.Lex();
4670
4671 if (getLexer().isNot(AsmToken::Colon)) {
4672 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4673 return true;
4674 }
4675 Parser.Lex(); // Eat the last ':'
4676 return false;
4677}
4678
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004679/// \brief Given a mnemonic, split out possible predication code and carry
4680/// setting letters to form a canonical mnemonic and flags.
4681//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004682// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004683// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004684StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004685 unsigned &PredicationCode,
4686 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004687 unsigned &ProcessorIMod,
4688 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004689 PredicationCode = ARMCC::AL;
4690 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004691 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004692
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004693 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004694 //
4695 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004696 if ((Mnemonic == "movs" && isThumb()) ||
4697 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4698 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4699 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4700 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004701 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004702 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4703 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004704 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004705 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004706 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4707 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4708 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004709 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004710
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004711 // First, split out any predication code. Ignore mnemonics we know aren't
4712 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004713 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004714 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004715 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004716 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004717 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4718 .Case("eq", ARMCC::EQ)
4719 .Case("ne", ARMCC::NE)
4720 .Case("hs", ARMCC::HS)
4721 .Case("cs", ARMCC::HS)
4722 .Case("lo", ARMCC::LO)
4723 .Case("cc", ARMCC::LO)
4724 .Case("mi", ARMCC::MI)
4725 .Case("pl", ARMCC::PL)
4726 .Case("vs", ARMCC::VS)
4727 .Case("vc", ARMCC::VC)
4728 .Case("hi", ARMCC::HI)
4729 .Case("ls", ARMCC::LS)
4730 .Case("ge", ARMCC::GE)
4731 .Case("lt", ARMCC::LT)
4732 .Case("gt", ARMCC::GT)
4733 .Case("le", ARMCC::LE)
4734 .Case("al", ARMCC::AL)
4735 .Default(~0U);
4736 if (CC != ~0U) {
4737 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4738 PredicationCode = CC;
4739 }
Bill Wendling193961b2010-10-29 23:50:21 +00004740 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004741
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004742 // Next, determine if we have a carry setting bit. We explicitly ignore all
4743 // the instructions we know end in 's'.
4744 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004745 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004746 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4747 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4748 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004749 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004750 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004751 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004752 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004753 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004754 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004755 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4756 CarrySetting = true;
4757 }
4758
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004759 // The "cps" instruction can have a interrupt mode operand which is glued into
4760 // the mnemonic. Check if this is the case, split it and parse the imod op
4761 if (Mnemonic.startswith("cps")) {
4762 // Split out any imod code.
4763 unsigned IMod =
4764 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4765 .Case("ie", ARM_PROC::IE)
4766 .Case("id", ARM_PROC::ID)
4767 .Default(~0U);
4768 if (IMod != ~0U) {
4769 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4770 ProcessorIMod = IMod;
4771 }
4772 }
4773
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004774 // The "it" instruction has the condition mask on the end of the mnemonic.
4775 if (Mnemonic.startswith("it")) {
4776 ITMask = Mnemonic.slice(2, Mnemonic.size());
4777 Mnemonic = Mnemonic.slice(0, 2);
4778 }
4779
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004780 return Mnemonic;
4781}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004782
4783/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4784/// inclusion of carry set or predication code operands.
4785//
4786// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004787void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00004788getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4789 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004790 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4791 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004792 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004793 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004794 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004795 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004796 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004797 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004798 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004799 Mnemonic == "mla" || Mnemonic == "smlal" ||
4800 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004801 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004802 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004803 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004804
Tim Northover2c45a382013-06-26 16:52:40 +00004805 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4806 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00004807 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004808 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4809 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004810 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4811 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00004812 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4813 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4814 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00004815 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004816 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004817 } else if (!isThumb()) {
4818 // Some instructions are only predicable in Thumb mode
4819 CanAcceptPredicationCode
4820 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4821 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4822 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4823 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4824 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4825 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4826 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4827 } else if (isThumbOne()) {
4828 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004829 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004830 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004831}
4832
Jim Grosbach7283da92011-08-16 21:12:37 +00004833bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4834 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004835 // FIXME: This is all horribly hacky. We really need a better way to deal
4836 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004837
4838 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4839 // another does not. Specifically, the MOVW instruction does not. So we
4840 // special case it here and remove the defaulted (non-setting) cc_out
4841 // operand if that's the instruction we're trying to match.
4842 //
4843 // We do this as post-processing of the explicit operands rather than just
4844 // conditionally adding the cc_out in the first place because we need
4845 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004846 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004847 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4848 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4849 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4850 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004851
4852 // Register-register 'add' for thumb does not have a cc_out operand
4853 // when there are only two register operands.
4854 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4855 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4856 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4857 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4858 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004859 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004860 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4861 // have to check the immediate range here since Thumb2 has a variant
4862 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004863 if (((isThumb() && Mnemonic == "add") ||
4864 (isThumbTwo() && Mnemonic == "sub")) &&
4865 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004866 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4867 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4868 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004869 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004870 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004871 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004872 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004873 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4874 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004875 // selecting via the generic "add" mnemonic, so to know that we
4876 // should remove the cc_out operand, we have to explicitly check that
4877 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004878 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4879 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004880 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4881 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4882 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4883 // Nest conditions rather than one big 'if' statement for readability.
4884 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004885 // If both registers are low, we're in an IT block, and the immediate is
4886 // in range, we should use encoding T1 instead, which has a cc_out.
4887 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004888 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004889 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4890 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4891 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004892 // Check against T3. If the second register is the PC, this is an
4893 // alternate form of ADR, which uses encoding T4, so check for that too.
4894 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4895 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4896 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004897
4898 // Otherwise, we use encoding T4, which does not have a cc_out
4899 // operand.
4900 return true;
4901 }
4902
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004903 // The thumb2 multiply instruction doesn't have a CCOut register, so
4904 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4905 // use the 16-bit encoding or not.
4906 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4907 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4908 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4909 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4910 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4911 // If the registers aren't low regs, the destination reg isn't the
4912 // same as one of the source regs, or the cc_out operand is zero
4913 // outside of an IT block, we have to use the 32-bit encoding, so
4914 // remove the cc_out operand.
4915 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4916 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004917 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004918 !inITBlock() ||
4919 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4920 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4921 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4922 static_cast<ARMOperand*>(Operands[4])->getReg())))
4923 return true;
4924
Jim Grosbachefa7e952011-11-15 19:55:16 +00004925 // Also check the 'mul' syntax variant that doesn't specify an explicit
4926 // destination register.
4927 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4928 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4929 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4930 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4931 // If the registers aren't low regs or the cc_out operand is zero
4932 // outside of an IT block, we have to use the 32-bit encoding, so
4933 // remove the cc_out operand.
4934 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4935 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4936 !inITBlock()))
4937 return true;
4938
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004939
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004940
Jim Grosbach4b701af2011-08-24 21:42:27 +00004941 // Register-register 'add/sub' for thumb does not have a cc_out operand
4942 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4943 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4944 // right, this will result in better diagnostics (which operand is off)
4945 // anyway.
4946 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4947 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004948 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4949 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004950 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4951 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4952 (Operands.size() == 6 &&
4953 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004954 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004955
Jim Grosbach7283da92011-08-16 21:12:37 +00004956 return false;
4957}
4958
Joey Goulye8602552013-07-19 16:34:16 +00004959bool ARMAsmParser::shouldOmitPredicateOperand(
4960 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4961 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4962 unsigned RegIdx = 3;
4963 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4964 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4965 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4966 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4967 RegIdx = 4;
4968
4969 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4970 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4971 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4972 ARMMCRegisterClasses[ARM::QPRRegClassID]
4973 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4974 return true;
4975 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004976 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004977}
4978
Jim Grosbach12952fe2011-11-11 23:08:10 +00004979static bool isDataTypeToken(StringRef Tok) {
4980 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4981 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4982 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4983 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4984 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4985 Tok == ".f" || Tok == ".d";
4986}
4987
4988// FIXME: This bit should probably be handled via an explicit match class
4989// in the .td files that matches the suffix instead of having it be
4990// a literal string token the way it is now.
4991static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4992 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4993}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004994static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4995 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004996/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004997bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4998 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004999 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005000 // Apply mnemonic aliases before doing anything else, as the destination
5001 // mnemnonic may include suffices and we want to handle them normally.
5002 // The generic tblgen'erated code does this later, at the start of
5003 // MatchInstructionImpl(), but that's too late for aliases that include
5004 // any sort of suffix.
5005 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005006 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5007 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005008
Jim Grosbachab5830e2011-12-14 02:16:11 +00005009 // First check for the ARM-specific .req directive.
5010 if (Parser.getTok().is(AsmToken::Identifier) &&
5011 Parser.getTok().getIdentifier() == ".req") {
5012 parseDirectiveReq(Name, NameLoc);
5013 // We always return 'error' for this, as we're done with this
5014 // statement and don't need to match the 'instruction."
5015 return true;
5016 }
5017
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005018 // Create the leading tokens for the mnemonic, split by '.' characters.
5019 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005020 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005021
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005022 // Split out the predication code and carry setting flag from the mnemonic.
5023 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005024 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005025 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005026 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005027 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005028 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005029
Jim Grosbach1c171b12011-08-25 17:23:55 +00005030 // In Thumb1, only the branch (B) instruction can be predicated.
5031 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005032 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005033 return Error(NameLoc, "conditional execution not supported in Thumb1");
5034 }
5035
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005036 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5037
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005038 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5039 // is the mask as it will be for the IT encoding if the conditional
5040 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5041 // where the conditional bit0 is zero, the instruction post-processing
5042 // will adjust the mask accordingly.
5043 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005044 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5045 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005046 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005047 return Error(Loc, "too many conditions on IT instruction");
5048 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005049 unsigned Mask = 8;
5050 for (unsigned i = ITMask.size(); i != 0; --i) {
5051 char pos = ITMask[i - 1];
5052 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005053 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005054 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005055 }
5056 Mask >>= 1;
5057 if (ITMask[i - 1] == 't')
5058 Mask |= 8;
5059 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005060 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005061 }
5062
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005063 // FIXME: This is all a pretty gross hack. We should automatically handle
5064 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005065
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005066 // Next, add the CCOut and ConditionCode operands, if needed.
5067 //
5068 // For mnemonics which can ever incorporate a carry setting bit or predication
5069 // code, our matching model involves us always generating CCOut and
5070 // ConditionCode operands to match the mnemonic "as written" and then we let
5071 // the matcher deal with finding the right instruction or generating an
5072 // appropriate error.
5073 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005074 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005075
Jim Grosbach03a8a162011-07-14 22:04:21 +00005076 // If we had a carry-set on an instruction that can't do that, issue an
5077 // error.
5078 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005079 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005080 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005081 "' can not set flags, but 's' suffix specified");
5082 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005083 // If we had a predication code on an instruction that can't do that, issue an
5084 // error.
5085 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005086 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005087 return Error(NameLoc, "instruction '" + Mnemonic +
5088 "' is not predicable, but condition code specified");
5089 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005090
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005091 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005092 if (CanAcceptCarrySet) {
5093 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005094 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005095 Loc));
5096 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005097
5098 // Add the predication code operand, if necessary.
5099 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005100 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5101 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005102 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005103 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005104 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005105
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005106 // Add the processor imod operand, if necessary.
5107 if (ProcessorIMod) {
5108 Operands.push_back(ARMOperand::CreateImm(
5109 MCConstantExpr::Create(ProcessorIMod, getContext()),
5110 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005111 }
5112
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005113 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005114 while (Next != StringRef::npos) {
5115 Start = Next;
5116 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005117 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005118
Jim Grosbach12952fe2011-11-11 23:08:10 +00005119 // Some NEON instructions have an optional datatype suffix that is
5120 // completely ignored. Check for that.
5121 if (isDataTypeToken(ExtraToken) &&
5122 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5123 continue;
5124
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005125 // For for ARM mode generate an error if the .n qualifier is used.
5126 if (ExtraToken == ".n" && !isThumb()) {
5127 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5128 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5129 "arm mode");
5130 }
5131
5132 // The .n qualifier is always discarded as that is what the tables
5133 // and matcher expect. In ARM mode the .w qualifier has no effect,
5134 // so discard it to avoid errors that can be caused by the matcher.
5135 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005136 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5137 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5138 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005139 }
5140
5141 // Read the remaining operands.
5142 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005143 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005144 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005145 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005146 return true;
5147 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005148
5149 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005150 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005151
5152 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005153 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005154 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005155 return true;
5156 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005157 }
5158 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005159
Chris Lattnera2a9d162010-09-11 16:18:25 +00005160 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005161 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005162 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005163 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005164 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005165
Chris Lattner91689c12010-09-08 05:10:46 +00005166 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005167
Jim Grosbach7283da92011-08-16 21:12:37 +00005168 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5169 // do and don't have a cc_out optional-def operand. With some spot-checks
5170 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005171 // parse and adjust accordingly before actually matching. We shouldn't ever
5172 // try to remove a cc_out operand that was explicitly set on the the
5173 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5174 // table driven matcher doesn't fit well with the ARM instruction set.
5175 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005176 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5177 Operands.erase(Operands.begin() + 1);
5178 delete Op;
5179 }
5180
Joey Goulye8602552013-07-19 16:34:16 +00005181 // Some instructions have the same mnemonic, but don't always
5182 // have a predicate. Distinguish them here and delete the
5183 // predicate if needed.
5184 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5185 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5186 Operands.erase(Operands.begin() + 1);
5187 delete Op;
5188 }
5189
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005190 // ARM mode 'blx' need special handling, as the register operand version
5191 // is predicable, but the label operand version is not. So, we can't rely
5192 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005193 // a k_CondCode operand in the list. If we're trying to match the label
5194 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005195 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5196 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5197 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5198 Operands.erase(Operands.begin() + 1);
5199 delete Op;
5200 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005201
Weiming Zhao8f56f882012-11-16 21:55:34 +00005202 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5203 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5204 // a single GPRPair reg operand is used in the .td file to replace the two
5205 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5206 // expressed as a GPRPair, so we have to manually merge them.
5207 // FIXME: We would really like to be able to tablegen'erate this.
5208 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005209 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5210 Mnemonic == "stlexd")) {
5211 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005212 unsigned Idx = isLoad ? 2 : 3;
5213 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5214 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5215
5216 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5217 // Adjust only if Op1 and Op2 are GPRs.
5218 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5219 MRC.contains(Op2->getReg())) {
5220 unsigned Reg1 = Op1->getReg();
5221 unsigned Reg2 = Op2->getReg();
5222 unsigned Rt = MRI->getEncodingValue(Reg1);
5223 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5224
5225 // Rt2 must be Rt + 1 and Rt must be even.
5226 if (Rt + 1 != Rt2 || (Rt & 1)) {
5227 Error(Op2->getStartLoc(), isLoad ?
5228 "destination operands must be sequential" :
5229 "source operands must be sequential");
5230 return true;
5231 }
5232 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5233 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5234 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5235 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5236 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5237 delete Op1;
5238 delete Op2;
5239 }
5240 }
5241
Kevin Enderby78f95722013-07-31 21:05:30 +00005242 // FIXME: As said above, this is all a pretty gross hack. This instruction
5243 // does not fit with other "subs" and tblgen.
5244 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5245 // so the Mnemonic is the original name "subs" and delete the predicate
5246 // operand so it will match the table entry.
5247 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5248 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5249 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5250 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5251 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5252 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5253 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5254 Operands.erase(Operands.begin());
5255 delete Op0;
5256 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5257
5258 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5259 Operands.erase(Operands.begin() + 1);
5260 delete Op1;
5261 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005262 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005263}
5264
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005265// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005266
5267// return 'true' if register list contains non-low GPR registers,
5268// 'false' otherwise. If Reg is in the register list or is HiReg, set
5269// 'containsReg' to true.
5270static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5271 unsigned HiReg, bool &containsReg) {
5272 containsReg = false;
5273 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5274 unsigned OpReg = Inst.getOperand(i).getReg();
5275 if (OpReg == Reg)
5276 containsReg = true;
5277 // Anything other than a low register isn't legal here.
5278 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5279 return true;
5280 }
5281 return false;
5282}
5283
Jim Grosbacha31f2232011-09-07 18:05:34 +00005284// Check if the specified regisgter is in the register list of the inst,
5285// starting at the indicated operand number.
5286static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5287 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5288 unsigned OpReg = Inst.getOperand(i).getReg();
5289 if (OpReg == Reg)
5290 return true;
5291 }
5292 return false;
5293}
5294
Richard Barton8d519fe2013-09-05 14:14:19 +00005295// Return true if instruction has the interesting property of being
5296// allowed in IT blocks, but not being predicable.
5297static bool instIsBreakpoint(const MCInst &Inst) {
5298 return Inst.getOpcode() == ARM::tBKPT ||
5299 Inst.getOpcode() == ARM::BKPT ||
5300 Inst.getOpcode() == ARM::tHLT ||
5301 Inst.getOpcode() == ARM::HLT;
5302
5303}
5304
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005305// FIXME: We would really like to be able to tablegen'erate this.
5306bool ARMAsmParser::
5307validateInstruction(MCInst &Inst,
5308 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005309 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005310 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005311
Jim Grosbached16ec42011-08-29 22:24:09 +00005312 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005313 // NOTE: BKPT and HLT instructions have the interesting property of being
5314 // allowed in IT blocks, but not being predicable. They just always
5315 // execute.
5316 if (inITBlock() && !instIsBreakpoint(Inst)) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005317 unsigned bit = 1;
5318 if (ITState.FirstCond)
5319 ITState.FirstCond = false;
5320 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005321 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005322 // The instruction must be predicable.
5323 if (!MCID.isPredicable())
5324 return Error(Loc, "instructions in IT block must be predicable");
5325 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5326 unsigned ITCond = bit ? ITState.Cond :
5327 ARMCC::getOppositeCondition(ITState.Cond);
5328 if (Cond != ITCond) {
5329 // Find the condition code Operand to get its SMLoc information.
5330 SMLoc CondLoc;
5331 for (unsigned i = 1; i < Operands.size(); ++i)
5332 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5333 CondLoc = Operands[i]->getStartLoc();
5334 return Error(CondLoc, "incorrect condition in IT block; got '" +
5335 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5336 "', but expected '" +
5337 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5338 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005339 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005340 } else if (isThumbTwo() && MCID.isPredicable() &&
5341 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005342 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5343 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005344 return Error(Loc, "predicated instructions must be in IT block");
5345
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005346 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005347 case ARM::LDRD:
5348 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005349 case ARM::LDRD_POST: {
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005350 unsigned RtReg = Inst.getOperand(0).getReg();
5351 // Rt can't be R14.
5352 if (RtReg == ARM::LR)
5353 return Error(Operands[3]->getStartLoc(),
5354 "Rt can't be R14");
5355 unsigned Rt = MRI->getEncodingValue(RtReg);
5356 // Rt must be even-numbered.
5357 if ((Rt & 1) == 1)
5358 return Error(Operands[3]->getStartLoc(),
5359 "Rt must be even-numbered");
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005360 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005361 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005362 if (Rt2 != Rt + 1)
5363 return Error(Operands[3]->getStartLoc(),
5364 "destination operands must be sequential");
5365 return false;
5366 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005367 case ARM::t2LDRDi8:
5368 case ARM::t2LDRD_PRE:
5369 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005370 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005371 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5372 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5373 if (Rt2 == Rt)
5374 return Error(Operands[3]->getStartLoc(),
5375 "destination operands can't be identical");
5376 return false;
5377 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005378 case ARM::STRD: {
5379 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005380 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5381 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005382 if (Rt2 != Rt + 1)
5383 return Error(Operands[3]->getStartLoc(),
5384 "source operands must be sequential");
5385 return false;
5386 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005387 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005388 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005389 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005390 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5391 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005392 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005393 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005394 "source operands must be sequential");
5395 return false;
5396 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005397 case ARM::SBFX:
5398 case ARM::UBFX: {
5399 // width must be in range [1, 32-lsb]
5400 unsigned lsb = Inst.getOperand(2).getImm();
5401 unsigned widthm1 = Inst.getOperand(3).getImm();
5402 if (widthm1 >= 32 - lsb)
5403 return Error(Operands[5]->getStartLoc(),
5404 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005405 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005406 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005407 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005408 // If we're parsing Thumb2, the .w variant is available and handles
5409 // most cases that are normally illegal for a Thumb1 LDM
5410 // instruction. We'll make the transformation in processInstruction()
5411 // if necessary.
5412 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005413 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005414 // in the register list.
5415 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005416 bool hasWritebackToken =
5417 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5418 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005419 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005420 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005421 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5422 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005423 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005424 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005425 return Error(Operands[2]->getStartLoc(),
5426 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005427 // If we should not have writeback, there must not be a '!'. This is
5428 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005429 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005430 return Error(Operands[3]->getStartLoc(),
5431 "writeback operator '!' not allowed when base register "
5432 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005433
5434 break;
5435 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005436 case ARM::t2LDMIA_UPD: {
5437 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5438 return Error(Operands[4]->getStartLoc(),
5439 "writeback operator '!' not allowed when base register "
5440 "in register list");
5441 break;
5442 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005443 case ARM::tMUL: {
5444 // The second source operand must be the same register as the destination
5445 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005446 //
5447 // In this case, we must directly check the parsed operands because the
5448 // cvtThumbMultiply() function is written in such a way that it guarantees
5449 // this first statement is always true for the new Inst. Essentially, the
5450 // destination is unconditionally copied into the second source operand
5451 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005452 if (Operands.size() == 6 &&
5453 (((ARMOperand*)Operands[3])->getReg() !=
5454 ((ARMOperand*)Operands[5])->getReg()) &&
5455 (((ARMOperand*)Operands[3])->getReg() !=
5456 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005457 return Error(Operands[3]->getStartLoc(),
5458 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005459 }
5460 break;
5461 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005462 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5463 // so only issue a diagnostic for thumb1. The instructions will be
5464 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005465 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005466 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005467 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5468 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005469 return Error(Operands[2]->getStartLoc(),
5470 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005471 break;
5472 }
5473 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005474 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005475 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5476 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005477 return Error(Operands[2]->getStartLoc(),
5478 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005479 break;
5480 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005481 case ARM::tSTMIA_UPD: {
5482 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005483 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005484 return Error(Operands[4]->getStartLoc(),
5485 "registers must be in range r0-r7");
5486 break;
5487 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005488 case ARM::tADDrSP: {
5489 // If the non-SP source operand and the destination operand are not the
5490 // same, we need thumb2 (for the wide encoding), or we have an error.
5491 if (!isThumbTwo() &&
5492 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5493 return Error(Operands[4]->getStartLoc(),
5494 "source register must be the same as destination");
5495 }
5496 break;
5497 }
Mihai Popaad18d3c2013-08-09 10:38:32 +00005498 // final range checking for Thumb unconditional branch instructions
5499 case ARM::tB:
5500 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5501 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5502 break;
5503 case ARM::t2B: {
5504 int op = (Operands[2]->isImm()) ? 2 : 3;
5505 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5506 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5507 break;
5508 }
5509 // final range checking for Thumb conditional branch instructions
5510 case ARM::tBcc:
5511 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5512 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5513 break;
5514 case ARM::t2Bcc: {
5515 int op = (Operands[2]->isImm()) ? 2 : 3;
5516 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<20, 1>())
5517 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5518 break;
5519 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005520 }
5521
5522 return false;
5523}
5524
Jim Grosbach1a747242012-01-23 23:45:44 +00005525static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005526 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005527 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005528 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005529 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5530 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5531 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5532 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5533 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5534 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5535 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5536 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5537 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005538
5539 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005540 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5541 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5542 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5543 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5544 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005545
Jim Grosbach1e946a42012-01-24 00:43:12 +00005546 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5547 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5548 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5549 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5550 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005551
Jim Grosbach1e946a42012-01-24 00:43:12 +00005552 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5553 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5554 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5555 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5556 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005557
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005558 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005559 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5560 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5561 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5562 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5563 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5564 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5565 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5566 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5567 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5568 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5569 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5570 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5571 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5572 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5573 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005574
Jim Grosbach1a747242012-01-23 23:45:44 +00005575 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005576 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5577 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5578 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5579 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5580 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5581 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5582 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5583 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5584 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5585 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5586 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5587 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5588 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5589 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5590 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5591 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5592 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5593 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005594
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005595 // VST4LN
5596 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5597 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5598 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5599 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5600 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5601 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5602 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5603 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5604 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5605 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5606 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5607 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5608 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5609 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5610 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5611
Jim Grosbachda70eac2012-01-24 00:58:13 +00005612 // VST4
5613 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5614 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5615 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5616 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5617 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5618 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5619 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5620 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5621 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5622 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5623 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5624 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5625 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5626 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5627 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5628 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5629 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5630 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005631 }
5632}
5633
Jim Grosbach1a747242012-01-23 23:45:44 +00005634static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005635 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005636 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005637 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005638 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5639 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5640 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5641 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5642 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5643 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5644 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5645 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5646 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005647
5648 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005649 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5650 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5651 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5652 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5653 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5654 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5655 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5656 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5657 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5658 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5659 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5660 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5661 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5662 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5663 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005664
Jim Grosbachb78403c2012-01-24 23:47:04 +00005665 // VLD3DUP
5666 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5667 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5668 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5669 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5670 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5671 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5672 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5673 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5674 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5675 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5676 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5677 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5678 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5679 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5680 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5681 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5682 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5683 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5684
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005685 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005686 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5687 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5688 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5689 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5690 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5691 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5692 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5693 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5694 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5695 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5696 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5697 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5698 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5699 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5700 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005701
5702 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005703 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5704 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5705 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5706 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5707 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5708 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5709 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5710 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5711 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5712 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5713 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5714 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5715 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5716 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5717 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5718 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5719 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5720 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005721
Jim Grosbach14952a02012-01-24 18:37:25 +00005722 // VLD4LN
5723 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5724 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5725 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5726 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5727 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5728 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5729 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5730 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5731 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5732 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5733 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5734 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5735 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5736 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5737 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5738
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005739 // VLD4DUP
5740 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5741 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5742 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5743 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5744 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5745 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5746 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5747 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5748 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5749 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5750 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5751 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5752 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5753 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5754 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5755 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5756 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5757 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5758
Jim Grosbached561fc2012-01-24 00:43:17 +00005759 // VLD4
5760 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5761 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5762 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5763 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5764 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5765 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5766 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5767 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5768 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5769 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5770 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5771 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5772 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5773 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5774 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5775 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5776 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5777 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005778 }
5779}
5780
Jim Grosbachafad0532011-11-10 23:42:14 +00005781bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005782processInstruction(MCInst &Inst,
5783 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5784 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005785 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5786 case ARM::ADDri: {
5787 if (Inst.getOperand(1).getReg() != ARM::PC ||
5788 Inst.getOperand(5).getReg() != 0)
5789 return false;
5790 MCInst TmpInst;
5791 TmpInst.setOpcode(ARM::ADR);
5792 TmpInst.addOperand(Inst.getOperand(0));
5793 TmpInst.addOperand(Inst.getOperand(2));
5794 TmpInst.addOperand(Inst.getOperand(3));
5795 TmpInst.addOperand(Inst.getOperand(4));
5796 Inst = TmpInst;
5797 return true;
5798 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005799 // Aliases for alternate PC+imm syntax of LDR instructions.
5800 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005801 // Select the narrow version if the immediate will fit.
5802 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005803 Inst.getOperand(1).getImm() <= 0xff &&
5804 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5805 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005806 Inst.setOpcode(ARM::tLDRpci);
5807 else
5808 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005809 return true;
5810 case ARM::t2LDRBpcrel:
5811 Inst.setOpcode(ARM::t2LDRBpci);
5812 return true;
5813 case ARM::t2LDRHpcrel:
5814 Inst.setOpcode(ARM::t2LDRHpci);
5815 return true;
5816 case ARM::t2LDRSBpcrel:
5817 Inst.setOpcode(ARM::t2LDRSBpci);
5818 return true;
5819 case ARM::t2LDRSHpcrel:
5820 Inst.setOpcode(ARM::t2LDRSHpci);
5821 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005822 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005823 case ARM::VST1LNdWB_register_Asm_8:
5824 case ARM::VST1LNdWB_register_Asm_16:
5825 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005826 MCInst TmpInst;
5827 // Shuffle the operands around so the lane index operand is in the
5828 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005829 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005830 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005831 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5832 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5833 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5834 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5835 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5836 TmpInst.addOperand(Inst.getOperand(1)); // lane
5837 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5838 TmpInst.addOperand(Inst.getOperand(6));
5839 Inst = TmpInst;
5840 return true;
5841 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005842
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005843 case ARM::VST2LNdWB_register_Asm_8:
5844 case ARM::VST2LNdWB_register_Asm_16:
5845 case ARM::VST2LNdWB_register_Asm_32:
5846 case ARM::VST2LNqWB_register_Asm_16:
5847 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005848 MCInst TmpInst;
5849 // Shuffle the operands around so the lane index operand is in the
5850 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005851 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005852 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005853 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5854 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5855 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5856 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5857 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5859 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005860 TmpInst.addOperand(Inst.getOperand(1)); // lane
5861 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5862 TmpInst.addOperand(Inst.getOperand(6));
5863 Inst = TmpInst;
5864 return true;
5865 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005866
5867 case ARM::VST3LNdWB_register_Asm_8:
5868 case ARM::VST3LNdWB_register_Asm_16:
5869 case ARM::VST3LNdWB_register_Asm_32:
5870 case ARM::VST3LNqWB_register_Asm_16:
5871 case ARM::VST3LNqWB_register_Asm_32: {
5872 MCInst TmpInst;
5873 // Shuffle the operands around so the lane index operand is in the
5874 // right place.
5875 unsigned Spacing;
5876 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5877 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5878 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5879 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5880 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5881 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5883 Spacing));
5884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5885 Spacing * 2));
5886 TmpInst.addOperand(Inst.getOperand(1)); // lane
5887 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5888 TmpInst.addOperand(Inst.getOperand(6));
5889 Inst = TmpInst;
5890 return true;
5891 }
5892
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005893 case ARM::VST4LNdWB_register_Asm_8:
5894 case ARM::VST4LNdWB_register_Asm_16:
5895 case ARM::VST4LNdWB_register_Asm_32:
5896 case ARM::VST4LNqWB_register_Asm_16:
5897 case ARM::VST4LNqWB_register_Asm_32: {
5898 MCInst TmpInst;
5899 // Shuffle the operands around so the lane index operand is in the
5900 // right place.
5901 unsigned Spacing;
5902 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5903 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5904 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5905 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5906 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5907 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5908 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5909 Spacing));
5910 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5911 Spacing * 2));
5912 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5913 Spacing * 3));
5914 TmpInst.addOperand(Inst.getOperand(1)); // lane
5915 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5916 TmpInst.addOperand(Inst.getOperand(6));
5917 Inst = TmpInst;
5918 return true;
5919 }
5920
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005921 case ARM::VST1LNdWB_fixed_Asm_8:
5922 case ARM::VST1LNdWB_fixed_Asm_16:
5923 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005924 MCInst TmpInst;
5925 // Shuffle the operands around so the lane index operand is in the
5926 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005927 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005928 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005929 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5930 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5931 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5932 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5933 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5934 TmpInst.addOperand(Inst.getOperand(1)); // lane
5935 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5936 TmpInst.addOperand(Inst.getOperand(5));
5937 Inst = TmpInst;
5938 return true;
5939 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005940
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005941 case ARM::VST2LNdWB_fixed_Asm_8:
5942 case ARM::VST2LNdWB_fixed_Asm_16:
5943 case ARM::VST2LNdWB_fixed_Asm_32:
5944 case ARM::VST2LNqWB_fixed_Asm_16:
5945 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005946 MCInst TmpInst;
5947 // Shuffle the operands around so the lane index operand is in the
5948 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005949 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005950 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005951 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5952 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5953 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5954 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5955 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005956 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5957 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005958 TmpInst.addOperand(Inst.getOperand(1)); // lane
5959 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5960 TmpInst.addOperand(Inst.getOperand(5));
5961 Inst = TmpInst;
5962 return true;
5963 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005964
5965 case ARM::VST3LNdWB_fixed_Asm_8:
5966 case ARM::VST3LNdWB_fixed_Asm_16:
5967 case ARM::VST3LNdWB_fixed_Asm_32:
5968 case ARM::VST3LNqWB_fixed_Asm_16:
5969 case ARM::VST3LNqWB_fixed_Asm_32: {
5970 MCInst TmpInst;
5971 // Shuffle the operands around so the lane index operand is in the
5972 // right place.
5973 unsigned Spacing;
5974 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5975 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5976 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5977 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5978 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5979 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5980 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5981 Spacing));
5982 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5983 Spacing * 2));
5984 TmpInst.addOperand(Inst.getOperand(1)); // lane
5985 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5986 TmpInst.addOperand(Inst.getOperand(5));
5987 Inst = TmpInst;
5988 return true;
5989 }
5990
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005991 case ARM::VST4LNdWB_fixed_Asm_8:
5992 case ARM::VST4LNdWB_fixed_Asm_16:
5993 case ARM::VST4LNdWB_fixed_Asm_32:
5994 case ARM::VST4LNqWB_fixed_Asm_16:
5995 case ARM::VST4LNqWB_fixed_Asm_32: {
5996 MCInst TmpInst;
5997 // Shuffle the operands around so the lane index operand is in the
5998 // right place.
5999 unsigned Spacing;
6000 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6001 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6002 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6003 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6004 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6005 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6006 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6007 Spacing));
6008 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6009 Spacing * 2));
6010 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6011 Spacing * 3));
6012 TmpInst.addOperand(Inst.getOperand(1)); // lane
6013 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6014 TmpInst.addOperand(Inst.getOperand(5));
6015 Inst = TmpInst;
6016 return true;
6017 }
6018
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006019 case ARM::VST1LNdAsm_8:
6020 case ARM::VST1LNdAsm_16:
6021 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006022 MCInst TmpInst;
6023 // Shuffle the operands around so the lane index operand is in the
6024 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006025 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006026 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006027 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6028 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6029 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6030 TmpInst.addOperand(Inst.getOperand(1)); // lane
6031 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6032 TmpInst.addOperand(Inst.getOperand(5));
6033 Inst = TmpInst;
6034 return true;
6035 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006036
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006037 case ARM::VST2LNdAsm_8:
6038 case ARM::VST2LNdAsm_16:
6039 case ARM::VST2LNdAsm_32:
6040 case ARM::VST2LNqAsm_16:
6041 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006042 MCInst TmpInst;
6043 // Shuffle the operands around so the lane index operand is in the
6044 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006045 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006046 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006047 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6048 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6049 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006050 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6051 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006052 TmpInst.addOperand(Inst.getOperand(1)); // lane
6053 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6054 TmpInst.addOperand(Inst.getOperand(5));
6055 Inst = TmpInst;
6056 return true;
6057 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006058
6059 case ARM::VST3LNdAsm_8:
6060 case ARM::VST3LNdAsm_16:
6061 case ARM::VST3LNdAsm_32:
6062 case ARM::VST3LNqAsm_16:
6063 case ARM::VST3LNqAsm_32: {
6064 MCInst TmpInst;
6065 // Shuffle the operands around so the lane index operand is in the
6066 // right place.
6067 unsigned Spacing;
6068 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6069 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6070 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6071 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6072 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6073 Spacing));
6074 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6075 Spacing * 2));
6076 TmpInst.addOperand(Inst.getOperand(1)); // lane
6077 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6078 TmpInst.addOperand(Inst.getOperand(5));
6079 Inst = TmpInst;
6080 return true;
6081 }
6082
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006083 case ARM::VST4LNdAsm_8:
6084 case ARM::VST4LNdAsm_16:
6085 case ARM::VST4LNdAsm_32:
6086 case ARM::VST4LNqAsm_16:
6087 case ARM::VST4LNqAsm_32: {
6088 MCInst TmpInst;
6089 // Shuffle the operands around so the lane index operand is in the
6090 // right place.
6091 unsigned Spacing;
6092 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6093 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6094 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6095 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6096 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6097 Spacing));
6098 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6099 Spacing * 2));
6100 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6101 Spacing * 3));
6102 TmpInst.addOperand(Inst.getOperand(1)); // lane
6103 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6104 TmpInst.addOperand(Inst.getOperand(5));
6105 Inst = TmpInst;
6106 return true;
6107 }
6108
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006109 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006110 case ARM::VLD1LNdWB_register_Asm_8:
6111 case ARM::VLD1LNdWB_register_Asm_16:
6112 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006113 MCInst TmpInst;
6114 // Shuffle the operands around so the lane index operand is in the
6115 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006116 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006117 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006118 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6119 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6120 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6121 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6122 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6123 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6124 TmpInst.addOperand(Inst.getOperand(1)); // lane
6125 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6126 TmpInst.addOperand(Inst.getOperand(6));
6127 Inst = TmpInst;
6128 return true;
6129 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006130
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006131 case ARM::VLD2LNdWB_register_Asm_8:
6132 case ARM::VLD2LNdWB_register_Asm_16:
6133 case ARM::VLD2LNdWB_register_Asm_32:
6134 case ARM::VLD2LNqWB_register_Asm_16:
6135 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006136 MCInst TmpInst;
6137 // Shuffle the operands around so the lane index operand is in the
6138 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006139 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006140 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006141 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6143 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006144 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6145 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6146 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6147 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6148 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006149 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6150 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006151 TmpInst.addOperand(Inst.getOperand(1)); // lane
6152 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6153 TmpInst.addOperand(Inst.getOperand(6));
6154 Inst = TmpInst;
6155 return true;
6156 }
6157
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006158 case ARM::VLD3LNdWB_register_Asm_8:
6159 case ARM::VLD3LNdWB_register_Asm_16:
6160 case ARM::VLD3LNdWB_register_Asm_32:
6161 case ARM::VLD3LNqWB_register_Asm_16:
6162 case ARM::VLD3LNqWB_register_Asm_32: {
6163 MCInst TmpInst;
6164 // Shuffle the operands around so the lane index operand is in the
6165 // right place.
6166 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006167 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006168 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6169 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6170 Spacing));
6171 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006172 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006173 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6174 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6175 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6176 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6177 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6178 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6179 Spacing));
6180 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006181 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006182 TmpInst.addOperand(Inst.getOperand(1)); // lane
6183 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6184 TmpInst.addOperand(Inst.getOperand(6));
6185 Inst = TmpInst;
6186 return true;
6187 }
6188
Jim Grosbach14952a02012-01-24 18:37:25 +00006189 case ARM::VLD4LNdWB_register_Asm_8:
6190 case ARM::VLD4LNdWB_register_Asm_16:
6191 case ARM::VLD4LNdWB_register_Asm_32:
6192 case ARM::VLD4LNqWB_register_Asm_16:
6193 case ARM::VLD4LNqWB_register_Asm_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(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6199 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6200 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6201 Spacing));
6202 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6203 Spacing * 2));
6204 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6205 Spacing * 3));
6206 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6207 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6208 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6209 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6210 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6212 Spacing));
6213 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6214 Spacing * 2));
6215 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6216 Spacing * 3));
6217 TmpInst.addOperand(Inst.getOperand(1)); // lane
6218 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6219 TmpInst.addOperand(Inst.getOperand(6));
6220 Inst = TmpInst;
6221 return true;
6222 }
6223
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006224 case ARM::VLD1LNdWB_fixed_Asm_8:
6225 case ARM::VLD1LNdWB_fixed_Asm_16:
6226 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006227 MCInst TmpInst;
6228 // Shuffle the operands around so the lane index operand is in the
6229 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006230 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006231 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006232 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6233 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6234 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6235 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6236 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6237 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6238 TmpInst.addOperand(Inst.getOperand(1)); // lane
6239 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6240 TmpInst.addOperand(Inst.getOperand(5));
6241 Inst = TmpInst;
6242 return true;
6243 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006244
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006245 case ARM::VLD2LNdWB_fixed_Asm_8:
6246 case ARM::VLD2LNdWB_fixed_Asm_16:
6247 case ARM::VLD2LNdWB_fixed_Asm_32:
6248 case ARM::VLD2LNqWB_fixed_Asm_16:
6249 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006250 MCInst TmpInst;
6251 // Shuffle the operands around so the lane index operand is in the
6252 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006253 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006254 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006255 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6257 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006258 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6259 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6260 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6261 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6262 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006263 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6264 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006265 TmpInst.addOperand(Inst.getOperand(1)); // lane
6266 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6267 TmpInst.addOperand(Inst.getOperand(5));
6268 Inst = TmpInst;
6269 return true;
6270 }
6271
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006272 case ARM::VLD3LNdWB_fixed_Asm_8:
6273 case ARM::VLD3LNdWB_fixed_Asm_16:
6274 case ARM::VLD3LNdWB_fixed_Asm_32:
6275 case ARM::VLD3LNqWB_fixed_Asm_16:
6276 case ARM::VLD3LNqWB_fixed_Asm_32: {
6277 MCInst TmpInst;
6278 // Shuffle the operands around so the lane index operand is in the
6279 // right place.
6280 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006281 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006282 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6283 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6284 Spacing));
6285 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006286 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006287 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6288 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6289 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6290 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6291 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6292 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6293 Spacing));
6294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006295 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006296 TmpInst.addOperand(Inst.getOperand(1)); // lane
6297 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6298 TmpInst.addOperand(Inst.getOperand(5));
6299 Inst = TmpInst;
6300 return true;
6301 }
6302
Jim Grosbach14952a02012-01-24 18:37:25 +00006303 case ARM::VLD4LNdWB_fixed_Asm_8:
6304 case ARM::VLD4LNdWB_fixed_Asm_16:
6305 case ARM::VLD4LNdWB_fixed_Asm_32:
6306 case ARM::VLD4LNqWB_fixed_Asm_16:
6307 case ARM::VLD4LNqWB_fixed_Asm_32: {
6308 MCInst TmpInst;
6309 // Shuffle the operands around so the lane index operand is in the
6310 // right place.
6311 unsigned Spacing;
6312 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6313 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6314 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6315 Spacing));
6316 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6317 Spacing * 2));
6318 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6319 Spacing * 3));
6320 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6321 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6322 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6323 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6324 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6326 Spacing));
6327 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6328 Spacing * 2));
6329 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6330 Spacing * 3));
6331 TmpInst.addOperand(Inst.getOperand(1)); // lane
6332 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6333 TmpInst.addOperand(Inst.getOperand(5));
6334 Inst = TmpInst;
6335 return true;
6336 }
6337
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006338 case ARM::VLD1LNdAsm_8:
6339 case ARM::VLD1LNdAsm_16:
6340 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006341 MCInst TmpInst;
6342 // Shuffle the operands around so the lane index operand is in the
6343 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006344 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006345 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006346 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6347 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6348 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6349 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6350 TmpInst.addOperand(Inst.getOperand(1)); // lane
6351 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6352 TmpInst.addOperand(Inst.getOperand(5));
6353 Inst = TmpInst;
6354 return true;
6355 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006356
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006357 case ARM::VLD2LNdAsm_8:
6358 case ARM::VLD2LNdAsm_16:
6359 case ARM::VLD2LNdAsm_32:
6360 case ARM::VLD2LNqAsm_16:
6361 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006362 MCInst TmpInst;
6363 // Shuffle the operands around so the lane index operand is in the
6364 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006365 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006366 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006367 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006368 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6369 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006370 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6371 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6372 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6374 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006375 TmpInst.addOperand(Inst.getOperand(1)); // lane
6376 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6377 TmpInst.addOperand(Inst.getOperand(5));
6378 Inst = TmpInst;
6379 return true;
6380 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006381
6382 case ARM::VLD3LNdAsm_8:
6383 case ARM::VLD3LNdAsm_16:
6384 case ARM::VLD3LNdAsm_32:
6385 case ARM::VLD3LNqAsm_16:
6386 case ARM::VLD3LNqAsm_32: {
6387 MCInst TmpInst;
6388 // Shuffle the operands around so the lane index operand is in the
6389 // right place.
6390 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006391 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006392 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6393 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6394 Spacing));
6395 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006396 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006397 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6398 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6399 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6401 Spacing));
6402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006403 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006404 TmpInst.addOperand(Inst.getOperand(1)); // lane
6405 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6406 TmpInst.addOperand(Inst.getOperand(5));
6407 Inst = TmpInst;
6408 return true;
6409 }
6410
Jim Grosbach14952a02012-01-24 18:37:25 +00006411 case ARM::VLD4LNdAsm_8:
6412 case ARM::VLD4LNdAsm_16:
6413 case ARM::VLD4LNdAsm_32:
6414 case ARM::VLD4LNqAsm_16:
6415 case ARM::VLD4LNqAsm_32: {
6416 MCInst TmpInst;
6417 // Shuffle the operands around so the lane index operand is in the
6418 // right place.
6419 unsigned Spacing;
6420 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6421 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6423 Spacing));
6424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6425 Spacing * 2));
6426 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6427 Spacing * 3));
6428 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6429 TmpInst.addOperand(Inst.getOperand(3)); // alignment
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 Grosbachb78403c2012-01-24 23:47:04 +00006444 // VLD3DUP single 3-element structure to all lanes instructions.
6445 case ARM::VLD3DUPdAsm_8:
6446 case ARM::VLD3DUPdAsm_16:
6447 case ARM::VLD3DUPdAsm_32:
6448 case ARM::VLD3DUPqAsm_8:
6449 case ARM::VLD3DUPqAsm_16:
6450 case ARM::VLD3DUPqAsm_32: {
6451 MCInst TmpInst;
6452 unsigned Spacing;
6453 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6454 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6455 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6456 Spacing));
6457 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6458 Spacing * 2));
6459 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6460 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6461 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6462 TmpInst.addOperand(Inst.getOperand(4));
6463 Inst = TmpInst;
6464 return true;
6465 }
6466
6467 case ARM::VLD3DUPdWB_fixed_Asm_8:
6468 case ARM::VLD3DUPdWB_fixed_Asm_16:
6469 case ARM::VLD3DUPdWB_fixed_Asm_32:
6470 case ARM::VLD3DUPqWB_fixed_Asm_8:
6471 case ARM::VLD3DUPqWB_fixed_Asm_16:
6472 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6473 MCInst TmpInst;
6474 unsigned Spacing;
6475 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6476 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6477 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6478 Spacing));
6479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6480 Spacing * 2));
6481 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6482 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6483 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6484 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6485 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6486 TmpInst.addOperand(Inst.getOperand(4));
6487 Inst = TmpInst;
6488 return true;
6489 }
6490
6491 case ARM::VLD3DUPdWB_register_Asm_8:
6492 case ARM::VLD3DUPdWB_register_Asm_16:
6493 case ARM::VLD3DUPdWB_register_Asm_32:
6494 case ARM::VLD3DUPqWB_register_Asm_8:
6495 case ARM::VLD3DUPqWB_register_Asm_16:
6496 case ARM::VLD3DUPqWB_register_Asm_32: {
6497 MCInst TmpInst;
6498 unsigned Spacing;
6499 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6500 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6501 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6502 Spacing));
6503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6504 Spacing * 2));
6505 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6506 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6507 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6508 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6509 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6510 TmpInst.addOperand(Inst.getOperand(5));
6511 Inst = TmpInst;
6512 return true;
6513 }
6514
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006515 // VLD3 multiple 3-element structure instructions.
6516 case ARM::VLD3dAsm_8:
6517 case ARM::VLD3dAsm_16:
6518 case ARM::VLD3dAsm_32:
6519 case ARM::VLD3qAsm_8:
6520 case ARM::VLD3qAsm_16:
6521 case ARM::VLD3qAsm_32: {
6522 MCInst TmpInst;
6523 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006524 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006525 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6526 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6527 Spacing));
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6529 Spacing * 2));
6530 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6531 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6532 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6533 TmpInst.addOperand(Inst.getOperand(4));
6534 Inst = TmpInst;
6535 return true;
6536 }
6537
6538 case ARM::VLD3dWB_fixed_Asm_8:
6539 case ARM::VLD3dWB_fixed_Asm_16:
6540 case ARM::VLD3dWB_fixed_Asm_32:
6541 case ARM::VLD3qWB_fixed_Asm_8:
6542 case ARM::VLD3qWB_fixed_Asm_16:
6543 case ARM::VLD3qWB_fixed_Asm_32: {
6544 MCInst TmpInst;
6545 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006546 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006547 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6549 Spacing));
6550 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6551 Spacing * 2));
6552 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6553 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6554 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6555 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6556 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6557 TmpInst.addOperand(Inst.getOperand(4));
6558 Inst = TmpInst;
6559 return true;
6560 }
6561
6562 case ARM::VLD3dWB_register_Asm_8:
6563 case ARM::VLD3dWB_register_Asm_16:
6564 case ARM::VLD3dWB_register_Asm_32:
6565 case ARM::VLD3qWB_register_Asm_8:
6566 case ARM::VLD3qWB_register_Asm_16:
6567 case ARM::VLD3qWB_register_Asm_32: {
6568 MCInst TmpInst;
6569 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006570 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006571 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6573 Spacing));
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6575 Spacing * 2));
6576 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6577 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6578 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6579 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6580 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6581 TmpInst.addOperand(Inst.getOperand(5));
6582 Inst = TmpInst;
6583 return true;
6584 }
6585
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006586 // VLD4DUP single 3-element structure to all lanes instructions.
6587 case ARM::VLD4DUPdAsm_8:
6588 case ARM::VLD4DUPdAsm_16:
6589 case ARM::VLD4DUPdAsm_32:
6590 case ARM::VLD4DUPqAsm_8:
6591 case ARM::VLD4DUPqAsm_16:
6592 case ARM::VLD4DUPqAsm_32: {
6593 MCInst TmpInst;
6594 unsigned Spacing;
6595 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6596 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6598 Spacing));
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6600 Spacing * 2));
6601 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6602 Spacing * 3));
6603 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6604 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6605 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6606 TmpInst.addOperand(Inst.getOperand(4));
6607 Inst = TmpInst;
6608 return true;
6609 }
6610
6611 case ARM::VLD4DUPdWB_fixed_Asm_8:
6612 case ARM::VLD4DUPdWB_fixed_Asm_16:
6613 case ARM::VLD4DUPdWB_fixed_Asm_32:
6614 case ARM::VLD4DUPqWB_fixed_Asm_8:
6615 case ARM::VLD4DUPqWB_fixed_Asm_16:
6616 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6617 MCInst TmpInst;
6618 unsigned Spacing;
6619 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6620 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6622 Spacing));
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6624 Spacing * 2));
6625 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6626 Spacing * 3));
6627 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6628 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6629 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6630 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6631 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6632 TmpInst.addOperand(Inst.getOperand(4));
6633 Inst = TmpInst;
6634 return true;
6635 }
6636
6637 case ARM::VLD4DUPdWB_register_Asm_8:
6638 case ARM::VLD4DUPdWB_register_Asm_16:
6639 case ARM::VLD4DUPdWB_register_Asm_32:
6640 case ARM::VLD4DUPqWB_register_Asm_8:
6641 case ARM::VLD4DUPqWB_register_Asm_16:
6642 case ARM::VLD4DUPqWB_register_Asm_32: {
6643 MCInst TmpInst;
6644 unsigned Spacing;
6645 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6646 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6648 Spacing));
6649 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6650 Spacing * 2));
6651 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6652 Spacing * 3));
6653 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6654 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6655 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6656 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6657 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6658 TmpInst.addOperand(Inst.getOperand(5));
6659 Inst = TmpInst;
6660 return true;
6661 }
6662
6663 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006664 case ARM::VLD4dAsm_8:
6665 case ARM::VLD4dAsm_16:
6666 case ARM::VLD4dAsm_32:
6667 case ARM::VLD4qAsm_8:
6668 case ARM::VLD4qAsm_16:
6669 case ARM::VLD4qAsm_32: {
6670 MCInst TmpInst;
6671 unsigned Spacing;
6672 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6673 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6675 Spacing));
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6677 Spacing * 2));
6678 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6679 Spacing * 3));
6680 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6681 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6682 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6683 TmpInst.addOperand(Inst.getOperand(4));
6684 Inst = TmpInst;
6685 return true;
6686 }
6687
6688 case ARM::VLD4dWB_fixed_Asm_8:
6689 case ARM::VLD4dWB_fixed_Asm_16:
6690 case ARM::VLD4dWB_fixed_Asm_32:
6691 case ARM::VLD4qWB_fixed_Asm_8:
6692 case ARM::VLD4qWB_fixed_Asm_16:
6693 case ARM::VLD4qWB_fixed_Asm_32: {
6694 MCInst TmpInst;
6695 unsigned Spacing;
6696 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6697 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6699 Spacing));
6700 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6701 Spacing * 2));
6702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6703 Spacing * 3));
6704 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6705 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6706 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6707 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6708 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6709 TmpInst.addOperand(Inst.getOperand(4));
6710 Inst = TmpInst;
6711 return true;
6712 }
6713
6714 case ARM::VLD4dWB_register_Asm_8:
6715 case ARM::VLD4dWB_register_Asm_16:
6716 case ARM::VLD4dWB_register_Asm_32:
6717 case ARM::VLD4qWB_register_Asm_8:
6718 case ARM::VLD4qWB_register_Asm_16:
6719 case ARM::VLD4qWB_register_Asm_32: {
6720 MCInst TmpInst;
6721 unsigned Spacing;
6722 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6723 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 Spacing));
6726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6727 Spacing * 2));
6728 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6729 Spacing * 3));
6730 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6731 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6732 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6733 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6734 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6735 TmpInst.addOperand(Inst.getOperand(5));
6736 Inst = TmpInst;
6737 return true;
6738 }
6739
Jim Grosbach1a747242012-01-23 23:45:44 +00006740 // VST3 multiple 3-element structure instructions.
6741 case ARM::VST3dAsm_8:
6742 case ARM::VST3dAsm_16:
6743 case ARM::VST3dAsm_32:
6744 case ARM::VST3qAsm_8:
6745 case ARM::VST3qAsm_16:
6746 case ARM::VST3qAsm_32: {
6747 MCInst TmpInst;
6748 unsigned Spacing;
6749 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6750 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6751 TmpInst.addOperand(Inst.getOperand(2)); // alignment
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(Inst.getOperand(3)); // CondCode
6758 TmpInst.addOperand(Inst.getOperand(4));
6759 Inst = TmpInst;
6760 return true;
6761 }
6762
6763 case ARM::VST3dWB_fixed_Asm_8:
6764 case ARM::VST3dWB_fixed_Asm_16:
6765 case ARM::VST3dWB_fixed_Asm_32:
6766 case ARM::VST3qWB_fixed_Asm_8:
6767 case ARM::VST3qWB_fixed_Asm_16:
6768 case ARM::VST3qWB_fixed_Asm_32: {
6769 MCInst TmpInst;
6770 unsigned Spacing;
6771 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6772 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6773 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6774 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6775 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6776 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6778 Spacing));
6779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6780 Spacing * 2));
6781 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6782 TmpInst.addOperand(Inst.getOperand(4));
6783 Inst = TmpInst;
6784 return true;
6785 }
6786
6787 case ARM::VST3dWB_register_Asm_8:
6788 case ARM::VST3dWB_register_Asm_16:
6789 case ARM::VST3dWB_register_Asm_32:
6790 case ARM::VST3qWB_register_Asm_8:
6791 case ARM::VST3qWB_register_Asm_16:
6792 case ARM::VST3qWB_register_Asm_32: {
6793 MCInst TmpInst;
6794 unsigned Spacing;
6795 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6796 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6797 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6798 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6799 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6800 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6801 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6802 Spacing));
6803 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6804 Spacing * 2));
6805 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6806 TmpInst.addOperand(Inst.getOperand(5));
6807 Inst = TmpInst;
6808 return true;
6809 }
6810
Jim Grosbachda70eac2012-01-24 00:58:13 +00006811 // VST4 multiple 3-element structure instructions.
6812 case ARM::VST4dAsm_8:
6813 case ARM::VST4dAsm_16:
6814 case ARM::VST4dAsm_32:
6815 case ARM::VST4qAsm_8:
6816 case ARM::VST4qAsm_16:
6817 case ARM::VST4qAsm_32: {
6818 MCInst TmpInst;
6819 unsigned Spacing;
6820 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6821 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6822 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6823 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6824 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6825 Spacing));
6826 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6827 Spacing * 2));
6828 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6829 Spacing * 3));
6830 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6831 TmpInst.addOperand(Inst.getOperand(4));
6832 Inst = TmpInst;
6833 return true;
6834 }
6835
6836 case ARM::VST4dWB_fixed_Asm_8:
6837 case ARM::VST4dWB_fixed_Asm_16:
6838 case ARM::VST4dWB_fixed_Asm_32:
6839 case ARM::VST4qWB_fixed_Asm_8:
6840 case ARM::VST4qWB_fixed_Asm_16:
6841 case ARM::VST4qWB_fixed_Asm_32: {
6842 MCInst TmpInst;
6843 unsigned Spacing;
6844 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6845 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6846 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6847 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6848 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6849 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6850 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6851 Spacing));
6852 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6853 Spacing * 2));
6854 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6855 Spacing * 3));
6856 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6857 TmpInst.addOperand(Inst.getOperand(4));
6858 Inst = TmpInst;
6859 return true;
6860 }
6861
6862 case ARM::VST4dWB_register_Asm_8:
6863 case ARM::VST4dWB_register_Asm_16:
6864 case ARM::VST4dWB_register_Asm_32:
6865 case ARM::VST4qWB_register_Asm_8:
6866 case ARM::VST4qWB_register_Asm_16:
6867 case ARM::VST4qWB_register_Asm_32: {
6868 MCInst TmpInst;
6869 unsigned Spacing;
6870 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6871 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6872 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6873 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6874 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6875 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6876 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6877 Spacing));
6878 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6879 Spacing * 2));
6880 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6881 Spacing * 3));
6882 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6883 TmpInst.addOperand(Inst.getOperand(5));
6884 Inst = TmpInst;
6885 return true;
6886 }
6887
Jim Grosbachad66de12012-04-11 00:15:16 +00006888 // Handle encoding choice for the shift-immediate instructions.
6889 case ARM::t2LSLri:
6890 case ARM::t2LSRri:
6891 case ARM::t2ASRri: {
6892 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6893 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6894 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6895 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6896 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6897 unsigned NewOpc;
6898 switch (Inst.getOpcode()) {
6899 default: llvm_unreachable("unexpected opcode");
6900 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6901 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6902 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6903 }
6904 // The Thumb1 operands aren't in the same order. Awesome, eh?
6905 MCInst TmpInst;
6906 TmpInst.setOpcode(NewOpc);
6907 TmpInst.addOperand(Inst.getOperand(0));
6908 TmpInst.addOperand(Inst.getOperand(5));
6909 TmpInst.addOperand(Inst.getOperand(1));
6910 TmpInst.addOperand(Inst.getOperand(2));
6911 TmpInst.addOperand(Inst.getOperand(3));
6912 TmpInst.addOperand(Inst.getOperand(4));
6913 Inst = TmpInst;
6914 return true;
6915 }
6916 return false;
6917 }
6918
Jim Grosbach485e5622011-12-13 22:45:11 +00006919 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006920 case ARM::t2MOVsr:
6921 case ARM::t2MOVSsr: {
6922 // Which instruction to expand to depends on the CCOut operand and
6923 // whether we're in an IT block if the register operands are low
6924 // registers.
6925 bool isNarrow = false;
6926 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6927 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6928 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6929 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6930 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6931 isNarrow = true;
6932 MCInst TmpInst;
6933 unsigned newOpc;
6934 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6935 default: llvm_unreachable("unexpected opcode!");
6936 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6937 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6938 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6939 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6940 }
6941 TmpInst.setOpcode(newOpc);
6942 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6943 if (isNarrow)
6944 TmpInst.addOperand(MCOperand::CreateReg(
6945 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6946 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6947 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6948 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6949 TmpInst.addOperand(Inst.getOperand(5));
6950 if (!isNarrow)
6951 TmpInst.addOperand(MCOperand::CreateReg(
6952 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6953 Inst = TmpInst;
6954 return true;
6955 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006956 case ARM::t2MOVsi:
6957 case ARM::t2MOVSsi: {
6958 // Which instruction to expand to depends on the CCOut operand and
6959 // whether we're in an IT block if the register operands are low
6960 // registers.
6961 bool isNarrow = false;
6962 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6963 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6964 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6965 isNarrow = true;
6966 MCInst TmpInst;
6967 unsigned newOpc;
6968 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6969 default: llvm_unreachable("unexpected opcode!");
6970 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6971 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6972 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6973 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006974 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006975 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006976 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6977 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006978 TmpInst.setOpcode(newOpc);
6979 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6980 if (isNarrow)
6981 TmpInst.addOperand(MCOperand::CreateReg(
6982 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6983 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006984 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006985 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006986 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6987 TmpInst.addOperand(Inst.getOperand(4));
6988 if (!isNarrow)
6989 TmpInst.addOperand(MCOperand::CreateReg(
6990 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6991 Inst = TmpInst;
6992 return true;
6993 }
6994 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006995 case ARM::ASRr:
6996 case ARM::LSRr:
6997 case ARM::LSLr:
6998 case ARM::RORr: {
6999 ARM_AM::ShiftOpc ShiftTy;
7000 switch(Inst.getOpcode()) {
7001 default: llvm_unreachable("unexpected opcode!");
7002 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7003 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7004 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7005 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7006 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007007 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7008 MCInst TmpInst;
7009 TmpInst.setOpcode(ARM::MOVsr);
7010 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7011 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7012 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7013 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7014 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7015 TmpInst.addOperand(Inst.getOperand(4));
7016 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7017 Inst = TmpInst;
7018 return true;
7019 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007020 case ARM::ASRi:
7021 case ARM::LSRi:
7022 case ARM::LSLi:
7023 case ARM::RORi: {
7024 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007025 switch(Inst.getOpcode()) {
7026 default: llvm_unreachable("unexpected opcode!");
7027 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7028 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7029 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7030 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7031 }
7032 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007033 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007034 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007035 // A shift by 32 should be encoded as 0 when permitted
7036 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7037 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007038 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007039 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007040 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007041 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7042 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007043 if (Opc == ARM::MOVsi)
7044 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007045 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7046 TmpInst.addOperand(Inst.getOperand(4));
7047 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7048 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007049 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007050 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007051 case ARM::RRXi: {
7052 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7053 MCInst TmpInst;
7054 TmpInst.setOpcode(ARM::MOVsi);
7055 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7056 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7057 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7058 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7059 TmpInst.addOperand(Inst.getOperand(3));
7060 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7061 Inst = TmpInst;
7062 return true;
7063 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007064 case ARM::t2LDMIA_UPD: {
7065 // If this is a load of a single register, then we should use
7066 // a post-indexed LDR instruction instead, per the ARM ARM.
7067 if (Inst.getNumOperands() != 5)
7068 return false;
7069 MCInst TmpInst;
7070 TmpInst.setOpcode(ARM::t2LDR_POST);
7071 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7072 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7073 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7074 TmpInst.addOperand(MCOperand::CreateImm(4));
7075 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7076 TmpInst.addOperand(Inst.getOperand(3));
7077 Inst = TmpInst;
7078 return true;
7079 }
7080 case ARM::t2STMDB_UPD: {
7081 // If this is a store of a single register, then we should use
7082 // a pre-indexed STR instruction instead, per the ARM ARM.
7083 if (Inst.getNumOperands() != 5)
7084 return false;
7085 MCInst TmpInst;
7086 TmpInst.setOpcode(ARM::t2STR_PRE);
7087 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7088 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7089 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7090 TmpInst.addOperand(MCOperand::CreateImm(-4));
7091 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7092 TmpInst.addOperand(Inst.getOperand(3));
7093 Inst = TmpInst;
7094 return true;
7095 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007096 case ARM::LDMIA_UPD:
7097 // If this is a load of a single register via a 'pop', then we should use
7098 // a post-indexed LDR instruction instead, per the ARM ARM.
7099 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7100 Inst.getNumOperands() == 5) {
7101 MCInst TmpInst;
7102 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7103 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7104 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7105 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7106 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7107 TmpInst.addOperand(MCOperand::CreateImm(4));
7108 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7109 TmpInst.addOperand(Inst.getOperand(3));
7110 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007111 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007112 }
7113 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007114 case ARM::STMDB_UPD:
7115 // If this is a store of a single register via a 'push', then we should use
7116 // a pre-indexed STR instruction instead, per the ARM ARM.
7117 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7118 Inst.getNumOperands() == 5) {
7119 MCInst TmpInst;
7120 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7121 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7122 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7123 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7124 TmpInst.addOperand(MCOperand::CreateImm(-4));
7125 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7126 TmpInst.addOperand(Inst.getOperand(3));
7127 Inst = TmpInst;
7128 }
7129 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007130 case ARM::t2ADDri12:
7131 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7132 // mnemonic was used (not "addw"), encoding T3 is preferred.
7133 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7134 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7135 break;
7136 Inst.setOpcode(ARM::t2ADDri);
7137 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7138 break;
7139 case ARM::t2SUBri12:
7140 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7141 // mnemonic was used (not "subw"), encoding T3 is preferred.
7142 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7143 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7144 break;
7145 Inst.setOpcode(ARM::t2SUBri);
7146 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7147 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007148 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007149 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007150 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7151 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7152 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007153 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007154 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007155 return true;
7156 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007157 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007158 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007159 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007160 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7161 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7162 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007163 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007164 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007165 return true;
7166 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007167 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007168 case ARM::t2ADDri:
7169 case ARM::t2SUBri: {
7170 // If the destination and first source operand are the same, and
7171 // the flags are compatible with the current IT status, use encoding T2
7172 // instead of T3. For compatibility with the system 'as'. Make sure the
7173 // wide encoding wasn't explicit.
7174 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007175 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007176 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7177 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7178 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7179 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7180 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7181 break;
7182 MCInst TmpInst;
7183 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7184 ARM::tADDi8 : ARM::tSUBi8);
7185 TmpInst.addOperand(Inst.getOperand(0));
7186 TmpInst.addOperand(Inst.getOperand(5));
7187 TmpInst.addOperand(Inst.getOperand(0));
7188 TmpInst.addOperand(Inst.getOperand(2));
7189 TmpInst.addOperand(Inst.getOperand(3));
7190 TmpInst.addOperand(Inst.getOperand(4));
7191 Inst = TmpInst;
7192 return true;
7193 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007194 case ARM::t2ADDrr: {
7195 // If the destination and first source operand are the same, and
7196 // there's no setting of the flags, use encoding T2 instead of T3.
7197 // Note that this is only for ADD, not SUB. This mirrors the system
7198 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7199 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7200 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007201 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7202 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007203 break;
7204 MCInst TmpInst;
7205 TmpInst.setOpcode(ARM::tADDhirr);
7206 TmpInst.addOperand(Inst.getOperand(0));
7207 TmpInst.addOperand(Inst.getOperand(0));
7208 TmpInst.addOperand(Inst.getOperand(2));
7209 TmpInst.addOperand(Inst.getOperand(3));
7210 TmpInst.addOperand(Inst.getOperand(4));
7211 Inst = TmpInst;
7212 return true;
7213 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007214 case ARM::tADDrSP: {
7215 // If the non-SP source operand and the destination operand are not the
7216 // same, we need to use the 32-bit encoding if it's available.
7217 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7218 Inst.setOpcode(ARM::t2ADDrr);
7219 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7220 return true;
7221 }
7222 break;
7223 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007224 case ARM::tB:
7225 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007226 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007227 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007228 return true;
7229 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007230 break;
7231 case ARM::t2B:
7232 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007233 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007234 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007235 return true;
7236 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007237 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007238 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007239 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007240 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007241 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007242 return true;
7243 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007244 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007245 case ARM::tBcc:
7246 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007247 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007248 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007249 return true;
7250 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007251 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007252 case ARM::tLDMIA: {
7253 // If the register list contains any high registers, or if the writeback
7254 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7255 // instead if we're in Thumb2. Otherwise, this should have generated
7256 // an error in validateInstruction().
7257 unsigned Rn = Inst.getOperand(0).getReg();
7258 bool hasWritebackToken =
7259 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7260 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7261 bool listContainsBase;
7262 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7263 (!listContainsBase && !hasWritebackToken) ||
7264 (listContainsBase && hasWritebackToken)) {
7265 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7266 assert (isThumbTwo());
7267 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7268 // If we're switching to the updating version, we need to insert
7269 // the writeback tied operand.
7270 if (hasWritebackToken)
7271 Inst.insert(Inst.begin(),
7272 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007273 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007274 }
7275 break;
7276 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007277 case ARM::tSTMIA_UPD: {
7278 // If the register list contains any high registers, we need to use
7279 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7280 // should have generated an error in validateInstruction().
7281 unsigned Rn = Inst.getOperand(0).getReg();
7282 bool listContainsBase;
7283 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7284 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7285 assert (isThumbTwo());
7286 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007287 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007288 }
7289 break;
7290 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007291 case ARM::tPOP: {
7292 bool listContainsBase;
7293 // If the register list contains any high registers, we need to use
7294 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7295 // should have generated an error in validateInstruction().
7296 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007297 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007298 assert (isThumbTwo());
7299 Inst.setOpcode(ARM::t2LDMIA_UPD);
7300 // Add the base register and writeback operands.
7301 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7302 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007303 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007304 }
7305 case ARM::tPUSH: {
7306 bool listContainsBase;
7307 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007308 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007309 assert (isThumbTwo());
7310 Inst.setOpcode(ARM::t2STMDB_UPD);
7311 // Add the base register and writeback operands.
7312 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7313 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007314 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007315 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007316 case ARM::t2MOVi: {
7317 // If we can use the 16-bit encoding and the user didn't explicitly
7318 // request the 32-bit variant, transform it here.
7319 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007320 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007321 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7322 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7323 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007324 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7325 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7326 // The operands aren't in the same order for tMOVi8...
7327 MCInst TmpInst;
7328 TmpInst.setOpcode(ARM::tMOVi8);
7329 TmpInst.addOperand(Inst.getOperand(0));
7330 TmpInst.addOperand(Inst.getOperand(4));
7331 TmpInst.addOperand(Inst.getOperand(1));
7332 TmpInst.addOperand(Inst.getOperand(2));
7333 TmpInst.addOperand(Inst.getOperand(3));
7334 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007335 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007336 }
7337 break;
7338 }
7339 case ARM::t2MOVr: {
7340 // If we can use the 16-bit encoding and the user didn't explicitly
7341 // request the 32-bit variant, transform it here.
7342 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7343 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7344 Inst.getOperand(2).getImm() == ARMCC::AL &&
7345 Inst.getOperand(4).getReg() == ARM::CPSR &&
7346 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7347 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7348 // The operands aren't the same for tMOV[S]r... (no cc_out)
7349 MCInst TmpInst;
7350 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7351 TmpInst.addOperand(Inst.getOperand(0));
7352 TmpInst.addOperand(Inst.getOperand(1));
7353 TmpInst.addOperand(Inst.getOperand(2));
7354 TmpInst.addOperand(Inst.getOperand(3));
7355 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007356 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007357 }
7358 break;
7359 }
Jim Grosbach82213192011-09-19 20:29:33 +00007360 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007361 case ARM::t2SXTB:
7362 case ARM::t2UXTH:
7363 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007364 // If we can use the 16-bit encoding and the user didn't explicitly
7365 // request the 32-bit variant, transform it here.
7366 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7367 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7368 Inst.getOperand(2).getImm() == 0 &&
7369 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7370 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007371 unsigned NewOpc;
7372 switch (Inst.getOpcode()) {
7373 default: llvm_unreachable("Illegal opcode!");
7374 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7375 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7376 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7377 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7378 }
Jim Grosbach82213192011-09-19 20:29:33 +00007379 // The operands aren't the same for thumb1 (no rotate operand).
7380 MCInst TmpInst;
7381 TmpInst.setOpcode(NewOpc);
7382 TmpInst.addOperand(Inst.getOperand(0));
7383 TmpInst.addOperand(Inst.getOperand(1));
7384 TmpInst.addOperand(Inst.getOperand(3));
7385 TmpInst.addOperand(Inst.getOperand(4));
7386 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007387 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007388 }
7389 break;
7390 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007391 case ARM::MOVsi: {
7392 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007393 // rrx shifts and asr/lsr of #32 is encoded as 0
7394 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7395 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007396 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7397 // Shifting by zero is accepted as a vanilla 'MOVr'
7398 MCInst TmpInst;
7399 TmpInst.setOpcode(ARM::MOVr);
7400 TmpInst.addOperand(Inst.getOperand(0));
7401 TmpInst.addOperand(Inst.getOperand(1));
7402 TmpInst.addOperand(Inst.getOperand(3));
7403 TmpInst.addOperand(Inst.getOperand(4));
7404 TmpInst.addOperand(Inst.getOperand(5));
7405 Inst = TmpInst;
7406 return true;
7407 }
7408 return false;
7409 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007410 case ARM::ANDrsi:
7411 case ARM::ORRrsi:
7412 case ARM::EORrsi:
7413 case ARM::BICrsi:
7414 case ARM::SUBrsi:
7415 case ARM::ADDrsi: {
7416 unsigned newOpc;
7417 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7418 if (SOpc == ARM_AM::rrx) return false;
7419 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007420 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007421 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7422 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7423 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7424 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7425 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7426 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7427 }
7428 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007429 // The exception is for right shifts, where 0 == 32
7430 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7431 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007432 MCInst TmpInst;
7433 TmpInst.setOpcode(newOpc);
7434 TmpInst.addOperand(Inst.getOperand(0));
7435 TmpInst.addOperand(Inst.getOperand(1));
7436 TmpInst.addOperand(Inst.getOperand(2));
7437 TmpInst.addOperand(Inst.getOperand(4));
7438 TmpInst.addOperand(Inst.getOperand(5));
7439 TmpInst.addOperand(Inst.getOperand(6));
7440 Inst = TmpInst;
7441 return true;
7442 }
7443 return false;
7444 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007445 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007446 case ARM::t2IT: {
7447 // The mask bits for all but the first condition are represented as
7448 // the low bit of the condition code value implies 't'. We currently
7449 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007450 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007451 MCOperand &MO = Inst.getOperand(1);
7452 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007453 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007454 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007455 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007456 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007457 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007458 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007459 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007460
7461 // Set up the IT block state according to the IT instruction we just
7462 // matched.
7463 assert(!inITBlock() && "nested IT blocks?!");
7464 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7465 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7466 ITState.CurPosition = 0;
7467 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007468 break;
7469 }
Richard Bartona39625e2012-07-09 16:12:24 +00007470 case ARM::t2LSLrr:
7471 case ARM::t2LSRrr:
7472 case ARM::t2ASRrr:
7473 case ARM::t2SBCrr:
7474 case ARM::t2RORrr:
7475 case ARM::t2BICrr:
7476 {
Richard Bartond5660372012-07-09 16:14:28 +00007477 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007478 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7479 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7480 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007481 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7482 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007483 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7484 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7485 unsigned NewOpc;
7486 switch (Inst.getOpcode()) {
7487 default: llvm_unreachable("unexpected opcode");
7488 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7489 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7490 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7491 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7492 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7493 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7494 }
7495 MCInst TmpInst;
7496 TmpInst.setOpcode(NewOpc);
7497 TmpInst.addOperand(Inst.getOperand(0));
7498 TmpInst.addOperand(Inst.getOperand(5));
7499 TmpInst.addOperand(Inst.getOperand(1));
7500 TmpInst.addOperand(Inst.getOperand(2));
7501 TmpInst.addOperand(Inst.getOperand(3));
7502 TmpInst.addOperand(Inst.getOperand(4));
7503 Inst = TmpInst;
7504 return true;
7505 }
7506 return false;
7507 }
7508 case ARM::t2ANDrr:
7509 case ARM::t2EORrr:
7510 case ARM::t2ADCrr:
7511 case ARM::t2ORRrr:
7512 {
Richard Bartond5660372012-07-09 16:14:28 +00007513 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007514 // These instructions are special in that they are commutable, so shorter encodings
7515 // are available more often.
7516 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7517 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7518 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7519 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007520 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7521 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007522 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7523 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7524 unsigned NewOpc;
7525 switch (Inst.getOpcode()) {
7526 default: llvm_unreachable("unexpected opcode");
7527 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7528 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7529 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7530 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7531 }
7532 MCInst TmpInst;
7533 TmpInst.setOpcode(NewOpc);
7534 TmpInst.addOperand(Inst.getOperand(0));
7535 TmpInst.addOperand(Inst.getOperand(5));
7536 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7537 TmpInst.addOperand(Inst.getOperand(1));
7538 TmpInst.addOperand(Inst.getOperand(2));
7539 } else {
7540 TmpInst.addOperand(Inst.getOperand(2));
7541 TmpInst.addOperand(Inst.getOperand(1));
7542 }
7543 TmpInst.addOperand(Inst.getOperand(3));
7544 TmpInst.addOperand(Inst.getOperand(4));
7545 Inst = TmpInst;
7546 return true;
7547 }
7548 return false;
7549 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007550 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007551 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007552}
7553
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007554unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7555 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7556 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007557 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007558 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007559 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7560 assert(MCID.hasOptionalDef() &&
7561 "optionally flag setting instruction missing optional def operand");
7562 assert(MCID.NumOperands == Inst.getNumOperands() &&
7563 "operand count mismatch!");
7564 // Find the optional-def operand (cc_out).
7565 unsigned OpNo;
7566 for (OpNo = 0;
7567 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7568 ++OpNo)
7569 ;
7570 // If we're parsing Thumb1, reject it completely.
7571 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7572 return Match_MnemonicFail;
7573 // If we're parsing Thumb2, which form is legal depends on whether we're
7574 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007575 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7576 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007577 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007578 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7579 inITBlock())
7580 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007581 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007582 // Some high-register supporting Thumb1 encodings only allow both registers
7583 // to be from r0-r7 when in Thumb2.
7584 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7585 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7586 isARMLowRegister(Inst.getOperand(2).getReg()))
7587 return Match_RequiresThumb2;
7588 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007589 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007590 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7591 isARMLowRegister(Inst.getOperand(1).getReg()))
7592 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007593 return Match_Success;
7594}
7595
Jim Grosbach5117ef72012-04-24 22:40:08 +00007596static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007597bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007598MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007599 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007600 MCStreamer &Out, unsigned &ErrorInfo,
7601 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007602 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007603 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007604
Chad Rosier2f480a82012-10-12 22:53:36 +00007605 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007606 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007607 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007608 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007609 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007610 // Context sensitive operand constraints aren't handled by the matcher,
7611 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007612 if (validateInstruction(Inst, Operands)) {
7613 // Still progress the IT block, otherwise one wrong condition causes
7614 // nasty cascading errors.
7615 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007616 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007617 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007618
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007619 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007620 // encoding is selected. Loop on it while changes happen so the
7621 // individual transformations can chain off each other. E.g.,
7622 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7623 while (processInstruction(Inst, Operands))
7624 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007625
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007626 // Only move forward at the very end so that everything in validate
7627 // and process gets a consistent answer about whether we're in an IT
7628 // block.
7629 forwardITPosition();
7630
Jim Grosbach82f76d12012-01-25 19:52:01 +00007631 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7632 // doesn't actually encode.
7633 if (Inst.getOpcode() == ARM::ITasm)
7634 return false;
7635
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007636 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007637 Out.EmitInstruction(Inst);
7638 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007639 case Match_MissingFeature: {
7640 assert(ErrorInfo && "Unknown missing feature!");
7641 // Special case the error message for the very common case where only
7642 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7643 std::string Msg = "instruction requires:";
7644 unsigned Mask = 1;
7645 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7646 if (ErrorInfo & Mask) {
7647 Msg += " ";
7648 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7649 }
7650 Mask <<= 1;
7651 }
7652 return Error(IDLoc, Msg);
7653 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007654 case Match_InvalidOperand: {
7655 SMLoc ErrorLoc = IDLoc;
7656 if (ErrorInfo != ~0U) {
7657 if (ErrorInfo >= Operands.size())
7658 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007659
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007660 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7661 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7662 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007663
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007664 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007665 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007666 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007667 return Error(IDLoc, "invalid instruction",
7668 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007669 case Match_RequiresNotITBlock:
7670 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007671 case Match_RequiresITBlock:
7672 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007673 case Match_RequiresV6:
7674 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7675 case Match_RequiresThumb2:
7676 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007677 case Match_ImmRange0_4: {
7678 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7679 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7680 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7681 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007682 case Match_ImmRange0_15: {
7683 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7684 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7685 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7686 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007687 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007688
Eric Christopher91d7b902010-10-29 09:26:59 +00007689 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007690}
7691
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007692/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007693bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7694 StringRef IDVal = DirectiveID.getIdentifier();
7695 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007696 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007697 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007698 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007699 else if (IDVal == ".arm")
7700 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007701 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007702 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007703 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007704 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007705 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007706 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007707 else if (IDVal == ".unreq")
7708 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007709 else if (IDVal == ".arch")
7710 return parseDirectiveArch(DirectiveID.getLoc());
7711 else if (IDVal == ".eabi_attribute")
7712 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007713 else if (IDVal == ".fnstart")
7714 return parseDirectiveFnStart(DirectiveID.getLoc());
7715 else if (IDVal == ".fnend")
7716 return parseDirectiveFnEnd(DirectiveID.getLoc());
7717 else if (IDVal == ".cantunwind")
7718 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7719 else if (IDVal == ".personality")
7720 return parseDirectivePersonality(DirectiveID.getLoc());
7721 else if (IDVal == ".handlerdata")
7722 return parseDirectiveHandlerData(DirectiveID.getLoc());
7723 else if (IDVal == ".setfp")
7724 return parseDirectiveSetFP(DirectiveID.getLoc());
7725 else if (IDVal == ".pad")
7726 return parseDirectivePad(DirectiveID.getLoc());
7727 else if (IDVal == ".save")
7728 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7729 else if (IDVal == ".vsave")
7730 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007731 return true;
7732}
7733
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007734/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007735/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007736bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007737 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7738 for (;;) {
7739 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007740 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007741 return true;
7742
Eric Christopherbf7bc492013-01-09 03:52:05 +00007743 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007744
7745 if (getLexer().is(AsmToken::EndOfStatement))
7746 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007747
Kevin Enderbyccab3172009-09-15 00:27:25 +00007748 // FIXME: Improve diagnostic.
7749 if (getLexer().isNot(AsmToken::Comma))
7750 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007751 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007752 }
7753 }
7754
Sean Callanana83fd7d2010-01-19 20:27:46 +00007755 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007756 return false;
7757}
7758
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007759/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007760/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007761bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007762 if (getLexer().isNot(AsmToken::EndOfStatement))
7763 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007764 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007765
Tim Northovera2292d02013-06-10 23:20:58 +00007766 if (!hasThumb())
7767 return Error(L, "target does not support Thumb mode");
7768
Jim Grosbach7f882392011-12-07 18:04:19 +00007769 if (!isThumb())
7770 SwitchMode();
7771 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7772 return false;
7773}
7774
7775/// parseDirectiveARM
7776/// ::= .arm
7777bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7778 if (getLexer().isNot(AsmToken::EndOfStatement))
7779 return Error(L, "unexpected token in directive");
7780 Parser.Lex();
7781
Tim Northovera2292d02013-06-10 23:20:58 +00007782 if (!hasARM())
7783 return Error(L, "target does not support ARM mode");
7784
Jim Grosbach7f882392011-12-07 18:04:19 +00007785 if (isThumb())
7786 SwitchMode();
7787 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007788 return false;
7789}
7790
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007791/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007792/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007793bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007794 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7795 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007796 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007797 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007798
Jim Grosbach1152cc02011-12-21 22:30:16 +00007799 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007800 // ELF doesn't
7801 if (isMachO) {
7802 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007803 if (Tok.isNot(AsmToken::EndOfStatement)) {
7804 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7805 return Error(L, "unexpected token in .thumb_func directive");
7806 Name = Tok.getIdentifier();
7807 Parser.Lex(); // Consume the identifier token.
7808 needFuncName = false;
7809 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007810 }
7811
Jim Grosbach1152cc02011-12-21 22:30:16 +00007812 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007813 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007814
7815 // Eat the end of statement and any blank lines that follow.
7816 while (getLexer().is(AsmToken::EndOfStatement))
7817 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007818
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007819 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007820 // We really should be checking the next symbol definition even if there's
7821 // stuff in between.
7822 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007823 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007824 }
7825
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007826 // Mark symbol as a thumb symbol.
7827 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7828 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007829 return false;
7830}
7831
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007832/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007833/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007834bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007835 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007836 if (Tok.isNot(AsmToken::Identifier))
7837 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007838 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007839 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007840 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007841 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007842 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007843 else
7844 return Error(L, "unrecognized syntax mode in .syntax directive");
7845
7846 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007847 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007848 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007849
7850 // TODO tell the MC streamer the mode
7851 // getParser().getStreamer().Emit???();
7852 return false;
7853}
7854
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007855/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007856/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007857bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007858 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007859 if (Tok.isNot(AsmToken::Integer))
7860 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007861 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007862 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007863 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007864 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007865 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007866 else
7867 return Error(L, "invalid operand to .code directive");
7868
7869 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007870 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007871 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007872
Evan Cheng284b4672011-07-08 22:36:29 +00007873 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007874 if (!hasThumb())
7875 return Error(L, "target does not support Thumb mode");
7876
Jim Grosbachf471ac32011-09-06 18:46:23 +00007877 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007878 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007879 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007880 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007881 if (!hasARM())
7882 return Error(L, "target does not support ARM mode");
7883
Jim Grosbachf471ac32011-09-06 18:46:23 +00007884 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007885 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007886 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007887 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007888
Kevin Enderby146dcf22009-10-15 20:48:48 +00007889 return false;
7890}
7891
Jim Grosbachab5830e2011-12-14 02:16:11 +00007892/// parseDirectiveReq
7893/// ::= name .req registername
7894bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7895 Parser.Lex(); // Eat the '.req' token.
7896 unsigned Reg;
7897 SMLoc SRegLoc, ERegLoc;
7898 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007899 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007900 return Error(SRegLoc, "register name expected");
7901 }
7902
7903 // Shouldn't be anything else.
7904 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007905 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007906 return Error(Parser.getTok().getLoc(),
7907 "unexpected input in .req directive.");
7908 }
7909
7910 Parser.Lex(); // Consume the EndOfStatement
7911
7912 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7913 return Error(SRegLoc, "redefinition of '" + Name +
7914 "' does not match original.");
7915
7916 return false;
7917}
7918
7919/// parseDirectiveUneq
7920/// ::= .unreq registername
7921bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7922 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007923 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007924 return Error(L, "unexpected input in .unreq directive.");
7925 }
7926 RegisterReqs.erase(Parser.getTok().getIdentifier());
7927 Parser.Lex(); // Eat the identifier.
7928 return false;
7929}
7930
Jason W Kim135d2442011-12-20 17:38:12 +00007931/// parseDirectiveArch
7932/// ::= .arch token
7933bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7934 return true;
7935}
7936
7937/// parseDirectiveEabiAttr
7938/// ::= .eabi_attribute int, int
7939bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7940 return true;
7941}
7942
Logan Chien4ea23b52013-05-10 16:17:24 +00007943/// parseDirectiveFnStart
7944/// ::= .fnstart
7945bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7946 if (FnStartLoc.isValid()) {
7947 Error(L, ".fnstart starts before the end of previous one");
7948 Error(FnStartLoc, "previous .fnstart starts here");
7949 return true;
7950 }
7951
7952 FnStartLoc = L;
7953 getParser().getStreamer().EmitFnStart();
7954 return false;
7955}
7956
7957/// parseDirectiveFnEnd
7958/// ::= .fnend
7959bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7960 // Check the ordering of unwind directives
7961 if (!FnStartLoc.isValid())
7962 return Error(L, ".fnstart must precede .fnend directive");
7963
7964 // Reset the unwind directives parser state
7965 resetUnwindDirectiveParserState();
7966
7967 getParser().getStreamer().EmitFnEnd();
7968 return false;
7969}
7970
7971/// parseDirectiveCantUnwind
7972/// ::= .cantunwind
7973bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7974 // Check the ordering of unwind directives
7975 CantUnwindLoc = L;
7976 if (!FnStartLoc.isValid())
7977 return Error(L, ".fnstart must precede .cantunwind directive");
7978 if (HandlerDataLoc.isValid()) {
7979 Error(L, ".cantunwind can't be used with .handlerdata directive");
7980 Error(HandlerDataLoc, ".handlerdata was specified here");
7981 return true;
7982 }
7983 if (PersonalityLoc.isValid()) {
7984 Error(L, ".cantunwind can't be used with .personality directive");
7985 Error(PersonalityLoc, ".personality was specified here");
7986 return true;
7987 }
7988
7989 getParser().getStreamer().EmitCantUnwind();
7990 return false;
7991}
7992
7993/// parseDirectivePersonality
7994/// ::= .personality name
7995bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7996 // Check the ordering of unwind directives
7997 PersonalityLoc = L;
7998 if (!FnStartLoc.isValid())
7999 return Error(L, ".fnstart must precede .personality directive");
8000 if (CantUnwindLoc.isValid()) {
8001 Error(L, ".personality can't be used with .cantunwind directive");
8002 Error(CantUnwindLoc, ".cantunwind was specified here");
8003 return true;
8004 }
8005 if (HandlerDataLoc.isValid()) {
8006 Error(L, ".personality must precede .handlerdata directive");
8007 Error(HandlerDataLoc, ".handlerdata was specified here");
8008 return true;
8009 }
8010
8011 // Parse the name of the personality routine
8012 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8013 Parser.eatToEndOfStatement();
8014 return Error(L, "unexpected input in .personality directive.");
8015 }
8016 StringRef Name(Parser.getTok().getIdentifier());
8017 Parser.Lex();
8018
8019 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8020 getParser().getStreamer().EmitPersonality(PR);
8021 return false;
8022}
8023
8024/// parseDirectiveHandlerData
8025/// ::= .handlerdata
8026bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8027 // Check the ordering of unwind directives
8028 HandlerDataLoc = L;
8029 if (!FnStartLoc.isValid())
8030 return Error(L, ".fnstart must precede .personality directive");
8031 if (CantUnwindLoc.isValid()) {
8032 Error(L, ".handlerdata can't be used with .cantunwind directive");
8033 Error(CantUnwindLoc, ".cantunwind was specified here");
8034 return true;
8035 }
8036
8037 getParser().getStreamer().EmitHandlerData();
8038 return false;
8039}
8040
8041/// parseDirectiveSetFP
8042/// ::= .setfp fpreg, spreg [, offset]
8043bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8044 // Check the ordering of unwind directives
8045 if (!FnStartLoc.isValid())
8046 return Error(L, ".fnstart must precede .setfp directive");
8047 if (HandlerDataLoc.isValid())
8048 return Error(L, ".setfp must precede .handlerdata directive");
8049
8050 // Parse fpreg
8051 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8052 int NewFPReg = tryParseRegister();
8053 if (NewFPReg == -1)
8054 return Error(NewFPRegLoc, "frame pointer register expected");
8055
8056 // Consume comma
8057 if (!Parser.getTok().is(AsmToken::Comma))
8058 return Error(Parser.getTok().getLoc(), "comma expected");
8059 Parser.Lex(); // skip comma
8060
8061 // Parse spreg
8062 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8063 int NewSPReg = tryParseRegister();
8064 if (NewSPReg == -1)
8065 return Error(NewSPRegLoc, "stack pointer register expected");
8066
8067 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8068 return Error(NewSPRegLoc,
8069 "register should be either $sp or the latest fp register");
8070
8071 // Update the frame pointer register
8072 FPReg = NewFPReg;
8073
8074 // Parse offset
8075 int64_t Offset = 0;
8076 if (Parser.getTok().is(AsmToken::Comma)) {
8077 Parser.Lex(); // skip comma
8078
8079 if (Parser.getTok().isNot(AsmToken::Hash) &&
8080 Parser.getTok().isNot(AsmToken::Dollar)) {
8081 return Error(Parser.getTok().getLoc(), "'#' expected");
8082 }
8083 Parser.Lex(); // skip hash token.
8084
8085 const MCExpr *OffsetExpr;
8086 SMLoc ExLoc = Parser.getTok().getLoc();
8087 SMLoc EndLoc;
8088 if (getParser().parseExpression(OffsetExpr, EndLoc))
8089 return Error(ExLoc, "malformed setfp offset");
8090 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8091 if (!CE)
8092 return Error(ExLoc, "setfp offset must be an immediate");
8093
8094 Offset = CE->getValue();
8095 }
8096
8097 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8098 static_cast<unsigned>(NewSPReg),
8099 Offset);
8100 return false;
8101}
8102
8103/// parseDirective
8104/// ::= .pad offset
8105bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8106 // Check the ordering of unwind directives
8107 if (!FnStartLoc.isValid())
8108 return Error(L, ".fnstart must precede .pad directive");
8109 if (HandlerDataLoc.isValid())
8110 return Error(L, ".pad must precede .handlerdata directive");
8111
8112 // Parse the offset
8113 if (Parser.getTok().isNot(AsmToken::Hash) &&
8114 Parser.getTok().isNot(AsmToken::Dollar)) {
8115 return Error(Parser.getTok().getLoc(), "'#' expected");
8116 }
8117 Parser.Lex(); // skip hash token.
8118
8119 const MCExpr *OffsetExpr;
8120 SMLoc ExLoc = Parser.getTok().getLoc();
8121 SMLoc EndLoc;
8122 if (getParser().parseExpression(OffsetExpr, EndLoc))
8123 return Error(ExLoc, "malformed pad offset");
8124 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8125 if (!CE)
8126 return Error(ExLoc, "pad offset must be an immediate");
8127
8128 getParser().getStreamer().EmitPad(CE->getValue());
8129 return false;
8130}
8131
8132/// parseDirectiveRegSave
8133/// ::= .save { registers }
8134/// ::= .vsave { registers }
8135bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8136 // Check the ordering of unwind directives
8137 if (!FnStartLoc.isValid())
8138 return Error(L, ".fnstart must precede .save or .vsave directives");
8139 if (HandlerDataLoc.isValid())
8140 return Error(L, ".save or .vsave must precede .handlerdata directive");
8141
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008142 // RAII object to make sure parsed operands are deleted.
8143 struct CleanupObject {
8144 SmallVector<MCParsedAsmOperand *, 1> Operands;
8145 ~CleanupObject() {
8146 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8147 delete Operands[I];
8148 }
8149 } CO;
8150
Logan Chien4ea23b52013-05-10 16:17:24 +00008151 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008152 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008153 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008154 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008155 if (!IsVector && !Op->isRegList())
8156 return Error(L, ".save expects GPR registers");
8157 if (IsVector && !Op->isDPRRegList())
8158 return Error(L, ".vsave expects DPR registers");
8159
8160 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8161 return false;
8162}
8163
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008164/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008165extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008166 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8167 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008168}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008169
Chris Lattner3e4582a2010-09-06 19:11:01 +00008170#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008171#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008172#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008173#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008174
8175// Define this matcher function after the auto-generated include so we
8176// have the match class enum definitions.
8177unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8178 unsigned Kind) {
8179 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8180 // If the kind is a token for a literal immediate, check if our asm
8181 // operand matches. This is for InstAliases which have a fixed-value
8182 // immediate in the syntax.
8183 if (Kind == MCK__35_0 && Op->isImm()) {
8184 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8185 if (!CE)
8186 return Match_InvalidOperand;
8187 if (CE->getValue() == 0)
8188 return Match_Success;
8189 }
8190 return Match_InvalidOperand;
8191}