blob: 6b42239747e543602fb60945c6bdfb4ce89d9278 [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"
21#include "llvm/MC/MCContext.h"
22#include "llvm/MC/MCExpr.h"
23#include "llvm/MC/MCInst.h"
24#include "llvm/MC/MCInstrDesc.h"
25#include "llvm/MC/MCParser/MCAsmLexer.h"
26#include "llvm/MC/MCParser/MCAsmParser.h"
27#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
28#include "llvm/MC/MCRegisterInfo.h"
29#include "llvm/MC/MCStreamer.h"
30#include "llvm/MC/MCSubtargetInfo.h"
31#include "llvm/Support/MathExtras.h"
32#include "llvm/Support/SourceMgr.h"
33#include "llvm/Support/TargetRegistry.h"
34#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000035
Kevin Enderbyccab3172009-09-15 00:27:25 +000036using namespace llvm;
37
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000038namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000039
40class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000041
Jim Grosbach04945c42011-12-02 00:35:16 +000042enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000043
Evan Cheng11424442011-07-26 00:24:13 +000044class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000045 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000046 MCAsmParser &Parser;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000047 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000048
Jim Grosbachab5830e2011-12-14 02:16:11 +000049 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
51
Jim Grosbached16ec42011-08-29 22:24:09 +000052 struct {
53 ARMCC::CondCodes Cond; // Condition for IT block.
54 unsigned Mask:4; // Condition mask for instructions.
55 // Starting at first 1 (from lsb).
56 // '1' condition as indicated in IT.
57 // '0' inverse of condition (else).
58 // Count of instructions in IT block is
59 // 4 - trailingzeroes(mask)
60
61 bool FirstCond; // Explicit flag for when we're parsing the
62 // First instruction in the IT block. It's
63 // implied in the mask, so needs special
64 // handling.
65
66 unsigned CurPosition; // Current position in parsing of IT
67 // block. In range [0,3]. Initialized
68 // according to count of instructions in block.
69 // ~0U if no active IT block.
70 } ITState;
71 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000072 void forwardITPosition() {
73 if (!inITBlock()) return;
74 // Move to the next instruction in the IT block, if there is one. If not,
75 // mark the block as done.
76 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
77 if (++ITState.CurPosition == 5 - TZ)
78 ITState.CurPosition = ~0U; // Done with the IT block after this.
79 }
Jim Grosbached16ec42011-08-29 22:24:09 +000080
81
Kevin Enderbyccab3172009-09-15 00:27:25 +000082 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +000083 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
84
Benjamin Kramer673824b2012-04-15 17:04:27 +000085 bool Warning(SMLoc L, const Twine &Msg,
86 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
87 return Parser.Warning(L, Msg, Ranges);
88 }
89 bool Error(SMLoc L, const Twine &Msg,
90 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
91 return Parser.Error(L, Msg, Ranges);
92 }
Kevin Enderbyccab3172009-09-15 00:27:25 +000093
Jim Grosbacheab1c0d2011-07-26 17:10:22 +000094 int tryParseRegister();
95 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +000096 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +000097 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +000098 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +000099 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
100 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000101 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
102 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000103 bool parseDirectiveWord(unsigned Size, SMLoc L);
104 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000105 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000106 bool parseDirectiveThumbFunc(SMLoc L);
107 bool parseDirectiveCode(SMLoc L);
108 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000109 bool parseDirectiveReq(StringRef Name, SMLoc L);
110 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000111 bool parseDirectiveArch(SMLoc L);
112 bool parseDirectiveEabiAttr(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000113
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000115 bool &CarrySetting, unsigned &ProcessorIMod,
116 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000117 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000118 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000119
Evan Cheng4d1ca962011-07-08 01:53:10 +0000120 bool isThumb() const {
121 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000122 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000123 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000124 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000125 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000126 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000127 bool isThumbTwo() const {
128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
129 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000130 bool hasV6Ops() const {
131 return STI.getFeatureBits() & ARM::HasV6Ops;
132 }
James Molloy21efa7d2011-09-28 14:21:38 +0000133 bool hasV7Ops() const {
134 return STI.getFeatureBits() & ARM::HasV7Ops;
135 }
Evan Cheng284b4672011-07-08 22:36:29 +0000136 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000137 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
138 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000139 }
James Molloy21efa7d2011-09-28 14:21:38 +0000140 bool isMClass() const {
141 return STI.getFeatureBits() & ARM::FeatureMClass;
142 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000143
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000144 /// @name Auto-generated Match Functions
145 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000146
Chris Lattner3e4582a2010-09-06 19:11:01 +0000147#define GET_ASSEMBLER_HEADER
148#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000149
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000150 /// }
151
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000152 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000153 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000154 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000155 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000156 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000157 OperandMatchResultTy parseCoprocOptionOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000159 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000160 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000161 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000162 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000163 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000164 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000165 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
166 StringRef Op, int Low, int High);
167 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
168 return parsePKHImm(O, "lsl", 0, 31);
169 }
170 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
171 return parsePKHImm(O, "asr", 1, 32);
172 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000173 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000174 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000175 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000176 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000177 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000178 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000179 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000180 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach04945c42011-12-02 00:35:16 +0000181 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000182
183 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000184 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
185 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
186 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +0000187 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000188 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +0000189 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000190 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000191 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000192 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +0000193 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000194 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +0000195 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000196 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000197 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000198 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +0000199 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000200 void cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000201 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000202 void cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000203 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000204 void cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000205 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000206 void cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000207 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000208 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
209 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
210 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +0000211 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000212 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000213 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000214 void cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000215 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000216 void cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000217 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000218 void cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000219 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000220 void cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000221 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000222 bool validateInstruction(MCInst &Inst,
223 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000224 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000226 bool shouldOmitCCOutOperand(StringRef Mnemonic,
227 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000228
Kevin Enderbyccab3172009-09-15 00:27:25 +0000229public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000230 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000231 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000232 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000233 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000234 Match_RequiresThumb2,
235#define GET_OPERAND_DIAGNOSTIC_TYPES
236#include "ARMGenAsmMatcher.inc"
237
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000238 };
239
Evan Cheng91111d22011-07-09 05:47:46 +0000240 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Evan Cheng11424442011-07-26 00:24:13 +0000241 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000242 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000243
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000244 // Cache the MCRegisterInfo.
245 MRI = &getContext().getRegisterInfo();
246
Evan Cheng4d1ca962011-07-08 01:53:10 +0000247 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000248 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000249
250 // Not in an ITBlock to start with.
251 ITState.CurPosition = ~0U;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000252 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000253
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000254 // Implementation of the MCTargetAsmParser interface:
255 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000256 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
257 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000258 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000259 bool ParseDirective(AsmToken DirectiveID);
260
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000261 unsigned checkTargetMatchPredicate(MCInst &Inst);
262
Chad Rosier49963552012-10-13 00:26:04 +0000263 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000264 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000265 MCStreamer &Out, unsigned &ErrorInfo,
266 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000267};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000268} // end anonymous namespace
269
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000270namespace {
271
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000272/// ARMOperand - Instances of this class represent a parsed ARM machine
273/// instruction.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000274class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000275 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000276 k_CondCode,
277 k_CCOut,
278 k_ITCondMask,
279 k_CoprocNum,
280 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000281 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000282 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000283 k_MemBarrierOpt,
284 k_Memory,
285 k_PostIndexRegister,
286 k_MSRMask,
287 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000288 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000289 k_Register,
290 k_RegisterList,
291 k_DPRRegisterList,
292 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000293 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000294 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000295 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000296 k_ShiftedRegister,
297 k_ShiftedImmediate,
298 k_ShifterImmediate,
299 k_RotateImmediate,
300 k_BitfieldDescriptor,
301 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000302 } Kind;
303
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000304 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000305 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000306
307 union {
308 struct {
Daniel Dunbard8042b72010-08-11 06:36:53 +0000309 ARMCC::CondCodes Val;
310 } CC;
311
312 struct {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000313 unsigned Val;
314 } Cop;
315
316 struct {
Jim Grosbach48399582011-10-12 17:34:41 +0000317 unsigned Val;
318 } CoprocOption;
319
320 struct {
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000321 unsigned Mask:4;
322 } ITMask;
323
324 struct {
325 ARM_MB::MemBOpt Val;
326 } MBOpt;
327
328 struct {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000329 ARM_PROC::IFlags Val;
330 } IFlags;
331
332 struct {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000333 unsigned Val;
334 } MMask;
335
336 struct {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000337 const char *Data;
338 unsigned Length;
339 } Tok;
340
341 struct {
342 unsigned RegNum;
343 } Reg;
344
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000345 // A vector register list is a sequential list of 1 to 4 registers.
346 struct {
347 unsigned RegNum;
348 unsigned Count;
Jim Grosbach04945c42011-12-02 00:35:16 +0000349 unsigned LaneIndex;
Jim Grosbach2f50e922011-12-15 21:44:33 +0000350 bool isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000351 } VectorList;
352
Bill Wendlingb884a8e2010-11-06 22:19:43 +0000353 struct {
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000354 unsigned Val;
355 } VectorIndex;
356
357 struct {
Kevin Enderbyf5079942009-10-13 22:19:02 +0000358 const MCExpr *Val;
359 } Imm;
Jim Grosbach624bcc72010-10-29 14:46:02 +0000360
Daniel Dunbar2be732a2011-01-10 15:26:21 +0000361 /// Combined record for all forms of ARM address expressions.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000362 struct {
363 unsigned BaseRegNum;
Jim Grosbachd3595712011-08-03 23:50:40 +0000364 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
365 // was specified.
366 const MCConstantExpr *OffsetImm; // Offset immediate value
367 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
368 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbacha95ec992011-10-11 17:29:55 +0000369 unsigned ShiftImm; // shift for OffsetReg.
370 unsigned Alignment; // 0 = no alignment specified
Jim Grosbachcef98cd2011-12-19 18:31:43 +0000371 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbachd3595712011-08-03 23:50:40 +0000372 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbach871dff72011-10-11 15:59:20 +0000373 } Memory;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000374
375 struct {
Jim Grosbachd3595712011-08-03 23:50:40 +0000376 unsigned RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +0000377 bool isAdd;
378 ARM_AM::ShiftOpc ShiftTy;
379 unsigned ShiftImm;
Jim Grosbachd3595712011-08-03 23:50:40 +0000380 } PostIdxReg;
381
382 struct {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000383 bool isASR;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000384 unsigned Imm;
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000385 } ShifterImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000386 struct {
387 ARM_AM::ShiftOpc ShiftTy;
388 unsigned SrcReg;
389 unsigned ShiftReg;
390 unsigned ShiftImm;
Jim Grosbachac798e12011-07-25 20:49:51 +0000391 } RegShiftedReg;
Owen Andersonb595ed02011-07-21 18:54:16 +0000392 struct {
393 ARM_AM::ShiftOpc ShiftTy;
394 unsigned SrcReg;
395 unsigned ShiftImm;
Jim Grosbachac798e12011-07-25 20:49:51 +0000396 } RegShiftedImm;
Jim Grosbach833b9d32011-07-27 20:15:40 +0000397 struct {
398 unsigned Imm;
399 } RotImm;
Jim Grosbach864b6092011-07-28 21:34:26 +0000400 struct {
401 unsigned LSB;
402 unsigned Width;
403 } Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000404 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000405
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000406 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
407public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000408 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
409 Kind = o.Kind;
410 StartLoc = o.StartLoc;
411 EndLoc = o.EndLoc;
412 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000413 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000414 CC = o.CC;
415 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000416 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000417 ITMask = o.ITMask;
418 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000419 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000420 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000421 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000422 case k_CCOut:
423 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000424 Reg = o.Reg;
425 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000426 case k_RegisterList:
427 case k_DPRRegisterList:
428 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000429 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000430 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000431 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000432 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000433 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000434 VectorList = o.VectorList;
435 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000436 case k_CoprocNum:
437 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000438 Cop = o.Cop;
439 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000440 case k_CoprocOption:
441 CoprocOption = o.CoprocOption;
442 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000443 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000444 Imm = o.Imm;
445 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000446 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000447 MBOpt = o.MBOpt;
448 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000449 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000450 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000451 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000452 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000453 PostIdxReg = o.PostIdxReg;
454 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000455 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000456 MMask = o.MMask;
457 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000458 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000459 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000460 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000461 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000462 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000463 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000464 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000465 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000466 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000467 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000468 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000469 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000470 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000471 RotImm = o.RotImm;
472 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000473 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000474 Bitfield = o.Bitfield;
475 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000476 case k_VectorIndex:
477 VectorIndex = o.VectorIndex;
478 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000479 }
480 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000481
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000482 /// getStartLoc - Get the location of the first token of this operand.
483 SMLoc getStartLoc() const { return StartLoc; }
484 /// getEndLoc - Get the location of the last token of this operand.
485 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000486 /// getLocRange - Get the range between the first and last token of this
487 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000488 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
489
Daniel Dunbard8042b72010-08-11 06:36:53 +0000490 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000491 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000492 return CC.Val;
493 }
494
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000495 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000496 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000497 return Cop.Val;
498 }
499
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000500 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000501 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000502 return StringRef(Tok.Data, Tok.Length);
503 }
504
505 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000506 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000507 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000508 }
509
Bill Wendlingbed94652010-11-09 23:28:44 +0000510 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000511 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
512 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000513 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000514 }
515
Kevin Enderbyf5079942009-10-13 22:19:02 +0000516 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000517 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000518 return Imm.Val;
519 }
520
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000521 unsigned getVectorIndex() const {
522 assert(Kind == k_VectorIndex && "Invalid access!");
523 return VectorIndex.Val;
524 }
525
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000526 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000527 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000528 return MBOpt.Val;
529 }
530
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000531 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000532 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000533 return IFlags.Val;
534 }
535
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000536 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000537 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000538 return MMask.Val;
539 }
540
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000541 bool isCoprocNum() const { return Kind == k_CoprocNum; }
542 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000543 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000544 bool isCondCode() const { return Kind == k_CondCode; }
545 bool isCCOut() const { return Kind == k_CCOut; }
546 bool isITMask() const { return Kind == k_ITCondMask; }
547 bool isITCondCode() const { return Kind == k_CondCode; }
548 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000549 bool isFPImm() const {
550 if (!isImm()) return false;
551 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
552 if (!CE) return false;
553 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
554 return Val != -1;
555 }
Jim Grosbachea231912011-12-22 22:19:05 +0000556 bool isFBits16() const {
557 if (!isImm()) return false;
558 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
559 if (!CE) return false;
560 int64_t Value = CE->getValue();
561 return Value >= 0 && Value <= 16;
562 }
563 bool isFBits32() const {
564 if (!isImm()) return false;
565 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
566 if (!CE) return false;
567 int64_t Value = CE->getValue();
568 return Value >= 1 && Value <= 32;
569 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000570 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000571 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000572 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
573 if (!CE) return false;
574 int64_t Value = CE->getValue();
575 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
576 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000577 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000578 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000579 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
580 if (!CE) return false;
581 int64_t Value = CE->getValue();
582 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
583 }
584 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000585 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000586 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
587 if (!CE) return false;
588 int64_t Value = CE->getValue();
589 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
590 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000591 bool isImm0_508s4Neg() const {
592 if (!isImm()) return false;
593 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
594 if (!CE) return false;
595 int64_t Value = -CE->getValue();
596 // explicitly exclude zero. we want that to use the normal 0_508 version.
597 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
598 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000599 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000600 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000601 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
602 if (!CE) return false;
603 int64_t Value = CE->getValue();
604 return Value >= 0 && Value < 256;
605 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000606 bool isImm0_4095() const {
607 if (!isImm()) return false;
608 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
609 if (!CE) return false;
610 int64_t Value = CE->getValue();
611 return Value >= 0 && Value < 4096;
612 }
613 bool isImm0_4095Neg() const {
614 if (!isImm()) return false;
615 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
616 if (!CE) return false;
617 int64_t Value = -CE->getValue();
618 return Value > 0 && Value < 4096;
619 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000620 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000621 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000622 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
623 if (!CE) return false;
624 int64_t Value = CE->getValue();
625 return Value >= 0 && Value < 2;
626 }
627 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000628 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
630 if (!CE) return false;
631 int64_t Value = CE->getValue();
632 return Value >= 0 && Value < 4;
633 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000634 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000635 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000636 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
637 if (!CE) return false;
638 int64_t Value = CE->getValue();
639 return Value >= 0 && Value < 8;
640 }
641 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000642 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000643 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
644 if (!CE) return false;
645 int64_t Value = CE->getValue();
646 return Value >= 0 && Value < 16;
647 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000648 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000649 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000650 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
651 if (!CE) return false;
652 int64_t Value = CE->getValue();
653 return Value >= 0 && Value < 32;
654 }
Jim Grosbach00326402011-12-08 01:30:04 +0000655 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000656 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000657 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
658 if (!CE) return false;
659 int64_t Value = CE->getValue();
660 return Value >= 0 && Value < 64;
661 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000662 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000663 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
665 if (!CE) return false;
666 int64_t Value = CE->getValue();
667 return Value == 8;
668 }
669 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000670 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
672 if (!CE) return false;
673 int64_t Value = CE->getValue();
674 return Value == 16;
675 }
676 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000677 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
679 if (!CE) return false;
680 int64_t Value = CE->getValue();
681 return Value == 32;
682 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000683 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000684 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000685 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
686 if (!CE) return false;
687 int64_t Value = CE->getValue();
688 return Value > 0 && Value <= 8;
689 }
690 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000691 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000692 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
693 if (!CE) return false;
694 int64_t Value = CE->getValue();
695 return Value > 0 && Value <= 16;
696 }
697 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000698 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
700 if (!CE) return false;
701 int64_t Value = CE->getValue();
702 return Value > 0 && Value <= 32;
703 }
704 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000705 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
707 if (!CE) return false;
708 int64_t Value = CE->getValue();
709 return Value > 0 && Value <= 64;
710 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000711 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000712 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
714 if (!CE) return false;
715 int64_t Value = CE->getValue();
716 return Value > 0 && Value < 8;
717 }
718 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000719 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
721 if (!CE) return false;
722 int64_t Value = CE->getValue();
723 return Value > 0 && Value < 16;
724 }
725 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000726 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
728 if (!CE) return false;
729 int64_t Value = CE->getValue();
730 return Value > 0 && Value < 32;
731 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000732 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000733 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
735 if (!CE) return false;
736 int64_t Value = CE->getValue();
737 return Value > 0 && Value < 17;
738 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000739 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000740 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000741 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
742 if (!CE) return false;
743 int64_t Value = CE->getValue();
744 return Value > 0 && Value < 33;
745 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000746 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000747 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
749 if (!CE) return false;
750 int64_t Value = CE->getValue();
751 return Value >= 0 && Value < 33;
752 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000753 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000754 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
756 if (!CE) return false;
757 int64_t Value = CE->getValue();
758 return Value >= 0 && Value < 65536;
759 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000760 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000761 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
763 // If it's not a constant expression, it'll generate a fixup and be
764 // handled later.
765 if (!CE) return true;
766 int64_t Value = CE->getValue();
767 return Value >= 0 && Value < 65536;
768 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000769 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000770 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000771 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
772 if (!CE) return false;
773 int64_t Value = CE->getValue();
774 return Value >= 0 && Value <= 0xffffff;
775 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000776 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000777 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
779 if (!CE) return false;
780 int64_t Value = CE->getValue();
781 return Value > 0 && Value < 33;
782 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000783 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000784 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
786 if (!CE) return false;
787 int64_t Value = CE->getValue();
788 return Value >= 0 && Value < 32;
789 }
790 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000791 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
793 if (!CE) return false;
794 int64_t Value = CE->getValue();
795 return Value > 0 && Value <= 32;
796 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000797 bool isAdrLabel() const {
798 // If we have an immediate that's not a constant, treat it as a label
799 // reference needing a fixup. If it is a constant, but it can't fit
800 // into shift immediate encoding, we reject it.
801 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
802 else return (isARMSOImm() || isARMSOImmNeg());
803 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000804 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000805 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
807 if (!CE) return false;
808 int64_t Value = CE->getValue();
809 return ARM_AM::getSOImmVal(Value) != -1;
810 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000811 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000812 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000813 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
814 if (!CE) return false;
815 int64_t Value = CE->getValue();
816 return ARM_AM::getSOImmVal(~Value) != -1;
817 }
Jim Grosbach30506252011-12-08 00:31:07 +0000818 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000819 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000823 // Only use this when not representable as a plain so_imm.
824 return ARM_AM::getSOImmVal(Value) == -1 &&
825 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000826 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000827 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000828 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000829 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
830 if (!CE) return false;
831 int64_t Value = CE->getValue();
832 return ARM_AM::getT2SOImmVal(Value) != -1;
833 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000834 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000835 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000836 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
837 if (!CE) return false;
838 int64_t Value = CE->getValue();
839 return ARM_AM::getT2SOImmVal(~Value) != -1;
840 }
Jim Grosbach30506252011-12-08 00:31:07 +0000841 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000842 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000843 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
844 if (!CE) return false;
845 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000846 // Only use this when not representable as a plain so_imm.
847 return ARM_AM::getT2SOImmVal(Value) == -1 &&
848 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000849 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000850 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000851 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 if (!CE) return false;
854 int64_t Value = CE->getValue();
855 return Value == 1 || Value == 0;
856 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000857 bool isReg() const { return Kind == k_Register; }
858 bool isRegList() const { return Kind == k_RegisterList; }
859 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
860 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
861 bool isToken() const { return Kind == k_Token; }
862 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000863 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000864 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
865 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
866 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
867 bool isRotImm() const { return Kind == k_RotateImmediate; }
868 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
869 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000870 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000871 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000872 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000873 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000874 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000875 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000876 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000877 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
878 (alignOK || Memory.Alignment == 0);
879 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000880 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000881 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000882 return false;
883 // Base register must be PC.
884 if (Memory.BaseRegNum != ARM::PC)
885 return false;
886 // Immediate offset in range [-4095, 4095].
887 if (!Memory.OffsetImm) return true;
888 int64_t Val = Memory.OffsetImm->getValue();
889 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
890 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000891 bool isAlignedMemory() const {
892 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000893 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000894 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000895 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000896 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000897 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000898 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000899 if (!Memory.OffsetImm) return true;
900 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000901 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000902 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000903 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000904 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000905 // Immediate offset in range [-4095, 4095].
906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
907 if (!CE) return false;
908 int64_t Val = CE->getValue();
909 return Val > -4096 && Val < 4096;
910 }
Jim Grosbach5b96b802011-08-10 20:29:19 +0000911 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +0000912 // If we have an immediate that's not a constant, treat it as a label
913 // reference needing a fixup. If it is a constant, it's something else
914 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000915 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +0000916 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000917 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000918 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +0000919 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000920 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000921 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000922 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +0000923 if (!Memory.OffsetImm) return true;
924 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +0000925 // The #-0 offset is encoded as INT32_MIN, and we have to check
926 // for this too.
927 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000928 }
929 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000930 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000931 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000932 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000933 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
934 // Immediate offset in range [-255, 255].
935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
936 if (!CE) return false;
937 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000938 // Special case, #-0 is INT32_MIN.
939 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000940 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000941 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000942 // If we have an immediate that's not a constant, treat it as a label
943 // reference needing a fixup. If it is a constant, it's something else
944 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000945 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000946 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000947 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000948 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000949 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000950 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +0000951 if (!Memory.OffsetImm) return true;
952 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +0000953 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000954 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +0000955 }
Jim Grosbach05541f42011-09-19 22:21:13 +0000956 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +0000957 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000958 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +0000959 return false;
960 return true;
961 }
962 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +0000963 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000964 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
965 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +0000966 return false;
967 return true;
968 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000969 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +0000970 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +0000971 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +0000972 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000973 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000974 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +0000975 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000976 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000977 return false;
978 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +0000979 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000980 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +0000981 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000982 return false;
983 return true;
984 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000985 bool isMemThumbRR() const {
986 // Thumb reg+reg addressing is simple. Just two registers, a base and
987 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +0000988 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000989 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +0000990 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +0000991 return isARMLowRegister(Memory.BaseRegNum) &&
992 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000993 }
994 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +0000995 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000996 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000997 return false;
998 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +0000999 if (!Memory.OffsetImm) return true;
1000 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001001 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1002 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001003 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001004 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001005 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001006 return false;
1007 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001008 if (!Memory.OffsetImm) return true;
1009 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001010 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1011 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001012 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001013 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001014 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001015 return false;
1016 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001017 if (!Memory.OffsetImm) return true;
1018 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001019 return Val >= 0 && Val <= 31;
1020 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001021 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001022 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001023 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001024 return false;
1025 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001026 if (!Memory.OffsetImm) return true;
1027 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001028 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001029 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001030 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001031 // If we have an immediate that's not a constant, treat it as a label
1032 // reference needing a fixup. If it is a constant, it's something else
1033 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001034 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001035 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001036 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001037 return false;
1038 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001039 if (!Memory.OffsetImm) return true;
1040 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001041 // Special case, #-0 is INT32_MIN.
1042 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001043 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001044 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001045 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001046 return false;
1047 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001048 if (!Memory.OffsetImm) return true;
1049 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001050 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1051 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001052 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001053 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001054 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001055 // Base reg of PC isn't allowed for these encodings.
1056 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001057 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001058 if (!Memory.OffsetImm) return true;
1059 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001060 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001061 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001062 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001063 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001064 return false;
1065 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001066 if (!Memory.OffsetImm) return true;
1067 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001068 return Val >= 0 && Val < 256;
1069 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001070 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001071 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001072 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001073 // Base reg of PC isn't allowed for these encodings.
1074 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001075 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001076 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001077 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001078 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001079 }
1080 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001081 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001082 return false;
1083 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001084 if (!Memory.OffsetImm) return true;
1085 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001086 return (Val >= 0 && Val < 4096);
1087 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001088 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001089 // If we have an immediate that's not a constant, treat it as a label
1090 // reference needing a fixup. If it is a constant, it's something else
1091 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001092 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001093 return true;
1094
Chad Rosier41099832012-09-11 23:02:35 +00001095 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001096 return false;
1097 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001098 if (!Memory.OffsetImm) return true;
1099 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001100 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001101 }
1102 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001103 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001104 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1105 if (!CE) return false;
1106 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001107 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001108 }
Jim Grosbach93981412011-10-11 21:55:36 +00001109 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001110 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001111 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1112 if (!CE) return false;
1113 int64_t Val = CE->getValue();
1114 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1115 (Val == INT32_MIN);
1116 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001117
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001118 bool isMSRMask() const { return Kind == k_MSRMask; }
1119 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001120
Jim Grosbach741cd732011-10-17 22:26:03 +00001121 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001122 bool isSingleSpacedVectorList() const {
1123 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1124 }
1125 bool isDoubleSpacedVectorList() const {
1126 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1127 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001128 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001129 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001130 return VectorList.Count == 1;
1131 }
1132
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001133 bool isVecListDPair() const {
1134 if (!isSingleSpacedVectorList()) return false;
1135 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1136 .contains(VectorList.RegNum));
1137 }
1138
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001139 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001140 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001141 return VectorList.Count == 3;
1142 }
1143
Jim Grosbach846bcff2011-10-21 20:35:01 +00001144 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001145 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001146 return VectorList.Count == 4;
1147 }
1148
Jim Grosbache5307f92012-03-05 21:43:40 +00001149 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001150 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001151 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1152 .contains(VectorList.RegNum));
1153 }
1154
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001155 bool isVecListThreeQ() const {
1156 if (!isDoubleSpacedVectorList()) return false;
1157 return VectorList.Count == 3;
1158 }
1159
Jim Grosbach1e946a42012-01-24 00:43:12 +00001160 bool isVecListFourQ() const {
1161 if (!isDoubleSpacedVectorList()) return false;
1162 return VectorList.Count == 4;
1163 }
1164
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001165 bool isSingleSpacedVectorAllLanes() const {
1166 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1167 }
1168 bool isDoubleSpacedVectorAllLanes() const {
1169 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1170 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001171 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001172 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001173 return VectorList.Count == 1;
1174 }
1175
Jim Grosbach13a292c2012-03-06 22:01:44 +00001176 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001177 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001178 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1179 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001180 }
1181
Jim Grosbached428bc2012-03-06 23:10:38 +00001182 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001183 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001184 return VectorList.Count == 2;
1185 }
1186
Jim Grosbachb78403c2012-01-24 23:47:04 +00001187 bool isVecListThreeDAllLanes() const {
1188 if (!isSingleSpacedVectorAllLanes()) return false;
1189 return VectorList.Count == 3;
1190 }
1191
1192 bool isVecListThreeQAllLanes() const {
1193 if (!isDoubleSpacedVectorAllLanes()) return false;
1194 return VectorList.Count == 3;
1195 }
1196
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001197 bool isVecListFourDAllLanes() const {
1198 if (!isSingleSpacedVectorAllLanes()) return false;
1199 return VectorList.Count == 4;
1200 }
1201
1202 bool isVecListFourQAllLanes() const {
1203 if (!isDoubleSpacedVectorAllLanes()) return false;
1204 return VectorList.Count == 4;
1205 }
1206
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001207 bool isSingleSpacedVectorIndexed() const {
1208 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1209 }
1210 bool isDoubleSpacedVectorIndexed() const {
1211 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1212 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001213 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001214 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001215 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1216 }
1217
Jim Grosbachda511042011-12-14 23:35:06 +00001218 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001219 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001220 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1221 }
1222
1223 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001224 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001225 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1226 }
1227
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001228 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001229 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001230 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1231 }
1232
Jim Grosbachda511042011-12-14 23:35:06 +00001233 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001234 if (!isSingleSpacedVectorIndexed()) return false;
1235 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1236 }
1237
1238 bool isVecListTwoQWordIndexed() const {
1239 if (!isDoubleSpacedVectorIndexed()) return false;
1240 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1241 }
1242
1243 bool isVecListTwoQHWordIndexed() const {
1244 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001245 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1246 }
1247
1248 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001249 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001250 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1251 }
1252
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001253 bool isVecListThreeDByteIndexed() const {
1254 if (!isSingleSpacedVectorIndexed()) return false;
1255 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1256 }
1257
1258 bool isVecListThreeDHWordIndexed() const {
1259 if (!isSingleSpacedVectorIndexed()) return false;
1260 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1261 }
1262
1263 bool isVecListThreeQWordIndexed() const {
1264 if (!isDoubleSpacedVectorIndexed()) return false;
1265 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1266 }
1267
1268 bool isVecListThreeQHWordIndexed() const {
1269 if (!isDoubleSpacedVectorIndexed()) return false;
1270 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1271 }
1272
1273 bool isVecListThreeDWordIndexed() const {
1274 if (!isSingleSpacedVectorIndexed()) return false;
1275 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1276 }
1277
Jim Grosbach14952a02012-01-24 18:37:25 +00001278 bool isVecListFourDByteIndexed() const {
1279 if (!isSingleSpacedVectorIndexed()) return false;
1280 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1281 }
1282
1283 bool isVecListFourDHWordIndexed() const {
1284 if (!isSingleSpacedVectorIndexed()) return false;
1285 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1286 }
1287
1288 bool isVecListFourQWordIndexed() const {
1289 if (!isDoubleSpacedVectorIndexed()) return false;
1290 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1291 }
1292
1293 bool isVecListFourQHWordIndexed() const {
1294 if (!isDoubleSpacedVectorIndexed()) return false;
1295 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1296 }
1297
1298 bool isVecListFourDWordIndexed() const {
1299 if (!isSingleSpacedVectorIndexed()) return false;
1300 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1301 }
1302
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001303 bool isVectorIndex8() const {
1304 if (Kind != k_VectorIndex) return false;
1305 return VectorIndex.Val < 8;
1306 }
1307 bool isVectorIndex16() const {
1308 if (Kind != k_VectorIndex) return false;
1309 return VectorIndex.Val < 4;
1310 }
1311 bool isVectorIndex32() const {
1312 if (Kind != k_VectorIndex) return false;
1313 return VectorIndex.Val < 2;
1314 }
1315
Jim Grosbach741cd732011-10-17 22:26:03 +00001316 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001317 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001318 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1319 // Must be a constant.
1320 if (!CE) return false;
1321 int64_t Value = CE->getValue();
1322 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1323 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001324 return Value >= 0 && Value < 256;
1325 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001326
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001327 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001328 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001329 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1330 // Must be a constant.
1331 if (!CE) return false;
1332 int64_t Value = CE->getValue();
1333 // i16 value in the range [0,255] or [0x0100, 0xff00]
1334 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1335 }
1336
Jim Grosbach8211c052011-10-18 00:22:00 +00001337 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001338 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001339 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1340 // Must be a constant.
1341 if (!CE) return false;
1342 int64_t Value = CE->getValue();
1343 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1344 return (Value >= 0 && Value < 256) ||
1345 (Value >= 0x0100 && Value <= 0xff00) ||
1346 (Value >= 0x010000 && Value <= 0xff0000) ||
1347 (Value >= 0x01000000 && Value <= 0xff000000);
1348 }
1349
1350 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001351 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001352 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1353 // Must be a constant.
1354 if (!CE) return false;
1355 int64_t Value = CE->getValue();
1356 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1357 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1358 return (Value >= 0 && Value < 256) ||
1359 (Value >= 0x0100 && Value <= 0xff00) ||
1360 (Value >= 0x010000 && Value <= 0xff0000) ||
1361 (Value >= 0x01000000 && Value <= 0xff000000) ||
1362 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1363 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1364 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001365 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001366 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001367 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1368 // Must be a constant.
1369 if (!CE) return false;
1370 int64_t Value = ~CE->getValue();
1371 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1372 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1373 return (Value >= 0 && Value < 256) ||
1374 (Value >= 0x0100 && Value <= 0xff00) ||
1375 (Value >= 0x010000 && Value <= 0xff0000) ||
1376 (Value >= 0x01000000 && Value <= 0xff000000) ||
1377 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1378 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1379 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001380
Jim Grosbache4454e02011-10-18 16:18:11 +00001381 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001382 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001383 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1384 // Must be a constant.
1385 if (!CE) return false;
1386 uint64_t Value = CE->getValue();
1387 // i64 value with each byte being either 0 or 0xff.
1388 for (unsigned i = 0; i < 8; ++i)
1389 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1390 return true;
1391 }
1392
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001393 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001394 // Add as immediates when possible. Null MCExpr = 0.
1395 if (Expr == 0)
1396 Inst.addOperand(MCOperand::CreateImm(0));
1397 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001398 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1399 else
1400 Inst.addOperand(MCOperand::CreateExpr(Expr));
1401 }
1402
Daniel Dunbard8042b72010-08-11 06:36:53 +00001403 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001404 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001405 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001406 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1407 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001408 }
1409
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001410 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1411 assert(N == 1 && "Invalid number of operands!");
1412 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1413 }
1414
Jim Grosbach48399582011-10-12 17:34:41 +00001415 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1416 assert(N == 1 && "Invalid number of operands!");
1417 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1418 }
1419
1420 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1421 assert(N == 1 && "Invalid number of operands!");
1422 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1423 }
1424
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001425 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1426 assert(N == 1 && "Invalid number of operands!");
1427 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1428 }
1429
1430 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1431 assert(N == 1 && "Invalid number of operands!");
1432 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1433 }
1434
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001435 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1436 assert(N == 1 && "Invalid number of operands!");
1437 Inst.addOperand(MCOperand::CreateReg(getReg()));
1438 }
1439
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001440 void addRegOperands(MCInst &Inst, unsigned N) const {
1441 assert(N == 1 && "Invalid number of operands!");
1442 Inst.addOperand(MCOperand::CreateReg(getReg()));
1443 }
1444
Jim Grosbachac798e12011-07-25 20:49:51 +00001445 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001446 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001447 assert(isRegShiftedReg() &&
1448 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001449 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1450 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001451 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001452 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001453 }
1454
Jim Grosbachac798e12011-07-25 20:49:51 +00001455 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001456 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001457 assert(isRegShiftedImm() &&
1458 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001459 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001460 // Shift of #32 is encoded as 0 where permitted
1461 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001462 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001463 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001464 }
1465
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001466 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001467 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001468 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1469 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001470 }
1471
Bill Wendling8d2aa032010-11-08 23:49:57 +00001472 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001473 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001474 const SmallVectorImpl<unsigned> &RegList = getRegList();
1475 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001476 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1477 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001478 }
1479
Bill Wendling9898ac92010-11-17 04:32:08 +00001480 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1481 addRegListOperands(Inst, N);
1482 }
1483
1484 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1485 addRegListOperands(Inst, N);
1486 }
1487
Jim Grosbach833b9d32011-07-27 20:15:40 +00001488 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1489 assert(N == 1 && "Invalid number of operands!");
1490 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1491 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1492 }
1493
Jim Grosbach864b6092011-07-28 21:34:26 +00001494 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1495 assert(N == 1 && "Invalid number of operands!");
1496 // Munge the lsb/width into a bitfield mask.
1497 unsigned lsb = Bitfield.LSB;
1498 unsigned width = Bitfield.Width;
1499 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1500 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1501 (32 - (lsb + width)));
1502 Inst.addOperand(MCOperand::CreateImm(Mask));
1503 }
1504
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001505 void addImmOperands(MCInst &Inst, unsigned N) const {
1506 assert(N == 1 && "Invalid number of operands!");
1507 addExpr(Inst, getImm());
1508 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001509
Jim Grosbachea231912011-12-22 22:19:05 +00001510 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1511 assert(N == 1 && "Invalid number of operands!");
1512 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1513 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1514 }
1515
1516 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1517 assert(N == 1 && "Invalid number of operands!");
1518 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1519 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1520 }
1521
Jim Grosbache7fbce72011-10-03 23:38:36 +00001522 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1523 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001524 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1525 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1526 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001527 }
1528
Jim Grosbach7db8d692011-09-08 22:07:06 +00001529 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1530 assert(N == 1 && "Invalid number of operands!");
1531 // FIXME: We really want to scale the value here, but the LDRD/STRD
1532 // instruction don't encode operands that way yet.
1533 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1534 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1535 }
1536
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001537 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1538 assert(N == 1 && "Invalid number of operands!");
1539 // The immediate is scaled by four in the encoding and is stored
1540 // in the MCInst as such. Lop off the low two bits here.
1541 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1542 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1543 }
1544
Jim Grosbach930f2f62012-04-05 20:57:13 +00001545 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1546 assert(N == 1 && "Invalid number of operands!");
1547 // The immediate is scaled by four in the encoding and is stored
1548 // in the MCInst as such. Lop off the low two bits here.
1549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1550 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1551 }
1552
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001553 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 // The immediate is scaled by four in the encoding and is stored
1556 // in the MCInst as such. Lop off the low two bits here.
1557 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1558 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1559 }
1560
Jim Grosbach475c6db2011-07-25 23:09:14 +00001561 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1562 assert(N == 1 && "Invalid number of operands!");
1563 // The constant encodes as the immediate-1, and we store in the instruction
1564 // the bits as encoded, so subtract off one here.
1565 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1566 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1567 }
1568
Jim Grosbach801e0a32011-07-22 23:16:18 +00001569 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1570 assert(N == 1 && "Invalid number of operands!");
1571 // The constant encodes as the immediate-1, and we store in the instruction
1572 // the bits as encoded, so subtract off one here.
1573 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1574 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1575 }
1576
Jim Grosbach46dd4132011-08-17 21:51:27 +00001577 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1578 assert(N == 1 && "Invalid number of operands!");
1579 // The constant encodes as the immediate, except for 32, which encodes as
1580 // zero.
1581 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1582 unsigned Imm = CE->getValue();
1583 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1584 }
1585
Jim Grosbach27c1e252011-07-21 17:23:04 +00001586 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1587 assert(N == 1 && "Invalid number of operands!");
1588 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1589 // the instruction as well.
1590 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1591 int Val = CE->getValue();
1592 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1593 }
1594
Jim Grosbachb009a872011-10-28 22:36:30 +00001595 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1596 assert(N == 1 && "Invalid number of operands!");
1597 // The operand is actually a t2_so_imm, but we have its bitwise
1598 // negation in the assembly source, so twiddle it here.
1599 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1600 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1601 }
1602
Jim Grosbach30506252011-12-08 00:31:07 +00001603 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1604 assert(N == 1 && "Invalid number of operands!");
1605 // The operand is actually a t2_so_imm, but we have its
1606 // negation in the assembly source, so twiddle it here.
1607 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1608 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1609 }
1610
Jim Grosbach930f2f62012-04-05 20:57:13 +00001611 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1612 assert(N == 1 && "Invalid number of operands!");
1613 // The operand is actually an imm0_4095, but we have its
1614 // negation in the assembly source, so twiddle it here.
1615 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1616 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1617 }
1618
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001619 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1620 assert(N == 1 && "Invalid number of operands!");
1621 // The operand is actually a so_imm, but we have its bitwise
1622 // negation in the assembly source, so twiddle it here.
1623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1624 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1625 }
1626
Jim Grosbach30506252011-12-08 00:31:07 +00001627 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
1629 // The operand is actually a so_imm, but we have its
1630 // negation in the assembly source, so twiddle it here.
1631 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1632 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1633 }
1634
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001635 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
1637 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1638 }
1639
Jim Grosbachd3595712011-08-03 23:50:40 +00001640 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1641 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001642 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001643 }
1644
Jim Grosbach94298a92012-01-18 22:46:46 +00001645 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
1647 int32_t Imm = Memory.OffsetImm->getValue();
1648 // FIXME: Handle #-0
1649 if (Imm == INT32_MIN) Imm = 0;
1650 Inst.addOperand(MCOperand::CreateImm(Imm));
1651 }
1652
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001653 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1654 assert(N == 1 && "Invalid number of operands!");
1655 assert(isImm() && "Not an immediate!");
1656
1657 // If we have an immediate that's not a constant, treat it as a label
1658 // reference needing a fixup.
1659 if (!isa<MCConstantExpr>(getImm())) {
1660 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1661 return;
1662 }
1663
1664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1665 int Val = CE->getValue();
1666 Inst.addOperand(MCOperand::CreateImm(Val));
1667 }
1668
Jim Grosbacha95ec992011-10-11 17:29:55 +00001669 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1670 assert(N == 2 && "Invalid number of operands!");
1671 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1672 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1673 }
1674
Jim Grosbachd3595712011-08-03 23:50:40 +00001675 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1676 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001677 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1678 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001679 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1680 // Special case for #-0
1681 if (Val == INT32_MIN) Val = 0;
1682 if (Val < 0) Val = -Val;
1683 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1684 } else {
1685 // For register offset, we encode the shift type and negation flag
1686 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001687 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1688 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001689 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001690 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1691 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001692 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001693 }
1694
Jim Grosbachcd17c122011-08-04 23:01:30 +00001695 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1696 assert(N == 2 && "Invalid number of operands!");
1697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1698 assert(CE && "non-constant AM2OffsetImm operand!");
1699 int32_t Val = CE->getValue();
1700 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1701 // Special case for #-0
1702 if (Val == INT32_MIN) Val = 0;
1703 if (Val < 0) Val = -Val;
1704 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1705 Inst.addOperand(MCOperand::CreateReg(0));
1706 Inst.addOperand(MCOperand::CreateImm(Val));
1707 }
1708
Jim Grosbach5b96b802011-08-10 20:29:19 +00001709 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1710 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001711 // If we have an immediate that's not a constant, treat it as a label
1712 // reference needing a fixup. If it is a constant, it's something else
1713 // and we reject it.
1714 if (isImm()) {
1715 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1716 Inst.addOperand(MCOperand::CreateReg(0));
1717 Inst.addOperand(MCOperand::CreateImm(0));
1718 return;
1719 }
1720
Jim Grosbach871dff72011-10-11 15:59:20 +00001721 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1722 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001723 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1724 // Special case for #-0
1725 if (Val == INT32_MIN) Val = 0;
1726 if (Val < 0) Val = -Val;
1727 Val = ARM_AM::getAM3Opc(AddSub, Val);
1728 } else {
1729 // For register offset, we encode the shift type and negation flag
1730 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001731 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001732 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001733 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1734 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001735 Inst.addOperand(MCOperand::CreateImm(Val));
1736 }
1737
1738 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1739 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001740 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001741 int32_t Val =
1742 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1743 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1744 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001745 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001746 }
1747
1748 // Constant offset.
1749 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1750 int32_t Val = CE->getValue();
1751 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1752 // Special case for #-0
1753 if (Val == INT32_MIN) Val = 0;
1754 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001755 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001756 Inst.addOperand(MCOperand::CreateReg(0));
1757 Inst.addOperand(MCOperand::CreateImm(Val));
1758 }
1759
Jim Grosbachd3595712011-08-03 23:50:40 +00001760 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1761 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001762 // If we have an immediate that's not a constant, treat it as a label
1763 // reference needing a fixup. If it is a constant, it's something else
1764 // and we reject it.
1765 if (isImm()) {
1766 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1767 Inst.addOperand(MCOperand::CreateImm(0));
1768 return;
1769 }
1770
Jim Grosbachd3595712011-08-03 23:50:40 +00001771 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001772 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001773 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1774 // Special case for #-0
1775 if (Val == INT32_MIN) Val = 0;
1776 if (Val < 0) Val = -Val;
1777 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001778 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001779 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001780 }
1781
Jim Grosbach7db8d692011-09-08 22:07:06 +00001782 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1783 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001784 // If we have an immediate that's not a constant, treat it as a label
1785 // reference needing a fixup. If it is a constant, it's something else
1786 // and we reject it.
1787 if (isImm()) {
1788 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1789 Inst.addOperand(MCOperand::CreateImm(0));
1790 return;
1791 }
1792
Jim Grosbach871dff72011-10-11 15:59:20 +00001793 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1794 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001795 Inst.addOperand(MCOperand::CreateImm(Val));
1796 }
1797
Jim Grosbacha05627e2011-09-09 18:37:27 +00001798 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1799 assert(N == 2 && "Invalid number of operands!");
1800 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001801 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1802 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001803 Inst.addOperand(MCOperand::CreateImm(Val));
1804 }
1805
Jim Grosbachd3595712011-08-03 23:50:40 +00001806 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1807 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001808 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1809 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001810 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001811 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001812
Jim Grosbach2392c532011-09-07 23:39:14 +00001813 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1814 addMemImm8OffsetOperands(Inst, N);
1815 }
1816
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001817 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001818 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001819 }
1820
1821 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1822 assert(N == 2 && "Invalid number of operands!");
1823 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001824 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001825 addExpr(Inst, getImm());
1826 Inst.addOperand(MCOperand::CreateImm(0));
1827 return;
1828 }
1829
1830 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001831 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1832 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001833 Inst.addOperand(MCOperand::CreateImm(Val));
1834 }
1835
Jim Grosbachd3595712011-08-03 23:50:40 +00001836 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1837 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001838 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001839 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001840 addExpr(Inst, getImm());
1841 Inst.addOperand(MCOperand::CreateImm(0));
1842 return;
1843 }
1844
1845 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001846 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1847 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001848 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001849 }
Bill Wendling811c9362010-11-30 07:44:32 +00001850
Jim Grosbach05541f42011-09-19 22:21:13 +00001851 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1852 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001853 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1854 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001855 }
1856
1857 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1858 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001859 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1860 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001861 }
1862
Jim Grosbachd3595712011-08-03 23:50:40 +00001863 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1864 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001865 unsigned Val =
1866 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1867 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001868 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1869 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001870 Inst.addOperand(MCOperand::CreateImm(Val));
1871 }
1872
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001873 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1874 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001875 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1876 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1877 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001878 }
1879
Jim Grosbachd3595712011-08-03 23:50:40 +00001880 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1881 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001882 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1883 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001884 }
1885
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001886 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1887 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001888 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1889 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001890 Inst.addOperand(MCOperand::CreateImm(Val));
1891 }
1892
Jim Grosbach26d35872011-08-19 18:55:51 +00001893 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1894 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001895 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1896 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00001897 Inst.addOperand(MCOperand::CreateImm(Val));
1898 }
1899
Jim Grosbacha32c7532011-08-19 18:49:59 +00001900 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1901 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001902 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1903 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00001904 Inst.addOperand(MCOperand::CreateImm(Val));
1905 }
1906
Jim Grosbach23983d62011-08-19 18:13:48 +00001907 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1908 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001909 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1910 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00001911 Inst.addOperand(MCOperand::CreateImm(Val));
1912 }
1913
Jim Grosbachd3595712011-08-03 23:50:40 +00001914 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1915 assert(N == 1 && "Invalid number of operands!");
1916 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1917 assert(CE && "non-constant post-idx-imm8 operand!");
1918 int Imm = CE->getValue();
1919 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00001920 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001921 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1922 Inst.addOperand(MCOperand::CreateImm(Imm));
1923 }
1924
Jim Grosbach93981412011-10-11 21:55:36 +00001925 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1926 assert(N == 1 && "Invalid number of operands!");
1927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1928 assert(CE && "non-constant post-idx-imm8s4 operand!");
1929 int Imm = CE->getValue();
1930 bool isAdd = Imm >= 0;
1931 if (Imm == INT32_MIN) Imm = 0;
1932 // Immediate is scaled by 4.
1933 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1934 Inst.addOperand(MCOperand::CreateImm(Imm));
1935 }
1936
Jim Grosbachd3595712011-08-03 23:50:40 +00001937 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1938 assert(N == 2 && "Invalid number of operands!");
1939 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00001940 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1941 }
1942
1943 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1944 assert(N == 2 && "Invalid number of operands!");
1945 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1946 // The sign, shift type, and shift amount are encoded in a single operand
1947 // using the AM2 encoding helpers.
1948 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1949 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1950 PostIdxReg.ShiftTy);
1951 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00001952 }
1953
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00001954 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1955 assert(N == 1 && "Invalid number of operands!");
1956 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1957 }
1958
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00001959 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1960 assert(N == 1 && "Invalid number of operands!");
1961 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1962 }
1963
Jim Grosbach182b6a02011-11-29 23:51:09 +00001964 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001965 assert(N == 1 && "Invalid number of operands!");
1966 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1967 }
1968
Jim Grosbach04945c42011-12-02 00:35:16 +00001969 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1970 assert(N == 2 && "Invalid number of operands!");
1971 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1972 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1973 }
1974
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001975 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1976 assert(N == 1 && "Invalid number of operands!");
1977 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1978 }
1979
1980 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1981 assert(N == 1 && "Invalid number of operands!");
1982 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1983 }
1984
1985 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1986 assert(N == 1 && "Invalid number of operands!");
1987 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1988 }
1989
Jim Grosbach741cd732011-10-17 22:26:03 +00001990 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1991 assert(N == 1 && "Invalid number of operands!");
1992 // The immediate encodes the type of constant as well as the value.
1993 // Mask in that this is an i8 splat.
1994 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1995 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1996 }
1997
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001998 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1999 assert(N == 1 && "Invalid number of operands!");
2000 // The immediate encodes the type of constant as well as the value.
2001 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2002 unsigned Value = CE->getValue();
2003 if (Value >= 256)
2004 Value = (Value >> 8) | 0xa00;
2005 else
2006 Value |= 0x800;
2007 Inst.addOperand(MCOperand::CreateImm(Value));
2008 }
2009
Jim Grosbach8211c052011-10-18 00:22:00 +00002010 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2011 assert(N == 1 && "Invalid number of operands!");
2012 // The immediate encodes the type of constant as well as the value.
2013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2014 unsigned Value = CE->getValue();
2015 if (Value >= 256 && Value <= 0xff00)
2016 Value = (Value >> 8) | 0x200;
2017 else if (Value > 0xffff && Value <= 0xff0000)
2018 Value = (Value >> 16) | 0x400;
2019 else if (Value > 0xffffff)
2020 Value = (Value >> 24) | 0x600;
2021 Inst.addOperand(MCOperand::CreateImm(Value));
2022 }
2023
2024 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2025 assert(N == 1 && "Invalid number of operands!");
2026 // The immediate encodes the type of constant as well as the value.
2027 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2028 unsigned Value = CE->getValue();
2029 if (Value >= 256 && Value <= 0xffff)
2030 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2031 else if (Value > 0xffff && Value <= 0xffffff)
2032 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2033 else if (Value > 0xffffff)
2034 Value = (Value >> 24) | 0x600;
2035 Inst.addOperand(MCOperand::CreateImm(Value));
2036 }
2037
Jim Grosbach045b6c72011-12-19 23:51:07 +00002038 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2039 assert(N == 1 && "Invalid number of operands!");
2040 // The immediate encodes the type of constant as well as the value.
2041 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2042 unsigned Value = ~CE->getValue();
2043 if (Value >= 256 && Value <= 0xffff)
2044 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2045 else if (Value > 0xffff && Value <= 0xffffff)
2046 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2047 else if (Value > 0xffffff)
2048 Value = (Value >> 24) | 0x600;
2049 Inst.addOperand(MCOperand::CreateImm(Value));
2050 }
2051
Jim Grosbache4454e02011-10-18 16:18:11 +00002052 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 1 && "Invalid number of operands!");
2054 // The immediate encodes the type of constant as well as the value.
2055 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2056 uint64_t Value = CE->getValue();
2057 unsigned Imm = 0;
2058 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2059 Imm |= (Value & 1) << i;
2060 }
2061 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2062 }
2063
Jim Grosbach602aa902011-07-13 15:34:57 +00002064 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002065
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002066 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002067 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002068 Op->ITMask.Mask = Mask;
2069 Op->StartLoc = S;
2070 Op->EndLoc = S;
2071 return Op;
2072 }
2073
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002074 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002075 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002076 Op->CC.Val = CC;
2077 Op->StartLoc = S;
2078 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002079 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002080 }
2081
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002082 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002083 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002084 Op->Cop.Val = CopVal;
2085 Op->StartLoc = S;
2086 Op->EndLoc = S;
2087 return Op;
2088 }
2089
2090 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002091 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002092 Op->Cop.Val = CopVal;
2093 Op->StartLoc = S;
2094 Op->EndLoc = S;
2095 return Op;
2096 }
2097
Jim Grosbach48399582011-10-12 17:34:41 +00002098 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2099 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2100 Op->Cop.Val = Val;
2101 Op->StartLoc = S;
2102 Op->EndLoc = E;
2103 return Op;
2104 }
2105
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002106 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002107 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002108 Op->Reg.RegNum = RegNum;
2109 Op->StartLoc = S;
2110 Op->EndLoc = S;
2111 return Op;
2112 }
2113
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002114 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002115 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002116 Op->Tok.Data = Str.data();
2117 Op->Tok.Length = Str.size();
2118 Op->StartLoc = S;
2119 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002120 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002121 }
2122
Bill Wendling2063b842010-11-18 23:43:05 +00002123 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002124 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002125 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002126 Op->StartLoc = S;
2127 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002128 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002129 }
2130
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002131 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2132 unsigned SrcReg,
2133 unsigned ShiftReg,
2134 unsigned ShiftImm,
2135 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002136 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002137 Op->RegShiftedReg.ShiftTy = ShTy;
2138 Op->RegShiftedReg.SrcReg = SrcReg;
2139 Op->RegShiftedReg.ShiftReg = ShiftReg;
2140 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002141 Op->StartLoc = S;
2142 Op->EndLoc = E;
2143 return Op;
2144 }
2145
Owen Andersonb595ed02011-07-21 18:54:16 +00002146 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2147 unsigned SrcReg,
2148 unsigned ShiftImm,
2149 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002150 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002151 Op->RegShiftedImm.ShiftTy = ShTy;
2152 Op->RegShiftedImm.SrcReg = SrcReg;
2153 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002154 Op->StartLoc = S;
2155 Op->EndLoc = E;
2156 return Op;
2157 }
2158
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002159 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002160 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002161 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002162 Op->ShifterImm.isASR = isASR;
2163 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002164 Op->StartLoc = S;
2165 Op->EndLoc = E;
2166 return Op;
2167 }
2168
Jim Grosbach833b9d32011-07-27 20:15:40 +00002169 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002170 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002171 Op->RotImm.Imm = Imm;
2172 Op->StartLoc = S;
2173 Op->EndLoc = E;
2174 return Op;
2175 }
2176
Jim Grosbach864b6092011-07-28 21:34:26 +00002177 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2178 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002179 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002180 Op->Bitfield.LSB = LSB;
2181 Op->Bitfield.Width = Width;
2182 Op->StartLoc = S;
2183 Op->EndLoc = E;
2184 return Op;
2185 }
2186
Bill Wendling2cae3272010-11-09 22:44:22 +00002187 static ARMOperand *
Bill Wendlingbed94652010-11-09 23:28:44 +00002188 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002189 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002190 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002191
Jim Grosbach75461af2011-09-13 22:56:44 +00002192 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002193 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002194 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng9eec7642011-07-25 21:32:49 +00002195 contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002196 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002197
2198 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendlingbed94652010-11-09 23:28:44 +00002199 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002200 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling0ab0f672010-11-18 21:50:54 +00002201 Op->Registers.push_back(I->first);
Bill Wendling20b5ea982010-11-19 00:38:19 +00002202 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002203 Op->StartLoc = StartLoc;
2204 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002205 return Op;
2206 }
2207
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002208 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002209 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002210 ARMOperand *Op = new ARMOperand(k_VectorList);
2211 Op->VectorList.RegNum = RegNum;
2212 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002213 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002214 Op->StartLoc = S;
2215 Op->EndLoc = E;
2216 return Op;
2217 }
2218
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002219 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002220 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002221 SMLoc S, SMLoc E) {
2222 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2223 Op->VectorList.RegNum = RegNum;
2224 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002225 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002226 Op->StartLoc = S;
2227 Op->EndLoc = E;
2228 return Op;
2229 }
2230
Jim Grosbach04945c42011-12-02 00:35:16 +00002231 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002232 unsigned Index,
2233 bool isDoubleSpaced,
2234 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002235 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2236 Op->VectorList.RegNum = RegNum;
2237 Op->VectorList.Count = Count;
2238 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002239 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002240 Op->StartLoc = S;
2241 Op->EndLoc = E;
2242 return Op;
2243 }
2244
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002245 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2246 MCContext &Ctx) {
2247 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2248 Op->VectorIndex.Val = Idx;
2249 Op->StartLoc = S;
2250 Op->EndLoc = E;
2251 return Op;
2252 }
2253
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002254 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002255 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002256 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002257 Op->StartLoc = S;
2258 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002259 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002260 }
2261
Jim Grosbachd3595712011-08-03 23:50:40 +00002262 static ARMOperand *CreateMem(unsigned BaseRegNum,
2263 const MCConstantExpr *OffsetImm,
2264 unsigned OffsetRegNum,
2265 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002266 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002267 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002268 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002269 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002270 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002271 Op->Memory.BaseRegNum = BaseRegNum;
2272 Op->Memory.OffsetImm = OffsetImm;
2273 Op->Memory.OffsetRegNum = OffsetRegNum;
2274 Op->Memory.ShiftType = ShiftType;
2275 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002276 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002277 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002278 Op->StartLoc = S;
2279 Op->EndLoc = E;
2280 return Op;
2281 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002282
Jim Grosbachc320c852011-08-05 21:28:30 +00002283 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2284 ARM_AM::ShiftOpc ShiftTy,
2285 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002286 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002287 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002288 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002289 Op->PostIdxReg.isAdd = isAdd;
2290 Op->PostIdxReg.ShiftTy = ShiftTy;
2291 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002292 Op->StartLoc = S;
2293 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002294 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002295 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002296
2297 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002298 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002299 Op->MBOpt.Val = Opt;
2300 Op->StartLoc = S;
2301 Op->EndLoc = S;
2302 return Op;
2303 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002304
2305 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002306 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002307 Op->IFlags.Val = IFlags;
2308 Op->StartLoc = S;
2309 Op->EndLoc = S;
2310 return Op;
2311 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002312
2313 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002314 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002315 Op->MMask.Val = MMask;
2316 Op->StartLoc = S;
2317 Op->EndLoc = S;
2318 return Op;
2319 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002320};
2321
2322} // end anonymous namespace.
2323
Jim Grosbach602aa902011-07-13 15:34:57 +00002324void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002325 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002326 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002327 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002328 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002329 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002330 OS << "<ccout " << getReg() << ">";
2331 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002332 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002333 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002334 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2335 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2336 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002337 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2338 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2339 break;
2340 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002341 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002342 OS << "<coprocessor number: " << getCoproc() << ">";
2343 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002344 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002345 OS << "<coprocessor register: " << getCoproc() << ">";
2346 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002347 case k_CoprocOption:
2348 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2349 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002350 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002351 OS << "<mask: " << getMSRMask() << ">";
2352 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002353 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002354 getImm()->print(OS);
2355 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002356 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002357 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2358 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002359 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002360 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002361 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002362 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002363 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002364 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002365 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2366 << PostIdxReg.RegNum;
2367 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2368 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2369 << PostIdxReg.ShiftImm;
2370 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002371 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002372 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002373 OS << "<ARM_PROC::";
2374 unsigned IFlags = getProcIFlags();
2375 for (int i=2; i >= 0; --i)
2376 if (IFlags & (1 << i))
2377 OS << ARM_PROC::IFlagsToString(1 << i);
2378 OS << ">";
2379 break;
2380 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002381 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002382 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002383 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002384 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002385 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2386 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002387 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002388 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002389 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002390 << RegShiftedReg.SrcReg << " "
2391 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2392 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002393 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002394 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002395 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002396 << RegShiftedImm.SrcReg << " "
2397 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2398 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002399 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002400 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002401 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2402 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002403 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002404 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2405 << ", width: " << Bitfield.Width << ">";
2406 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002407 case k_RegisterList:
2408 case k_DPRRegisterList:
2409 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002410 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002411
Bill Wendlingbed94652010-11-09 23:28:44 +00002412 const SmallVectorImpl<unsigned> &RegList = getRegList();
2413 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002414 I = RegList.begin(), E = RegList.end(); I != E; ) {
2415 OS << *I;
2416 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002417 }
2418
2419 OS << ">";
2420 break;
2421 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002422 case k_VectorList:
2423 OS << "<vector_list " << VectorList.Count << " * "
2424 << VectorList.RegNum << ">";
2425 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002426 case k_VectorListAllLanes:
2427 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2428 << VectorList.RegNum << ">";
2429 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002430 case k_VectorListIndexed:
2431 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2432 << VectorList.Count << " * " << VectorList.RegNum << ">";
2433 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002434 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002435 OS << "'" << getToken() << "'";
2436 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002437 case k_VectorIndex:
2438 OS << "<vectorindex " << getVectorIndex() << ">";
2439 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002440 }
2441}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002442
2443/// @name Auto-generated Match Functions
2444/// {
2445
2446static unsigned MatchRegisterName(StringRef Name);
2447
2448/// }
2449
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002450bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2451 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002452 StartLoc = Parser.getTok().getLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002453 RegNo = tryParseRegister();
Jim Grosbachab5830e2011-12-14 02:16:11 +00002454 EndLoc = Parser.getTok().getLoc();
Roman Divacky36b1b472011-01-27 17:14:22 +00002455
2456 return (RegNo == (unsigned)-1);
2457}
2458
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002459/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002460/// and if it is a register name the token is eaten and the register number is
2461/// returned. Otherwise return -1.
2462///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002463int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002464 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002465 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002466
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002467 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002468 unsigned RegNum = MatchRegisterName(lowerCase);
2469 if (!RegNum) {
2470 RegNum = StringSwitch<unsigned>(lowerCase)
2471 .Case("r13", ARM::SP)
2472 .Case("r14", ARM::LR)
2473 .Case("r15", ARM::PC)
2474 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002475 // Additional register name aliases for 'gas' compatibility.
2476 .Case("a1", ARM::R0)
2477 .Case("a2", ARM::R1)
2478 .Case("a3", ARM::R2)
2479 .Case("a4", ARM::R3)
2480 .Case("v1", ARM::R4)
2481 .Case("v2", ARM::R5)
2482 .Case("v3", ARM::R6)
2483 .Case("v4", ARM::R7)
2484 .Case("v5", ARM::R8)
2485 .Case("v6", ARM::R9)
2486 .Case("v7", ARM::R10)
2487 .Case("v8", ARM::R11)
2488 .Case("sb", ARM::R9)
2489 .Case("sl", ARM::R10)
2490 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002491 .Default(0);
2492 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002493 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002494 // Check for aliases registered via .req. Canonicalize to lower case.
2495 // That's more consistent since register names are case insensitive, and
2496 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2497 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002498 // If no match, return failure.
2499 if (Entry == RegisterReqs.end())
2500 return -1;
2501 Parser.Lex(); // Eat identifier token.
2502 return Entry->getValue();
2503 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002504
Chris Lattner44e5981c2010-10-30 04:09:10 +00002505 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002506
Chris Lattner44e5981c2010-10-30 04:09:10 +00002507 return RegNum;
2508}
Jim Grosbach99710a82010-11-01 16:44:21 +00002509
Jim Grosbachbb24c592011-07-13 18:49:30 +00002510// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2511// If a recoverable error occurs, return 1. If an irrecoverable error
2512// occurs, return -1. An irrecoverable error is one where tokens have been
2513// consumed in the process of trying to parse the shifter (i.e., when it is
2514// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002515int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002516 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2517 SMLoc S = Parser.getTok().getLoc();
2518 const AsmToken &Tok = Parser.getTok();
2519 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2520
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002521 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002522 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002523 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002524 .Case("lsl", ARM_AM::lsl)
2525 .Case("lsr", ARM_AM::lsr)
2526 .Case("asr", ARM_AM::asr)
2527 .Case("ror", ARM_AM::ror)
2528 .Case("rrx", ARM_AM::rrx)
2529 .Default(ARM_AM::no_shift);
2530
2531 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002532 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002533
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002534 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002535
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002536 // The source register for the shift has already been added to the
2537 // operand list, so we need to pop it off and combine it into the shifted
2538 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002539 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002540 if (!PrevOp->isReg())
2541 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2542 int SrcReg = PrevOp->getReg();
2543 int64_t Imm = 0;
2544 int ShiftReg = 0;
2545 if (ShiftTy == ARM_AM::rrx) {
2546 // RRX Doesn't have an explicit shift amount. The encoder expects
2547 // the shift register to be the same as the source register. Seems odd,
2548 // but OK.
2549 ShiftReg = SrcReg;
2550 } else {
2551 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002552 if (Parser.getTok().is(AsmToken::Hash) ||
2553 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002554 Parser.Lex(); // Eat hash.
2555 SMLoc ImmLoc = Parser.getTok().getLoc();
2556 const MCExpr *ShiftExpr = 0;
Jim Grosbachbb24c592011-07-13 18:49:30 +00002557 if (getParser().ParseExpression(ShiftExpr)) {
2558 Error(ImmLoc, "invalid immediate shift value");
2559 return -1;
2560 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002561 // The expression must be evaluatable as an immediate.
2562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002563 if (!CE) {
2564 Error(ImmLoc, "invalid immediate shift value");
2565 return -1;
2566 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002567 // Range check the immediate.
2568 // lsl, ror: 0 <= imm <= 31
2569 // lsr, asr: 0 <= imm <= 32
2570 Imm = CE->getValue();
2571 if (Imm < 0 ||
2572 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2573 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002574 Error(ImmLoc, "immediate shift value out of range");
2575 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002576 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002577 // shift by zero is a nop. Always send it through as lsl.
2578 // ('as' compatibility)
2579 if (Imm == 0)
2580 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002581 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002582 ShiftReg = tryParseRegister();
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002583 SMLoc L = Parser.getTok().getLoc();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002584 if (ShiftReg == -1) {
2585 Error (L, "expected immediate or register in shift operand");
2586 return -1;
2587 }
2588 } else {
2589 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002590 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002591 return -1;
2592 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002593 }
2594
Owen Andersonb595ed02011-07-21 18:54:16 +00002595 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2596 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002597 ShiftReg, Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002598 S, Parser.getTok().getLoc()));
Owen Andersonb595ed02011-07-21 18:54:16 +00002599 else
2600 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2601 S, Parser.getTok().getLoc()));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002602
Jim Grosbachbb24c592011-07-13 18:49:30 +00002603 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002604}
2605
2606
Bill Wendling2063b842010-11-18 23:43:05 +00002607/// Try to parse a register name. The token must be an Identifier when called.
2608/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2609/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002610///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002611/// TODO this is likely to change to allow different register types and or to
2612/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002613bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002614tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002615 SMLoc S = Parser.getTok().getLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002616 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002617 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002618 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002619
Bill Wendling2063b842010-11-18 23:43:05 +00002620 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002621
Chris Lattner44e5981c2010-10-30 04:09:10 +00002622 const AsmToken &ExclaimTok = Parser.getTok();
2623 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002624 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2625 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002626 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002627 return false;
2628 }
2629
2630 // Also check for an index operand. This is only legal for vector registers,
2631 // but that'll get caught OK in operand matching, so we don't need to
2632 // explicitly filter everything else out here.
2633 if (Parser.getTok().is(AsmToken::LBrac)) {
2634 SMLoc SIdx = Parser.getTok().getLoc();
2635 Parser.Lex(); // Eat left bracket token.
2636
2637 const MCExpr *ImmVal;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002638 if (getParser().ParseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002639 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002640 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002641 if (!MCE)
2642 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002643
2644 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002645 if (Parser.getTok().isNot(AsmToken::RBrac))
2646 return Error(E, "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002647
2648 Parser.Lex(); // Eat right bracket token.
2649
2650 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2651 SIdx, E,
2652 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002653 }
2654
Bill Wendling2063b842010-11-18 23:43:05 +00002655 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002656}
2657
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002658/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2659/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2660/// "c5", ...
2661static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002662 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2663 // but efficient.
2664 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002665 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002666 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002667 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002668 return -1;
2669 switch (Name[1]) {
2670 default: return -1;
2671 case '0': return 0;
2672 case '1': return 1;
2673 case '2': return 2;
2674 case '3': return 3;
2675 case '4': return 4;
2676 case '5': return 5;
2677 case '6': return 6;
2678 case '7': return 7;
2679 case '8': return 8;
2680 case '9': return 9;
2681 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002682 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002683 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002684 return -1;
2685 switch (Name[2]) {
2686 default: return -1;
2687 case '0': return 10;
2688 case '1': return 11;
2689 case '2': return 12;
2690 case '3': return 13;
2691 case '4': return 14;
2692 case '5': return 15;
2693 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002694 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002695}
2696
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002697/// parseITCondCode - Try to parse a condition code for an IT instruction.
2698ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2699parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2700 SMLoc S = Parser.getTok().getLoc();
2701 const AsmToken &Tok = Parser.getTok();
2702 if (!Tok.is(AsmToken::Identifier))
2703 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002704 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002705 .Case("eq", ARMCC::EQ)
2706 .Case("ne", ARMCC::NE)
2707 .Case("hs", ARMCC::HS)
2708 .Case("cs", ARMCC::HS)
2709 .Case("lo", ARMCC::LO)
2710 .Case("cc", ARMCC::LO)
2711 .Case("mi", ARMCC::MI)
2712 .Case("pl", ARMCC::PL)
2713 .Case("vs", ARMCC::VS)
2714 .Case("vc", ARMCC::VC)
2715 .Case("hi", ARMCC::HI)
2716 .Case("ls", ARMCC::LS)
2717 .Case("ge", ARMCC::GE)
2718 .Case("lt", ARMCC::LT)
2719 .Case("gt", ARMCC::GT)
2720 .Case("le", ARMCC::LE)
2721 .Case("al", ARMCC::AL)
2722 .Default(~0U);
2723 if (CC == ~0U)
2724 return MatchOperand_NoMatch;
2725 Parser.Lex(); // Eat the token.
2726
2727 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2728
2729 return MatchOperand_Success;
2730}
2731
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002732/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002733/// token must be an Identifier when called, and if it is a coprocessor
2734/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002735ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002736parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002737 SMLoc S = Parser.getTok().getLoc();
2738 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002739 if (Tok.isNot(AsmToken::Identifier))
2740 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002741
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002742 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002743 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002744 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002745
2746 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002747 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002748 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002749}
2750
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002751/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002752/// token must be an Identifier when called, and if it is a coprocessor
2753/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002754ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002755parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002756 SMLoc S = Parser.getTok().getLoc();
2757 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002758 if (Tok.isNot(AsmToken::Identifier))
2759 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002760
2761 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2762 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002763 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002764
2765 Parser.Lex(); // Eat identifier token.
2766 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002767 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002768}
2769
Jim Grosbach48399582011-10-12 17:34:41 +00002770/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2771/// coproc_option : '{' imm0_255 '}'
2772ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2773parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2774 SMLoc S = Parser.getTok().getLoc();
2775
2776 // If this isn't a '{', this isn't a coprocessor immediate operand.
2777 if (Parser.getTok().isNot(AsmToken::LCurly))
2778 return MatchOperand_NoMatch;
2779 Parser.Lex(); // Eat the '{'
2780
2781 const MCExpr *Expr;
2782 SMLoc Loc = Parser.getTok().getLoc();
2783 if (getParser().ParseExpression(Expr)) {
2784 Error(Loc, "illegal expression");
2785 return MatchOperand_ParseFail;
2786 }
2787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2788 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2789 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2790 return MatchOperand_ParseFail;
2791 }
2792 int Val = CE->getValue();
2793
2794 // Check for and consume the closing '}'
2795 if (Parser.getTok().isNot(AsmToken::RCurly))
2796 return MatchOperand_ParseFail;
2797 SMLoc E = Parser.getTok().getLoc();
2798 Parser.Lex(); // Eat the '}'
2799
2800 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2801 return MatchOperand_Success;
2802}
2803
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002804// For register list parsing, we need to map from raw GPR register numbering
2805// to the enumeration values. The enumeration values aren't sorted by
2806// register number due to our using "sp", "lr" and "pc" as canonical names.
2807static unsigned getNextRegister(unsigned Reg) {
2808 // If this is a GPR, we need to do it manually, otherwise we can rely
2809 // on the sort ordering of the enumeration since the other reg-classes
2810 // are sane.
2811 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2812 return Reg + 1;
2813 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002814 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002815 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2816 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2817 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2818 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2819 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2820 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2821 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2822 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2823 }
2824}
2825
Jim Grosbach85a23432011-11-11 21:27:40 +00002826// Return the low-subreg of a given Q register.
2827static unsigned getDRegFromQReg(unsigned QReg) {
2828 switch (QReg) {
2829 default: llvm_unreachable("expected a Q register!");
2830 case ARM::Q0: return ARM::D0;
2831 case ARM::Q1: return ARM::D2;
2832 case ARM::Q2: return ARM::D4;
2833 case ARM::Q3: return ARM::D6;
2834 case ARM::Q4: return ARM::D8;
2835 case ARM::Q5: return ARM::D10;
2836 case ARM::Q6: return ARM::D12;
2837 case ARM::Q7: return ARM::D14;
2838 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002839 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002840 case ARM::Q10: return ARM::D20;
2841 case ARM::Q11: return ARM::D22;
2842 case ARM::Q12: return ARM::D24;
2843 case ARM::Q13: return ARM::D26;
2844 case ARM::Q14: return ARM::D28;
2845 case ARM::Q15: return ARM::D30;
2846 }
2847}
2848
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002849/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002850bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002851parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002852 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002853 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00002854 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002855 Parser.Lex(); // Eat '{' token.
2856 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00002857
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002858 // Check the first register in the list to see what register class
2859 // this is a list of.
2860 int Reg = tryParseRegister();
2861 if (Reg == -1)
2862 return Error(RegLoc, "register expected");
2863
Jim Grosbach85a23432011-11-11 21:27:40 +00002864 // The reglist instructions have at most 16 registers, so reserve
2865 // space for that many.
2866 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2867
2868 // Allow Q regs and just interpret them as the two D sub-registers.
2869 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2870 Reg = getDRegFromQReg(Reg);
2871 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2872 ++Reg;
2873 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002874 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002875 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2876 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2877 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2878 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2879 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2880 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2881 else
2882 return Error(RegLoc, "invalid register in register list");
2883
Jim Grosbach85a23432011-11-11 21:27:40 +00002884 // Store the register.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002885 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbya2b99102009-10-09 21:12:28 +00002886
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002887 // This starts immediately after the first register token in the list,
2888 // so we can see either a comma or a minus (range separator) as a legal
2889 // next token.
2890 while (Parser.getTok().is(AsmToken::Comma) ||
2891 Parser.getTok().is(AsmToken::Minus)) {
2892 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00002893 Parser.Lex(); // Eat the minus.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002894 SMLoc EndLoc = Parser.getTok().getLoc();
2895 int EndReg = tryParseRegister();
2896 if (EndReg == -1)
2897 return Error(EndLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002898 // Allow Q regs and just interpret them as the two D sub-registers.
2899 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2900 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002901 // If the register is the same as the start reg, there's nothing
2902 // more to do.
2903 if (Reg == EndReg)
2904 continue;
2905 // The register must be in the same register class as the first.
2906 if (!RC->contains(EndReg))
2907 return Error(EndLoc, "invalid register in register list");
2908 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002909 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002910 return Error(EndLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00002911
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002912 // Add all the registers in the range to the register list.
2913 while (Reg != EndReg) {
2914 Reg = getNextRegister(Reg);
2915 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2916 }
2917 continue;
2918 }
2919 Parser.Lex(); // Eat the comma.
2920 RegLoc = Parser.getTok().getLoc();
2921 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00002922 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002923 Reg = tryParseRegister();
2924 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00002925 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002926 // Allow Q regs and just interpret them as the two D sub-registers.
2927 bool isQReg = false;
2928 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2929 Reg = getDRegFromQReg(Reg);
2930 isQReg = true;
2931 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002932 // The register must be in the same register class as the first.
2933 if (!RC->contains(Reg))
2934 return Error(RegLoc, "invalid register in register list");
2935 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002936 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00002937 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2938 Warning(RegLoc, "register list not in ascending order");
2939 else
2940 return Error(RegLoc, "register list not in ascending order");
2941 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00002942 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00002943 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2944 ") in register list");
2945 continue;
2946 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002947 // VFP register lists must also be contiguous.
2948 // It's OK to use the enumeration values directly here rather, as the
2949 // VFP register classes have the enum sorted properly.
2950 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2951 Reg != OldReg + 1)
2952 return Error(RegLoc, "non-contiguous register range");
2953 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbach85a23432011-11-11 21:27:40 +00002954 if (isQReg)
2955 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge18980a2010-11-06 22:36:58 +00002956 }
2957
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002958 SMLoc E = Parser.getTok().getLoc();
2959 if (Parser.getTok().isNot(AsmToken::RCurly))
2960 return Error(E, "'}' expected");
2961 Parser.Lex(); // Eat '}' token.
2962
Jim Grosbach18bf3632011-12-13 21:48:29 +00002963 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00002964 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00002965
2966 // The ARM system instruction variants for LDM/STM have a '^' token here.
2967 if (Parser.getTok().is(AsmToken::Caret)) {
2968 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2969 Parser.Lex(); // Eat '^' token.
2970 }
2971
Bill Wendling2063b842010-11-18 23:43:05 +00002972 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00002973}
2974
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002975// Helper function to parse the lane index for vector lists.
2976ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach04945c42011-12-02 00:35:16 +00002977parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2978 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002979 if (Parser.getTok().is(AsmToken::LBrac)) {
2980 Parser.Lex(); // Eat the '['.
2981 if (Parser.getTok().is(AsmToken::RBrac)) {
2982 // "Dn[]" is the 'all lanes' syntax.
2983 LaneKind = AllLanes;
2984 Parser.Lex(); // Eat the ']'.
2985 return MatchOperand_Success;
2986 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00002987
2988 // There's an optional '#' token here. Normally there wouldn't be, but
2989 // inline assemble puts one in, and it's friendly to accept that.
2990 if (Parser.getTok().is(AsmToken::Hash))
2991 Parser.Lex(); // Eat the '#'
2992
Jim Grosbach7de7ab82011-12-21 01:19:23 +00002993 const MCExpr *LaneIndex;
2994 SMLoc Loc = Parser.getTok().getLoc();
2995 if (getParser().ParseExpression(LaneIndex)) {
2996 Error(Loc, "illegal expression");
2997 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00002998 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00002999 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3000 if (!CE) {
3001 Error(Loc, "lane index must be empty or an integer");
3002 return MatchOperand_ParseFail;
3003 }
3004 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3005 Error(Parser.getTok().getLoc(), "']' expected");
3006 return MatchOperand_ParseFail;
3007 }
3008 Parser.Lex(); // Eat the ']'.
3009 int64_t Val = CE->getValue();
3010
3011 // FIXME: Make this range check context sensitive for .8, .16, .32.
3012 if (Val < 0 || Val > 7) {
3013 Error(Parser.getTok().getLoc(), "lane index out of range");
3014 return MatchOperand_ParseFail;
3015 }
3016 Index = Val;
3017 LaneKind = IndexedLane;
3018 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003019 }
3020 LaneKind = NoLanes;
3021 return MatchOperand_Success;
3022}
3023
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003024// parse a vector register list
3025ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3026parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003027 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003028 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003029 SMLoc S = Parser.getTok().getLoc();
3030 // As an extension (to match gas), support a plain D register or Q register
3031 // (without encosing curly braces) as a single or double entry list,
3032 // respectively.
3033 if (Parser.getTok().is(AsmToken::Identifier)) {
3034 int Reg = tryParseRegister();
3035 if (Reg == -1)
3036 return MatchOperand_NoMatch;
3037 SMLoc E = Parser.getTok().getLoc();
3038 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003039 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003040 if (Res != MatchOperand_Success)
3041 return Res;
3042 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003043 case NoLanes:
3044 E = Parser.getTok().getLoc();
Jim Grosbach2f50e922011-12-15 21:44:33 +00003045 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003046 break;
3047 case AllLanes:
3048 E = Parser.getTok().getLoc();
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003049 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3050 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003051 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003052 case IndexedLane:
3053 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003054 LaneIndex,
3055 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003056 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003057 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003058 return MatchOperand_Success;
3059 }
3060 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3061 Reg = getDRegFromQReg(Reg);
Jim Grosbach04945c42011-12-02 00:35:16 +00003062 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003063 if (Res != MatchOperand_Success)
3064 return Res;
3065 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003066 case NoLanes:
3067 E = Parser.getTok().getLoc();
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003068 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003069 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003070 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003071 break;
3072 case AllLanes:
3073 E = Parser.getTok().getLoc();
Jim Grosbach13a292c2012-03-06 22:01:44 +00003074 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3075 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003076 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3077 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003078 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003079 case IndexedLane:
3080 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003081 LaneIndex,
3082 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003083 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003084 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003085 return MatchOperand_Success;
3086 }
3087 Error(S, "vector register expected");
3088 return MatchOperand_ParseFail;
3089 }
3090
3091 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003092 return MatchOperand_NoMatch;
3093
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003094 Parser.Lex(); // Eat '{' token.
3095 SMLoc RegLoc = Parser.getTok().getLoc();
3096
3097 int Reg = tryParseRegister();
3098 if (Reg == -1) {
3099 Error(RegLoc, "register expected");
3100 return MatchOperand_ParseFail;
3101 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003102 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003103 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003104 unsigned FirstReg = Reg;
3105 // The list is of D registers, but we also allow Q regs and just interpret
3106 // them as the two D sub-registers.
3107 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3108 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003109 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3110 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003111 ++Reg;
3112 ++Count;
3113 }
Jim Grosbach04945c42011-12-02 00:35:16 +00003114 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003115 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003116
Jim Grosbache891fe82011-11-15 23:19:15 +00003117 while (Parser.getTok().is(AsmToken::Comma) ||
3118 Parser.getTok().is(AsmToken::Minus)) {
3119 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003120 if (!Spacing)
3121 Spacing = 1; // Register range implies a single spaced list.
3122 else if (Spacing == 2) {
3123 Error(Parser.getTok().getLoc(),
3124 "sequential registers in double spaced list");
3125 return MatchOperand_ParseFail;
3126 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003127 Parser.Lex(); // Eat the minus.
3128 SMLoc EndLoc = Parser.getTok().getLoc();
3129 int EndReg = tryParseRegister();
3130 if (EndReg == -1) {
3131 Error(EndLoc, "register expected");
3132 return MatchOperand_ParseFail;
3133 }
3134 // Allow Q regs and just interpret them as the two D sub-registers.
3135 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3136 EndReg = getDRegFromQReg(EndReg) + 1;
3137 // If the register is the same as the start reg, there's nothing
3138 // more to do.
3139 if (Reg == EndReg)
3140 continue;
3141 // The register must be in the same register class as the first.
3142 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3143 Error(EndLoc, "invalid register in register list");
3144 return MatchOperand_ParseFail;
3145 }
3146 // Ranges must go from low to high.
3147 if (Reg > EndReg) {
3148 Error(EndLoc, "bad range in register list");
3149 return MatchOperand_ParseFail;
3150 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003151 // Parse the lane specifier if present.
3152 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003153 unsigned NextLaneIndex;
3154 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003155 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003156 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003157 Error(EndLoc, "mismatched lane index in register list");
3158 return MatchOperand_ParseFail;
3159 }
3160 EndLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003161
3162 // Add all the registers in the range to the register list.
3163 Count += EndReg - Reg;
3164 Reg = EndReg;
3165 continue;
3166 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003167 Parser.Lex(); // Eat the comma.
3168 RegLoc = Parser.getTok().getLoc();
3169 int OldReg = Reg;
3170 Reg = tryParseRegister();
3171 if (Reg == -1) {
3172 Error(RegLoc, "register expected");
3173 return MatchOperand_ParseFail;
3174 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003175 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003176 // It's OK to use the enumeration values directly here rather, as the
3177 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003178 //
3179 // The list is of D registers, but we also allow Q regs and just interpret
3180 // them as the two D sub-registers.
3181 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003182 if (!Spacing)
3183 Spacing = 1; // Register range implies a single spaced list.
3184 else if (Spacing == 2) {
3185 Error(RegLoc,
3186 "invalid register in double-spaced list (must be 'D' register')");
3187 return MatchOperand_ParseFail;
3188 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003189 Reg = getDRegFromQReg(Reg);
3190 if (Reg != OldReg + 1) {
3191 Error(RegLoc, "non-contiguous register range");
3192 return MatchOperand_ParseFail;
3193 }
3194 ++Reg;
3195 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003196 // Parse the lane specifier if present.
3197 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003198 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003199 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach04945c42011-12-02 00:35:16 +00003200 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003201 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003202 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003203 Error(EndLoc, "mismatched lane index in register list");
3204 return MatchOperand_ParseFail;
3205 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003206 continue;
3207 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003208 // Normal D register.
3209 // Figure out the register spacing (single or double) of the list if
3210 // we don't know it already.
3211 if (!Spacing)
3212 Spacing = 1 + (Reg == OldReg + 2);
3213
3214 // Just check that it's contiguous and keep going.
3215 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003216 Error(RegLoc, "non-contiguous register range");
3217 return MatchOperand_ParseFail;
3218 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003219 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003220 // Parse the lane specifier if present.
3221 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003222 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003223 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach04945c42011-12-02 00:35:16 +00003224 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003225 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003226 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003227 Error(EndLoc, "mismatched lane index in register list");
3228 return MatchOperand_ParseFail;
3229 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003230 }
3231
3232 SMLoc E = Parser.getTok().getLoc();
3233 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3234 Error(E, "'}' expected");
3235 return MatchOperand_ParseFail;
3236 }
3237 Parser.Lex(); // Eat '}' token.
3238
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003239 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003240 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003241 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003242 // composite register classes.
3243 if (Count == 2) {
3244 const MCRegisterClass *RC = (Spacing == 1) ?
3245 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3246 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3247 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3248 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003249
Jim Grosbach2f50e922011-12-15 21:44:33 +00003250 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3251 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003252 break;
3253 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003254 // Two-register operands have been converted to the
3255 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003256 if (Count == 2) {
3257 const MCRegisterClass *RC = (Spacing == 1) ?
3258 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3259 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003260 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3261 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003262 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003263 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003264 S, E));
3265 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003266 case IndexedLane:
3267 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003268 LaneIndex,
3269 (Spacing == 2),
3270 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003271 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003272 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003273 return MatchOperand_Success;
3274}
3275
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003276/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003277ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003278parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003279 SMLoc S = Parser.getTok().getLoc();
3280 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003281 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003282
Jiangning Liu288e1af2012-08-02 08:21:27 +00003283 if (Tok.is(AsmToken::Identifier)) {
3284 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003285
Jiangning Liu288e1af2012-08-02 08:21:27 +00003286 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3287 .Case("sy", ARM_MB::SY)
3288 .Case("st", ARM_MB::ST)
3289 .Case("sh", ARM_MB::ISH)
3290 .Case("ish", ARM_MB::ISH)
3291 .Case("shst", ARM_MB::ISHST)
3292 .Case("ishst", ARM_MB::ISHST)
3293 .Case("nsh", ARM_MB::NSH)
3294 .Case("un", ARM_MB::NSH)
3295 .Case("nshst", ARM_MB::NSHST)
3296 .Case("unst", ARM_MB::NSHST)
3297 .Case("osh", ARM_MB::OSH)
3298 .Case("oshst", ARM_MB::OSHST)
3299 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003300
Jiangning Liu288e1af2012-08-02 08:21:27 +00003301 if (Opt == ~0U)
3302 return MatchOperand_NoMatch;
3303
3304 Parser.Lex(); // Eat identifier token.
3305 } else if (Tok.is(AsmToken::Hash) ||
3306 Tok.is(AsmToken::Dollar) ||
3307 Tok.is(AsmToken::Integer)) {
3308 if (Parser.getTok().isNot(AsmToken::Integer))
3309 Parser.Lex(); // Eat the '#'.
3310 SMLoc Loc = Parser.getTok().getLoc();
3311
3312 const MCExpr *MemBarrierID;
3313 if (getParser().ParseExpression(MemBarrierID)) {
3314 Error(Loc, "illegal expression");
3315 return MatchOperand_ParseFail;
3316 }
3317
3318 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3319 if (!CE) {
3320 Error(Loc, "constant expression expected");
3321 return MatchOperand_ParseFail;
3322 }
3323
3324 int Val = CE->getValue();
3325 if (Val & ~0xf) {
3326 Error(Loc, "immediate value out of range");
3327 return MatchOperand_ParseFail;
3328 }
3329
3330 Opt = ARM_MB::RESERVED_0 + Val;
3331 } else
3332 return MatchOperand_ParseFail;
3333
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003334 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003335 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003336}
3337
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003338/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003339ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003340parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003341 SMLoc S = Parser.getTok().getLoc();
3342 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003343 if (!Tok.is(AsmToken::Identifier))
3344 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003345 StringRef IFlagsStr = Tok.getString();
3346
Owen Anderson10c5b122011-10-05 17:16:40 +00003347 // An iflags string of "none" is interpreted to mean that none of the AIF
3348 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003349 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003350 if (IFlagsStr != "none") {
3351 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3352 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3353 .Case("a", ARM_PROC::A)
3354 .Case("i", ARM_PROC::I)
3355 .Case("f", ARM_PROC::F)
3356 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003357
Owen Anderson10c5b122011-10-05 17:16:40 +00003358 // If some specific iflag is already set, it means that some letter is
3359 // present more than once, this is not acceptable.
3360 if (Flag == ~0U || (IFlags & Flag))
3361 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003362
Owen Anderson10c5b122011-10-05 17:16:40 +00003363 IFlags |= Flag;
3364 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003365 }
3366
3367 Parser.Lex(); // Eat identifier token.
3368 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3369 return MatchOperand_Success;
3370}
3371
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003372/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003373ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003374parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003375 SMLoc S = Parser.getTok().getLoc();
3376 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003377 if (!Tok.is(AsmToken::Identifier))
3378 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003379 StringRef Mask = Tok.getString();
3380
James Molloy21efa7d2011-09-28 14:21:38 +00003381 if (isMClass()) {
3382 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003383 std::string Name = Mask.lower();
3384 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003385 // Note: in the documentation:
3386 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3387 // for MSR APSR_nzcvq.
3388 // but we do make it an alias here. This is so to get the "mask encoding"
3389 // bits correct on MSR APSR writes.
3390 //
3391 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3392 // should really only be allowed when writing a special register. Note
3393 // they get dropped in the MRS instruction reading a special register as
3394 // the SYSm field is only 8 bits.
3395 //
3396 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3397 // includes the DSP extension but that is not checked.
3398 .Case("apsr", 0x800)
3399 .Case("apsr_nzcvq", 0x800)
3400 .Case("apsr_g", 0x400)
3401 .Case("apsr_nzcvqg", 0xc00)
3402 .Case("iapsr", 0x801)
3403 .Case("iapsr_nzcvq", 0x801)
3404 .Case("iapsr_g", 0x401)
3405 .Case("iapsr_nzcvqg", 0xc01)
3406 .Case("eapsr", 0x802)
3407 .Case("eapsr_nzcvq", 0x802)
3408 .Case("eapsr_g", 0x402)
3409 .Case("eapsr_nzcvqg", 0xc02)
3410 .Case("xpsr", 0x803)
3411 .Case("xpsr_nzcvq", 0x803)
3412 .Case("xpsr_g", 0x403)
3413 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003414 .Case("ipsr", 0x805)
3415 .Case("epsr", 0x806)
3416 .Case("iepsr", 0x807)
3417 .Case("msp", 0x808)
3418 .Case("psp", 0x809)
3419 .Case("primask", 0x810)
3420 .Case("basepri", 0x811)
3421 .Case("basepri_max", 0x812)
3422 .Case("faultmask", 0x813)
3423 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003424 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003425
James Molloy21efa7d2011-09-28 14:21:38 +00003426 if (FlagsVal == ~0U)
3427 return MatchOperand_NoMatch;
3428
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003429 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003430 // basepri, basepri_max and faultmask only valid for V7m.
3431 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003432
James Molloy21efa7d2011-09-28 14:21:38 +00003433 Parser.Lex(); // Eat identifier token.
3434 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3435 return MatchOperand_Success;
3436 }
3437
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003438 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3439 size_t Start = 0, Next = Mask.find('_');
3440 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003441 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003442 if (Next != StringRef::npos)
3443 Flags = Mask.slice(Next+1, Mask.size());
3444
3445 // FlagsVal contains the complete mask:
3446 // 3-0: Mask
3447 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3448 unsigned FlagsVal = 0;
3449
3450 if (SpecReg == "apsr") {
3451 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003452 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003453 .Case("g", 0x4) // same as CPSR_s
3454 .Case("nzcvqg", 0xc) // same as CPSR_fs
3455 .Default(~0U);
3456
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003457 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003458 if (!Flags.empty())
3459 return MatchOperand_NoMatch;
3460 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003461 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003462 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003463 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003464 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3465 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003466 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003467 for (int i = 0, e = Flags.size(); i != e; ++i) {
3468 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3469 .Case("c", 1)
3470 .Case("x", 2)
3471 .Case("s", 4)
3472 .Case("f", 8)
3473 .Default(~0U);
3474
3475 // If some specific flag is already set, it means that some letter is
3476 // present more than once, this is not acceptable.
3477 if (FlagsVal == ~0U || (FlagsVal & Flag))
3478 return MatchOperand_NoMatch;
3479 FlagsVal |= Flag;
3480 }
3481 } else // No match for special register.
3482 return MatchOperand_NoMatch;
3483
Owen Anderson03a173e2011-10-21 18:43:28 +00003484 // Special register without flags is NOT equivalent to "fc" flags.
3485 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3486 // two lines would enable gas compatibility at the expense of breaking
3487 // round-tripping.
3488 //
3489 // if (!FlagsVal)
3490 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003491
3492 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3493 if (SpecReg == "spsr")
3494 FlagsVal |= 16;
3495
3496 Parser.Lex(); // Eat identifier token.
3497 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3498 return MatchOperand_Success;
3499}
3500
Jim Grosbach27c1e252011-07-21 17:23:04 +00003501ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3502parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3503 int Low, int High) {
3504 const AsmToken &Tok = Parser.getTok();
3505 if (Tok.isNot(AsmToken::Identifier)) {
3506 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3507 return MatchOperand_ParseFail;
3508 }
3509 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003510 std::string LowerOp = Op.lower();
3511 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003512 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3513 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3514 return MatchOperand_ParseFail;
3515 }
3516 Parser.Lex(); // Eat shift type token.
3517
3518 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003519 if (Parser.getTok().isNot(AsmToken::Hash) &&
3520 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003521 Error(Parser.getTok().getLoc(), "'#' expected");
3522 return MatchOperand_ParseFail;
3523 }
3524 Parser.Lex(); // Eat hash token.
3525
3526 const MCExpr *ShiftAmount;
3527 SMLoc Loc = Parser.getTok().getLoc();
3528 if (getParser().ParseExpression(ShiftAmount)) {
3529 Error(Loc, "illegal expression");
3530 return MatchOperand_ParseFail;
3531 }
3532 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3533 if (!CE) {
3534 Error(Loc, "constant expression expected");
3535 return MatchOperand_ParseFail;
3536 }
3537 int Val = CE->getValue();
3538 if (Val < Low || Val > High) {
3539 Error(Loc, "immediate value out of range");
3540 return MatchOperand_ParseFail;
3541 }
3542
3543 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3544
3545 return MatchOperand_Success;
3546}
3547
Jim Grosbach0a547702011-07-22 17:44:50 +00003548ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3549parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3550 const AsmToken &Tok = Parser.getTok();
3551 SMLoc S = Tok.getLoc();
3552 if (Tok.isNot(AsmToken::Identifier)) {
3553 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3554 return MatchOperand_ParseFail;
3555 }
3556 int Val = StringSwitch<int>(Tok.getString())
3557 .Case("be", 1)
3558 .Case("le", 0)
3559 .Default(-1);
3560 Parser.Lex(); // Eat the token.
3561
3562 if (Val == -1) {
3563 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3564 return MatchOperand_ParseFail;
3565 }
3566 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3567 getContext()),
3568 S, Parser.getTok().getLoc()));
3569 return MatchOperand_Success;
3570}
3571
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003572/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3573/// instructions. Legal values are:
3574/// lsl #n 'n' in [0,31]
3575/// asr #n 'n' in [1,32]
3576/// n == 32 encoded as n == 0.
3577ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3578parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3579 const AsmToken &Tok = Parser.getTok();
3580 SMLoc S = Tok.getLoc();
3581 if (Tok.isNot(AsmToken::Identifier)) {
3582 Error(S, "shift operator 'asr' or 'lsl' expected");
3583 return MatchOperand_ParseFail;
3584 }
3585 StringRef ShiftName = Tok.getString();
3586 bool isASR;
3587 if (ShiftName == "lsl" || ShiftName == "LSL")
3588 isASR = false;
3589 else if (ShiftName == "asr" || ShiftName == "ASR")
3590 isASR = true;
3591 else {
3592 Error(S, "shift operator 'asr' or 'lsl' expected");
3593 return MatchOperand_ParseFail;
3594 }
3595 Parser.Lex(); // Eat the operator.
3596
3597 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003598 if (Parser.getTok().isNot(AsmToken::Hash) &&
3599 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003600 Error(Parser.getTok().getLoc(), "'#' expected");
3601 return MatchOperand_ParseFail;
3602 }
3603 Parser.Lex(); // Eat hash token.
3604
3605 const MCExpr *ShiftAmount;
3606 SMLoc E = Parser.getTok().getLoc();
3607 if (getParser().ParseExpression(ShiftAmount)) {
3608 Error(E, "malformed shift expression");
3609 return MatchOperand_ParseFail;
3610 }
3611 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3612 if (!CE) {
3613 Error(E, "shift amount must be an immediate");
3614 return MatchOperand_ParseFail;
3615 }
3616
3617 int64_t Val = CE->getValue();
3618 if (isASR) {
3619 // Shift amount must be in [1,32]
3620 if (Val < 1 || Val > 32) {
3621 Error(E, "'asr' shift amount must be in range [1,32]");
3622 return MatchOperand_ParseFail;
3623 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003624 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3625 if (isThumb() && Val == 32) {
3626 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3627 return MatchOperand_ParseFail;
3628 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003629 if (Val == 32) Val = 0;
3630 } else {
3631 // Shift amount must be in [1,32]
3632 if (Val < 0 || Val > 31) {
3633 Error(E, "'lsr' shift amount must be in range [0,31]");
3634 return MatchOperand_ParseFail;
3635 }
3636 }
3637
3638 E = Parser.getTok().getLoc();
3639 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3640
3641 return MatchOperand_Success;
3642}
3643
Jim Grosbach833b9d32011-07-27 20:15:40 +00003644/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3645/// of instructions. Legal values are:
3646/// ror #n 'n' in {0, 8, 16, 24}
3647ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3648parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3649 const AsmToken &Tok = Parser.getTok();
3650 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003651 if (Tok.isNot(AsmToken::Identifier))
3652 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003653 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003654 if (ShiftName != "ror" && ShiftName != "ROR")
3655 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003656 Parser.Lex(); // Eat the operator.
3657
3658 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003659 if (Parser.getTok().isNot(AsmToken::Hash) &&
3660 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003661 Error(Parser.getTok().getLoc(), "'#' expected");
3662 return MatchOperand_ParseFail;
3663 }
3664 Parser.Lex(); // Eat hash token.
3665
3666 const MCExpr *ShiftAmount;
3667 SMLoc E = Parser.getTok().getLoc();
3668 if (getParser().ParseExpression(ShiftAmount)) {
3669 Error(E, "malformed rotate expression");
3670 return MatchOperand_ParseFail;
3671 }
3672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3673 if (!CE) {
3674 Error(E, "rotate amount must be an immediate");
3675 return MatchOperand_ParseFail;
3676 }
3677
3678 int64_t Val = CE->getValue();
3679 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3680 // normally, zero is represented in asm by omitting the rotate operand
3681 // entirely.
3682 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3683 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3684 return MatchOperand_ParseFail;
3685 }
3686
3687 E = Parser.getTok().getLoc();
3688 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3689
3690 return MatchOperand_Success;
3691}
3692
Jim Grosbach864b6092011-07-28 21:34:26 +00003693ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3694parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3695 SMLoc S = Parser.getTok().getLoc();
3696 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003697 if (Parser.getTok().isNot(AsmToken::Hash) &&
3698 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003699 Error(Parser.getTok().getLoc(), "'#' expected");
3700 return MatchOperand_ParseFail;
3701 }
3702 Parser.Lex(); // Eat hash token.
3703
3704 const MCExpr *LSBExpr;
3705 SMLoc E = Parser.getTok().getLoc();
3706 if (getParser().ParseExpression(LSBExpr)) {
3707 Error(E, "malformed immediate expression");
3708 return MatchOperand_ParseFail;
3709 }
3710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3711 if (!CE) {
3712 Error(E, "'lsb' operand must be an immediate");
3713 return MatchOperand_ParseFail;
3714 }
3715
3716 int64_t LSB = CE->getValue();
3717 // The LSB must be in the range [0,31]
3718 if (LSB < 0 || LSB > 31) {
3719 Error(E, "'lsb' operand must be in the range [0,31]");
3720 return MatchOperand_ParseFail;
3721 }
3722 E = Parser.getTok().getLoc();
3723
3724 // Expect another immediate operand.
3725 if (Parser.getTok().isNot(AsmToken::Comma)) {
3726 Error(Parser.getTok().getLoc(), "too few operands");
3727 return MatchOperand_ParseFail;
3728 }
3729 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003730 if (Parser.getTok().isNot(AsmToken::Hash) &&
3731 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003732 Error(Parser.getTok().getLoc(), "'#' expected");
3733 return MatchOperand_ParseFail;
3734 }
3735 Parser.Lex(); // Eat hash token.
3736
3737 const MCExpr *WidthExpr;
3738 if (getParser().ParseExpression(WidthExpr)) {
3739 Error(E, "malformed immediate expression");
3740 return MatchOperand_ParseFail;
3741 }
3742 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3743 if (!CE) {
3744 Error(E, "'width' operand must be an immediate");
3745 return MatchOperand_ParseFail;
3746 }
3747
3748 int64_t Width = CE->getValue();
3749 // The LSB must be in the range [1,32-lsb]
3750 if (Width < 1 || Width > 32 - LSB) {
3751 Error(E, "'width' operand must be in the range [1,32-lsb]");
3752 return MatchOperand_ParseFail;
3753 }
3754 E = Parser.getTok().getLoc();
3755
3756 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3757
3758 return MatchOperand_Success;
3759}
3760
Jim Grosbachd3595712011-08-03 23:50:40 +00003761ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3762parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3763 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003764 // postidx_reg := '+' register {, shift}
3765 // | '-' register {, shift}
3766 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003767
3768 // This method must return MatchOperand_NoMatch without consuming any tokens
3769 // in the case where there is no match, as other alternatives take other
3770 // parse methods.
3771 AsmToken Tok = Parser.getTok();
3772 SMLoc S = Tok.getLoc();
3773 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003774 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003775 int Reg = -1;
3776 if (Tok.is(AsmToken::Plus)) {
3777 Parser.Lex(); // Eat the '+' token.
3778 haveEaten = true;
3779 } else if (Tok.is(AsmToken::Minus)) {
3780 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003781 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003782 haveEaten = true;
3783 }
3784 if (Parser.getTok().is(AsmToken::Identifier))
3785 Reg = tryParseRegister();
3786 if (Reg == -1) {
3787 if (!haveEaten)
3788 return MatchOperand_NoMatch;
3789 Error(Parser.getTok().getLoc(), "register expected");
3790 return MatchOperand_ParseFail;
3791 }
3792 SMLoc E = Parser.getTok().getLoc();
3793
Jim Grosbachc320c852011-08-05 21:28:30 +00003794 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3795 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003796 if (Parser.getTok().is(AsmToken::Comma)) {
3797 Parser.Lex(); // Eat the ','.
3798 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3799 return MatchOperand_ParseFail;
3800 }
Jim Grosbachc320c852011-08-05 21:28:30 +00003801
3802 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3803 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00003804
3805 return MatchOperand_Success;
3806}
3807
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003808ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3809parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3810 // Check for a post-index addressing register operand. Specifically:
3811 // am3offset := '+' register
3812 // | '-' register
3813 // | register
3814 // | # imm
3815 // | # + imm
3816 // | # - imm
3817
3818 // This method must return MatchOperand_NoMatch without consuming any tokens
3819 // in the case where there is no match, as other alternatives take other
3820 // parse methods.
3821 AsmToken Tok = Parser.getTok();
3822 SMLoc S = Tok.getLoc();
3823
3824 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003825 if (Parser.getTok().is(AsmToken::Hash) ||
3826 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003827 Parser.Lex(); // Eat the '#'.
3828 // Explicitly look for a '-', as we need to encode negative zero
3829 // differently.
3830 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3831 const MCExpr *Offset;
3832 if (getParser().ParseExpression(Offset))
3833 return MatchOperand_ParseFail;
3834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3835 if (!CE) {
3836 Error(S, "constant expression expected");
3837 return MatchOperand_ParseFail;
3838 }
3839 SMLoc E = Tok.getLoc();
3840 // Negative zero is encoded as the flag value INT32_MIN.
3841 int32_t Val = CE->getValue();
3842 if (isNegative && Val == 0)
3843 Val = INT32_MIN;
3844
3845 Operands.push_back(
3846 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3847
3848 return MatchOperand_Success;
3849 }
3850
3851
3852 bool haveEaten = false;
3853 bool isAdd = true;
3854 int Reg = -1;
3855 if (Tok.is(AsmToken::Plus)) {
3856 Parser.Lex(); // Eat the '+' token.
3857 haveEaten = true;
3858 } else if (Tok.is(AsmToken::Minus)) {
3859 Parser.Lex(); // Eat the '-' token.
3860 isAdd = false;
3861 haveEaten = true;
3862 }
3863 if (Parser.getTok().is(AsmToken::Identifier))
3864 Reg = tryParseRegister();
3865 if (Reg == -1) {
3866 if (!haveEaten)
3867 return MatchOperand_NoMatch;
3868 Error(Parser.getTok().getLoc(), "register expected");
3869 return MatchOperand_ParseFail;
3870 }
3871 SMLoc E = Parser.getTok().getLoc();
3872
3873 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3874 0, S, E));
3875
3876 return MatchOperand_Success;
3877}
3878
Jim Grosbach7db8d692011-09-08 22:07:06 +00003879/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3880/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3881/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003882void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003883cvtT2LdrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003884 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3885 // Rt, Rt2
3886 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3887 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3888 // Create a writeback register dummy placeholder.
3889 Inst.addOperand(MCOperand::CreateReg(0));
3890 // addr
3891 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3892 // pred
3893 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003894}
3895
3896/// cvtT2StrdPre - Convert parsed operands to MCInst.
3897/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3898/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003899void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003900cvtT2StrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003901 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3902 // Create a writeback register dummy placeholder.
3903 Inst.addOperand(MCOperand::CreateReg(0));
3904 // Rt, Rt2
3905 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3906 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3907 // addr
3908 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3909 // pred
3910 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003911}
3912
Jim Grosbachc086f682011-09-08 00:39:19 +00003913/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3914/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3915/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003916void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003917cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +00003918 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3919 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3920
3921 // Create a writeback register dummy placeholder.
3922 Inst.addOperand(MCOperand::CreateImm(0));
3923
3924 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3925 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachc086f682011-09-08 00:39:19 +00003926}
3927
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003928/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3929/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3930/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003931void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003932cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003933 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3934 // Create a writeback register dummy placeholder.
3935 Inst.addOperand(MCOperand::CreateImm(0));
3936 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3937 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3938 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003939}
3940
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003941/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003942/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3943/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003944void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003945cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003946 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3947 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3948
3949 // Create a writeback register dummy placeholder.
3950 Inst.addOperand(MCOperand::CreateImm(0));
3951
Jim Grosbachd3595712011-08-03 23:50:40 +00003952 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003953 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003954}
3955
Owen Anderson16d33f32011-08-26 20:43:14 +00003956/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3957/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3958/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003959void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003960cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +00003961 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3962 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3963
3964 // Create a writeback register dummy placeholder.
3965 Inst.addOperand(MCOperand::CreateImm(0));
3966
3967 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3968 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson16d33f32011-08-26 20:43:14 +00003969}
3970
3971
Jim Grosbachd564bf32011-08-11 19:22:40 +00003972/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3973/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3974/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003975void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003976cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +00003977 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3978 // Create a writeback register dummy placeholder.
3979 Inst.addOperand(MCOperand::CreateImm(0));
3980 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3981 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3982 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd564bf32011-08-11 19:22:40 +00003983}
3984
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003985/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003986/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3987/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003988void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003989cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003990 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3991 // Create a writeback register dummy placeholder.
3992 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd564bf32011-08-11 19:22:40 +00003993 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3994 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3995 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00003996}
3997
Jim Grosbachd886f8c2011-08-11 21:17:22 +00003998/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3999/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4000/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004001void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004002cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004003 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4004 // Create a writeback register dummy placeholder.
4005 Inst.addOperand(MCOperand::CreateImm(0));
4006 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4007 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4008 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004009}
4010
Jim Grosbachd3595712011-08-03 23:50:40 +00004011/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4012/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4013/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004014void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004015cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004016 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4017 // Rt
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004018 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004019 // Create a writeback register dummy placeholder.
4020 Inst.addOperand(MCOperand::CreateImm(0));
4021 // addr
4022 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4023 // offset
4024 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4025 // pred
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004026 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004027}
4028
Jim Grosbachd3595712011-08-03 23:50:40 +00004029/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004030/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4031/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004032void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004033cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004034 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4035 // Rt
Owen Andersonb0e68992011-07-28 17:18:57 +00004036 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004037 // Create a writeback register dummy placeholder.
4038 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004039 // addr
4040 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4041 // offset
4042 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4043 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004044 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004045}
4046
Jim Grosbachd3595712011-08-03 23:50:40 +00004047/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004048/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4049/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004050void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004051cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004052 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004053 // Create a writeback register dummy placeholder.
4054 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004055 // Rt
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004056 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004057 // addr
4058 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4059 // offset
4060 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4061 // pred
4062 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004063}
4064
4065/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4066/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4067/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004068void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004069cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004070 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4071 // Create a writeback register dummy placeholder.
4072 Inst.addOperand(MCOperand::CreateImm(0));
4073 // Rt
4074 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4075 // addr
4076 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4077 // offset
4078 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4079 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004080 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004081}
4082
Jim Grosbach5b96b802011-08-10 20:29:19 +00004083/// cvtLdrdPre - Convert parsed operands to MCInst.
4084/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4085/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004086void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004087cvtLdrdPre(MCInst &Inst,
Jim Grosbach5b96b802011-08-10 20:29:19 +00004088 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4089 // Rt, Rt2
4090 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4091 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4092 // Create a writeback register dummy placeholder.
4093 Inst.addOperand(MCOperand::CreateImm(0));
4094 // addr
4095 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4096 // pred
4097 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach5b96b802011-08-10 20:29:19 +00004098}
4099
Jim Grosbacheb09f492011-08-11 20:28:23 +00004100/// cvtStrdPre - Convert parsed operands to MCInst.
4101/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4102/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004103void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004104cvtStrdPre(MCInst &Inst,
Jim Grosbacheb09f492011-08-11 20:28:23 +00004105 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4106 // Create a writeback register dummy placeholder.
4107 Inst.addOperand(MCOperand::CreateImm(0));
4108 // Rt, Rt2
4109 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4110 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4111 // addr
4112 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4113 // pred
4114 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheb09f492011-08-11 20:28:23 +00004115}
4116
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004117/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4118/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4119/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004120void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004121cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004122 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4123 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4124 // Create a writeback register dummy placeholder.
4125 Inst.addOperand(MCOperand::CreateImm(0));
4126 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4127 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004128}
4129
Chad Rosier5eec49f2012-08-30 23:00:00 +00004130/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach8e048492011-08-19 22:07:46 +00004131/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4132/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004133void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004134cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004135 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004136 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4137 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004138 // If we have a three-operand form, make sure to set Rn to be the operand
4139 // that isn't the same as Rd.
4140 unsigned RegOp = 4;
4141 if (Operands.size() == 6 &&
4142 ((ARMOperand*)Operands[4])->getReg() ==
4143 ((ARMOperand*)Operands[3])->getReg())
4144 RegOp = 5;
4145 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4146 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004147 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004148}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004149
Chad Rosier98cfa102012-08-31 00:03:31 +00004150void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004151cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004152 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4153 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004154 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004155 // Create a writeback register dummy placeholder.
4156 Inst.addOperand(MCOperand::CreateImm(0));
4157 // Vn
4158 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4159 // pred
4160 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004161}
4162
Chad Rosier98cfa102012-08-31 00:03:31 +00004163void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004164cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004165 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4166 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004167 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004168 // Create a writeback register dummy placeholder.
4169 Inst.addOperand(MCOperand::CreateImm(0));
4170 // Vn
4171 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4172 // Vm
4173 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4174 // pred
4175 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004176}
4177
Chad Rosier98cfa102012-08-31 00:03:31 +00004178void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004179cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004180 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4181 // Create a writeback register dummy placeholder.
4182 Inst.addOperand(MCOperand::CreateImm(0));
4183 // Vn
4184 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4185 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004186 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004187 // pred
4188 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004189}
4190
Chad Rosier98cfa102012-08-31 00:03:31 +00004191void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004192cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004193 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4194 // Create a writeback register dummy placeholder.
4195 Inst.addOperand(MCOperand::CreateImm(0));
4196 // Vn
4197 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4198 // Vm
4199 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4200 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004201 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004202 // pred
4203 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004204}
4205
Bill Wendlinge18980a2010-11-06 22:36:58 +00004206/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004207/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004208bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004209parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004210 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004211 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004212 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004213 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004214 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004215
Sean Callanan936b0d32010-01-19 21:44:56 +00004216 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004217 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004218 if (BaseRegNum == -1)
4219 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004220
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004221 // The next token must either be a comma or a closing bracket.
4222 const AsmToken &Tok = Parser.getTok();
4223 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004224 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004225
Jim Grosbachd3595712011-08-03 23:50:40 +00004226 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004227 E = Tok.getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004228 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004229
Jim Grosbachd3595712011-08-03 23:50:40 +00004230 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004231 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004232
Jim Grosbach40700e02011-09-19 18:42:21 +00004233 // If there's a pre-indexing writeback marker, '!', just add it as a token
4234 // operand. It's rather odd, but syntactically valid.
4235 if (Parser.getTok().is(AsmToken::Exclaim)) {
4236 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4237 Parser.Lex(); // Eat the '!'.
4238 }
4239
Jim Grosbachd3595712011-08-03 23:50:40 +00004240 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004241 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004242
Jim Grosbachd3595712011-08-03 23:50:40 +00004243 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4244 Parser.Lex(); // Eat the comma.
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;
4252 if (getParser().ParseExpression(Expr))
4253 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 ']'
4275 E = Parser.getTok().getLoc();
4276 if (Parser.getTok().isNot(AsmToken::RBrac))
4277 return Error(E, "']' expected");
4278 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))
Jim Grosbach8279c182011-11-15 22:14:41 +00004303 Parser.Lex(); // Eat the '#'.
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;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004308 if (getParser().ParseExpression(Offset))
4309 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 ']'
4324 E = Parser.getTok().getLoc();
4325 if (Parser.getTok().isNot(AsmToken::RBrac))
4326 return Error(E, "']' expected");
4327 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 ']'
4370 E = Parser.getTok().getLoc();
4371 if (Parser.getTok().isNot(AsmToken::RBrac))
4372 return Error(E, "']' expected");
4373 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;
4427 if (getParser().ParseExpression(Expr))
4428 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
4456 // needs to go through here, as the regular ParseExpression is
4457 // 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
Jim Grosbache7fbce72011-10-03 23:38:36 +00004485 Parser.Lex(); // Eat the '#'.
4486
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: {
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004549 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling2063b842010-11-18 23:43:05 +00004550 return false;
Jim Grosbach0d6022d2011-07-26 20:41:24 +00004551 int Res = tryParseShiftRegister(Operands);
Jim Grosbachbb24c592011-07-13 18:49:30 +00004552 if (Res == 0) // success
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004553 return false;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004554 else if (Res == -1) // irrecoverable error
4555 return true;
Jim Grosbach4eda1452011-12-20 22:26:38 +00004556 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachd28888d2012-03-15 21:34:14 +00004557 if (Mnemonic == "vmrs" &&
4558 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004559 S = Parser.getTok().getLoc();
4560 Parser.Lex();
Jim Grosbachd28888d2012-03-15 21:34:14 +00004561 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004562 return false;
4563 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004564
4565 // Fall though for the Identifier case that is not a register or a
4566 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004567 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004568 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004569 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004570 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004571 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004572 // This was not a register so parse other operands that start with an
4573 // identifier (like labels) as expressions and create them as immediates.
4574 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004575 S = Parser.getTok().getLoc();
Kevin Enderby146dcf22009-10-15 20:48:48 +00004576 if (getParser().ParseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004577 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004578 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004579 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4580 return false;
4581 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004582 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004583 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004584 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004585 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004586 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004587 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004588 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004589 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004590 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004591
4592 if (Parser.getTok().isNot(AsmToken::Colon)) {
4593 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4594 const MCExpr *ImmVal;
4595 if (getParser().ParseExpression(ImmVal))
4596 return true;
4597 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4598 if (CE) {
4599 int32_t Val = CE->getValue();
4600 if (isNegative && Val == 0)
4601 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4602 }
4603 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4604 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4605 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004606 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004607 // w/ a ':' after the '#', it's just like a plain ':'.
4608 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004609 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004610 case AsmToken::Colon: {
4611 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004612 // FIXME: Check it's an expression prefix,
4613 // e.g. (FOO - :lower16:BAR) isn't legal.
4614 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004615 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004616 return true;
4617
Evan Cheng965b3c72011-01-13 07:58:56 +00004618 const MCExpr *SubExprVal;
4619 if (getParser().ParseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004620 return true;
4621
Evan Cheng965b3c72011-01-13 07:58:56 +00004622 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004623 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004624 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004625 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004626 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004627 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004628 }
4629}
4630
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004631// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004632// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004633bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004634 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004635
4636 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004637 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004638 Parser.Lex(); // Eat ':'
4639
4640 if (getLexer().isNot(AsmToken::Identifier)) {
4641 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4642 return true;
4643 }
4644
4645 StringRef IDVal = Parser.getTok().getIdentifier();
4646 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004647 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004648 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004649 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004650 } else {
4651 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4652 return true;
4653 }
4654 Parser.Lex();
4655
4656 if (getLexer().isNot(AsmToken::Colon)) {
4657 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4658 return true;
4659 }
4660 Parser.Lex(); // Eat the last ':'
4661 return false;
4662}
4663
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004664/// \brief Given a mnemonic, split out possible predication code and carry
4665/// setting letters to form a canonical mnemonic and flags.
4666//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004667// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004668// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004669StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004670 unsigned &PredicationCode,
4671 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004672 unsigned &ProcessorIMod,
4673 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004674 PredicationCode = ARMCC::AL;
4675 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004676 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004677
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004678 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004679 //
4680 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004681 if ((Mnemonic == "movs" && isThumb()) ||
4682 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4683 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4684 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4685 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4686 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4687 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004688 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4689 Mnemonic == "fmuls")
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004690 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004691
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004692 // First, split out any predication code. Ignore mnemonics we know aren't
4693 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004694 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004695 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004696 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004697 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004698 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4699 .Case("eq", ARMCC::EQ)
4700 .Case("ne", ARMCC::NE)
4701 .Case("hs", ARMCC::HS)
4702 .Case("cs", ARMCC::HS)
4703 .Case("lo", ARMCC::LO)
4704 .Case("cc", ARMCC::LO)
4705 .Case("mi", ARMCC::MI)
4706 .Case("pl", ARMCC::PL)
4707 .Case("vs", ARMCC::VS)
4708 .Case("vc", ARMCC::VC)
4709 .Case("hi", ARMCC::HI)
4710 .Case("ls", ARMCC::LS)
4711 .Case("ge", ARMCC::GE)
4712 .Case("lt", ARMCC::LT)
4713 .Case("gt", ARMCC::GT)
4714 .Case("le", ARMCC::LE)
4715 .Case("al", ARMCC::AL)
4716 .Default(~0U);
4717 if (CC != ~0U) {
4718 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4719 PredicationCode = CC;
4720 }
Bill Wendling193961b2010-10-29 23:50:21 +00004721 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004722
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004723 // Next, determine if we have a carry setting bit. We explicitly ignore all
4724 // the instructions we know end in 's'.
4725 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004726 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004727 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4728 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4729 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004730 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004731 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004732 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004733 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004734 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004735 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004736 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4737 CarrySetting = true;
4738 }
4739
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004740 // The "cps" instruction can have a interrupt mode operand which is glued into
4741 // the mnemonic. Check if this is the case, split it and parse the imod op
4742 if (Mnemonic.startswith("cps")) {
4743 // Split out any imod code.
4744 unsigned IMod =
4745 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4746 .Case("ie", ARM_PROC::IE)
4747 .Case("id", ARM_PROC::ID)
4748 .Default(~0U);
4749 if (IMod != ~0U) {
4750 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4751 ProcessorIMod = IMod;
4752 }
4753 }
4754
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004755 // The "it" instruction has the condition mask on the end of the mnemonic.
4756 if (Mnemonic.startswith("it")) {
4757 ITMask = Mnemonic.slice(2, Mnemonic.size());
4758 Mnemonic = Mnemonic.slice(0, 2);
4759 }
4760
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004761 return Mnemonic;
4762}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004763
4764/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4765/// inclusion of carry set or predication code operands.
4766//
4767// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004768void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004769getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004770 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004771 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4772 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004773 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004774 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004775 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004776 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004777 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004778 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004779 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004780 Mnemonic == "mla" || Mnemonic == "smlal" ||
4781 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004782 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004783 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004784 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004785
Daniel Dunbar09264122011-01-11 19:06:29 +00004786 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4787 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4788 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4789 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbach803898f2011-09-06 20:27:04 +00004790 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4791 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach25977222011-08-19 23:24:36 +00004792 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach93981412011-10-11 21:55:36 +00004793 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4794 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4795 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbachb9d4e372011-08-26 22:21:51 +00004796 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4797 !isThumb()) ||
Jim Grosbachb908b7a2011-09-10 00:15:36 +00004798 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004799 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004800 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004801 CanAcceptPredicationCode = true;
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004802
Jim Grosbach6c45b752011-09-16 16:39:25 +00004803 if (isThumb()) {
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004804 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbachb98ab912011-06-30 22:10:46 +00004805 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004806 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004807 }
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004808}
4809
Jim Grosbach7283da92011-08-16 21:12:37 +00004810bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4811 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004812 // FIXME: This is all horribly hacky. We really need a better way to deal
4813 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004814
4815 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4816 // another does not. Specifically, the MOVW instruction does not. So we
4817 // special case it here and remove the defaulted (non-setting) cc_out
4818 // operand if that's the instruction we're trying to match.
4819 //
4820 // We do this as post-processing of the explicit operands rather than just
4821 // conditionally adding the cc_out in the first place because we need
4822 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004823 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004824 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4825 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4826 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4827 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004828
4829 // Register-register 'add' for thumb does not have a cc_out operand
4830 // when there are only two register operands.
4831 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4832 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4833 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4834 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4835 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004836 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004837 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4838 // have to check the immediate range here since Thumb2 has a variant
4839 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004840 if (((isThumb() && Mnemonic == "add") ||
4841 (isThumbTwo() && Mnemonic == "sub")) &&
4842 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004843 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4844 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4845 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004846 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004847 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004848 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004849 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004850 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4851 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004852 // selecting via the generic "add" mnemonic, so to know that we
4853 // should remove the cc_out operand, we have to explicitly check that
4854 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004855 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4856 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004857 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4858 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4859 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4860 // Nest conditions rather than one big 'if' statement for readability.
4861 //
4862 // If either register is a high reg, it's either one of the SP
4863 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004864 // check against T3. If the second register is the PC, this is an
4865 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004866 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4867 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004868 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004869 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4870 return false;
4871 // If both registers are low, we're in an IT block, and the immediate is
4872 // in range, we should use encoding T1 instead, which has a cc_out.
4873 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004874 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004875 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4876 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4877 return false;
4878
4879 // Otherwise, we use encoding T4, which does not have a cc_out
4880 // operand.
4881 return true;
4882 }
4883
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004884 // The thumb2 multiply instruction doesn't have a CCOut register, so
4885 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4886 // use the 16-bit encoding or not.
4887 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4888 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4889 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4890 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4891 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4892 // If the registers aren't low regs, the destination reg isn't the
4893 // same as one of the source regs, or the cc_out operand is zero
4894 // outside of an IT block, we have to use the 32-bit encoding, so
4895 // remove the cc_out operand.
4896 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4897 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004898 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004899 !inITBlock() ||
4900 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4901 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4902 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4903 static_cast<ARMOperand*>(Operands[4])->getReg())))
4904 return true;
4905
Jim Grosbachefa7e952011-11-15 19:55:16 +00004906 // Also check the 'mul' syntax variant that doesn't specify an explicit
4907 // destination register.
4908 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4909 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4910 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4911 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4912 // If the registers aren't low 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()) ||
4917 !inITBlock()))
4918 return true;
4919
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004920
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004921
Jim Grosbach4b701af2011-08-24 21:42:27 +00004922 // Register-register 'add/sub' for thumb does not have a cc_out operand
4923 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4924 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4925 // right, this will result in better diagnostics (which operand is off)
4926 // anyway.
4927 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4928 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004929 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4930 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004931 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4932 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4933 (Operands.size() == 6 &&
4934 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004935 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004936
Jim Grosbach7283da92011-08-16 21:12:37 +00004937 return false;
4938}
4939
Jim Grosbach12952fe2011-11-11 23:08:10 +00004940static bool isDataTypeToken(StringRef Tok) {
4941 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4942 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4943 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4944 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4945 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4946 Tok == ".f" || Tok == ".d";
4947}
4948
4949// FIXME: This bit should probably be handled via an explicit match class
4950// in the .td files that matches the suffix instead of having it be
4951// a literal string token the way it is now.
4952static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4953 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4954}
4955
Jim Grosbach8be2f652011-12-09 23:34:09 +00004956static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004957/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004958bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4959 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004960 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004961 // Apply mnemonic aliases before doing anything else, as the destination
4962 // mnemnonic may include suffices and we want to handle them normally.
4963 // The generic tblgen'erated code does this later, at the start of
4964 // MatchInstructionImpl(), but that's too late for aliases that include
4965 // any sort of suffix.
4966 unsigned AvailableFeatures = getAvailableFeatures();
4967 applyMnemonicAliases(Name, AvailableFeatures);
4968
Jim Grosbachab5830e2011-12-14 02:16:11 +00004969 // First check for the ARM-specific .req directive.
4970 if (Parser.getTok().is(AsmToken::Identifier) &&
4971 Parser.getTok().getIdentifier() == ".req") {
4972 parseDirectiveReq(Name, NameLoc);
4973 // We always return 'error' for this, as we're done with this
4974 // statement and don't need to match the 'instruction."
4975 return true;
4976 }
4977
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004978 // Create the leading tokens for the mnemonic, split by '.' characters.
4979 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004980 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004981
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004982 // Split out the predication code and carry setting flag from the mnemonic.
4983 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004984 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004985 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004986 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004987 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004988 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004989
Jim Grosbach1c171b12011-08-25 17:23:55 +00004990 // In Thumb1, only the branch (B) instruction can be predicated.
4991 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4992 Parser.EatToEndOfStatement();
4993 return Error(NameLoc, "conditional execution not supported in Thumb1");
4994 }
4995
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004996 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4997
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004998 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4999 // is the mask as it will be for the IT encoding if the conditional
5000 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5001 // where the conditional bit0 is zero, the instruction post-processing
5002 // will adjust the mask accordingly.
5003 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005004 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5005 if (ITMask.size() > 3) {
5006 Parser.EatToEndOfStatement();
5007 return Error(Loc, "too many conditions on IT instruction");
5008 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005009 unsigned Mask = 8;
5010 for (unsigned i = ITMask.size(); i != 0; --i) {
5011 char pos = ITMask[i - 1];
5012 if (pos != 't' && pos != 'e') {
5013 Parser.EatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005014 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005015 }
5016 Mask >>= 1;
5017 if (ITMask[i - 1] == 't')
5018 Mask |= 8;
5019 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005020 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005021 }
5022
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005023 // FIXME: This is all a pretty gross hack. We should automatically handle
5024 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005025
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005026 // Next, add the CCOut and ConditionCode operands, if needed.
5027 //
5028 // For mnemonics which can ever incorporate a carry setting bit or predication
5029 // code, our matching model involves us always generating CCOut and
5030 // ConditionCode operands to match the mnemonic "as written" and then we let
5031 // the matcher deal with finding the right instruction or generating an
5032 // appropriate error.
5033 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005034 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005035
Jim Grosbach03a8a162011-07-14 22:04:21 +00005036 // If we had a carry-set on an instruction that can't do that, issue an
5037 // error.
5038 if (!CanAcceptCarrySet && CarrySetting) {
5039 Parser.EatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005040 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005041 "' can not set flags, but 's' suffix specified");
5042 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005043 // If we had a predication code on an instruction that can't do that, issue an
5044 // error.
5045 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5046 Parser.EatToEndOfStatement();
5047 return Error(NameLoc, "instruction '" + Mnemonic +
5048 "' is not predicable, but condition code specified");
5049 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005050
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005051 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005052 if (CanAcceptCarrySet) {
5053 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005054 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005055 Loc));
5056 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005057
5058 // Add the predication code operand, if necessary.
5059 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005060 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5061 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005062 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005063 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005064 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005065
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005066 // Add the processor imod operand, if necessary.
5067 if (ProcessorIMod) {
5068 Operands.push_back(ARMOperand::CreateImm(
5069 MCConstantExpr::Create(ProcessorIMod, getContext()),
5070 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005071 }
5072
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005073 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005074 while (Next != StringRef::npos) {
5075 Start = Next;
5076 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005077 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005078
Jim Grosbach12952fe2011-11-11 23:08:10 +00005079 // Some NEON instructions have an optional datatype suffix that is
5080 // completely ignored. Check for that.
5081 if (isDataTypeToken(ExtraToken) &&
5082 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5083 continue;
5084
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005085 if (ExtraToken != ".n") {
5086 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5087 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5088 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005089 }
5090
5091 // Read the remaining operands.
5092 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005093 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005094 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnera2a9d162010-09-11 16:18:25 +00005095 Parser.EatToEndOfStatement();
5096 return true;
5097 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005098
5099 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005100 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005101
5102 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005103 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnera2a9d162010-09-11 16:18:25 +00005104 Parser.EatToEndOfStatement();
5105 return true;
5106 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005107 }
5108 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005109
Chris Lattnera2a9d162010-09-11 16:18:25 +00005110 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005111 SMLoc Loc = getLexer().getLoc();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005112 Parser.EatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005113 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005114 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005115
Chris Lattner91689c12010-09-08 05:10:46 +00005116 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005117
Jim Grosbach7283da92011-08-16 21:12:37 +00005118 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5119 // do and don't have a cc_out optional-def operand. With some spot-checks
5120 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005121 // parse and adjust accordingly before actually matching. We shouldn't ever
5122 // try to remove a cc_out operand that was explicitly set on the the
5123 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5124 // table driven matcher doesn't fit well with the ARM instruction set.
5125 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005126 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5127 Operands.erase(Operands.begin() + 1);
5128 delete Op;
5129 }
5130
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005131 // ARM mode 'blx' need special handling, as the register operand version
5132 // is predicable, but the label operand version is not. So, we can't rely
5133 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005134 // a k_CondCode operand in the list. If we're trying to match the label
5135 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005136 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5137 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5138 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5139 Operands.erase(Operands.begin() + 1);
5140 delete Op;
5141 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005142
5143 // The vector-compare-to-zero instructions have a literal token "#0" at
5144 // the end that comes to here as an immediate operand. Convert it to a
5145 // token to play nicely with the matcher.
5146 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5147 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5148 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5149 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5150 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5151 if (CE && CE->getValue() == 0) {
5152 Operands.erase(Operands.begin() + 5);
5153 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5154 delete Op;
5155 }
5156 }
Jim Grosbach46b66462011-10-03 22:30:24 +00005157 // VCMP{E} does the same thing, but with a different operand count.
5158 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5159 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5160 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5161 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5162 if (CE && CE->getValue() == 0) {
5163 Operands.erase(Operands.begin() + 4);
5164 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5165 delete Op;
5166 }
5167 }
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005168 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005169 // end. Convert it to a token here. Take care not to convert those
5170 // that should hit the Thumb2 encoding.
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005171 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005172 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5173 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005174 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5175 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005177 if (CE && CE->getValue() == 0 &&
5178 (isThumbOne() ||
Jim Grosbach5ac89672011-12-13 21:06:41 +00005179 // The cc_out operand matches the IT block.
5180 ((inITBlock() != CarrySetting) &&
5181 // Neither register operand is a high register.
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005182 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach5ac89672011-12-13 21:06:41 +00005183 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005184 Operands.erase(Operands.begin() + 5);
5185 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5186 delete Op;
5187 }
5188 }
5189
Weiming Zhao8f56f882012-11-16 21:55:34 +00005190 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5191 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5192 // a single GPRPair reg operand is used in the .td file to replace the two
5193 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5194 // expressed as a GPRPair, so we have to manually merge them.
5195 // FIXME: We would really like to be able to tablegen'erate this.
5196 if (!isThumb() && Operands.size() > 4 &&
5197 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5198 bool isLoad = (Mnemonic == "ldrexd");
5199 unsigned Idx = isLoad ? 2 : 3;
5200 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5201 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5202
5203 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5204 // Adjust only if Op1 and Op2 are GPRs.
5205 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5206 MRC.contains(Op2->getReg())) {
5207 unsigned Reg1 = Op1->getReg();
5208 unsigned Reg2 = Op2->getReg();
5209 unsigned Rt = MRI->getEncodingValue(Reg1);
5210 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5211
5212 // Rt2 must be Rt + 1 and Rt must be even.
5213 if (Rt + 1 != Rt2 || (Rt & 1)) {
5214 Error(Op2->getStartLoc(), isLoad ?
5215 "destination operands must be sequential" :
5216 "source operands must be sequential");
5217 return true;
5218 }
5219 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5220 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5221 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5222 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5223 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5224 delete Op1;
5225 delete Op2;
5226 }
5227 }
5228
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005229 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005230}
5231
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005232// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005233
5234// return 'true' if register list contains non-low GPR registers,
5235// 'false' otherwise. If Reg is in the register list or is HiReg, set
5236// 'containsReg' to true.
5237static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5238 unsigned HiReg, bool &containsReg) {
5239 containsReg = false;
5240 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5241 unsigned OpReg = Inst.getOperand(i).getReg();
5242 if (OpReg == Reg)
5243 containsReg = true;
5244 // Anything other than a low register isn't legal here.
5245 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5246 return true;
5247 }
5248 return false;
5249}
5250
Jim Grosbacha31f2232011-09-07 18:05:34 +00005251// Check if the specified regisgter is in the register list of the inst,
5252// starting at the indicated operand number.
5253static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5254 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5255 unsigned OpReg = Inst.getOperand(i).getReg();
5256 if (OpReg == Reg)
5257 return true;
5258 }
5259 return false;
5260}
5261
Jim Grosbached16ec42011-08-29 22:24:09 +00005262// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5263// the ARMInsts array) instead. Getting that here requires awkward
5264// API changes, though. Better way?
5265namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005266extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005267}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005268static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005269 return ARMInsts[Opcode];
5270}
5271
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005272// FIXME: We would really like to be able to tablegen'erate this.
5273bool ARMAsmParser::
5274validateInstruction(MCInst &Inst,
5275 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005276 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005277 SMLoc Loc = Operands[0]->getStartLoc();
5278 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005279 // NOTE: BKPT instruction has the interesting property of being
5280 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005281 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005282 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5283 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005284 unsigned bit = 1;
5285 if (ITState.FirstCond)
5286 ITState.FirstCond = false;
5287 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005288 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005289 // The instruction must be predicable.
5290 if (!MCID.isPredicable())
5291 return Error(Loc, "instructions in IT block must be predicable");
5292 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5293 unsigned ITCond = bit ? ITState.Cond :
5294 ARMCC::getOppositeCondition(ITState.Cond);
5295 if (Cond != ITCond) {
5296 // Find the condition code Operand to get its SMLoc information.
5297 SMLoc CondLoc;
5298 for (unsigned i = 1; i < Operands.size(); ++i)
5299 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5300 CondLoc = Operands[i]->getStartLoc();
5301 return Error(CondLoc, "incorrect condition in IT block; got '" +
5302 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5303 "', but expected '" +
5304 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5305 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005306 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005307 } else if (isThumbTwo() && MCID.isPredicable() &&
5308 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005309 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5310 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005311 return Error(Loc, "predicated instructions must be in IT block");
5312
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005313 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005314 case ARM::LDRD:
5315 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005316 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005317 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005318 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5319 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005320 if (Rt2 != Rt + 1)
5321 return Error(Operands[3]->getStartLoc(),
5322 "destination operands must be sequential");
5323 return false;
5324 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005325 case ARM::STRD: {
5326 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005327 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5328 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005329 if (Rt2 != Rt + 1)
5330 return Error(Operands[3]->getStartLoc(),
5331 "source operands must be sequential");
5332 return false;
5333 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005334 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005335 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005336 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005337 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5338 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005339 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005340 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005341 "source operands must be sequential");
5342 return false;
5343 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005344 case ARM::SBFX:
5345 case ARM::UBFX: {
5346 // width must be in range [1, 32-lsb]
5347 unsigned lsb = Inst.getOperand(2).getImm();
5348 unsigned widthm1 = Inst.getOperand(3).getImm();
5349 if (widthm1 >= 32 - lsb)
5350 return Error(Operands[5]->getStartLoc(),
5351 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005352 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005353 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005354 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005355 // If we're parsing Thumb2, the .w variant is available and handles
5356 // most cases that are normally illegal for a Thumb1 LDM
5357 // instruction. We'll make the transformation in processInstruction()
5358 // if necessary.
5359 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005360 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005361 // in the register list.
5362 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005363 bool hasWritebackToken =
5364 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5365 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005366 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005367 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005368 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5369 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005370 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005371 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005372 return Error(Operands[2]->getStartLoc(),
5373 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005374 // If we should not have writeback, there must not be a '!'. This is
5375 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005376 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005377 return Error(Operands[3]->getStartLoc(),
5378 "writeback operator '!' not allowed when base register "
5379 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005380
5381 break;
5382 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005383 case ARM::t2LDMIA_UPD: {
5384 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5385 return Error(Operands[4]->getStartLoc(),
5386 "writeback operator '!' not allowed when base register "
5387 "in register list");
5388 break;
5389 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005390 case ARM::tMUL: {
5391 // The second source operand must be the same register as the destination
5392 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005393 //
5394 // In this case, we must directly check the parsed operands because the
5395 // cvtThumbMultiply() function is written in such a way that it guarantees
5396 // this first statement is always true for the new Inst. Essentially, the
5397 // destination is unconditionally copied into the second source operand
5398 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005399 if (Operands.size() == 6 &&
5400 (((ARMOperand*)Operands[3])->getReg() !=
5401 ((ARMOperand*)Operands[5])->getReg()) &&
5402 (((ARMOperand*)Operands[3])->getReg() !=
5403 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005404 return Error(Operands[3]->getStartLoc(),
5405 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005406 }
5407 break;
5408 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005409 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5410 // so only issue a diagnostic for thumb1. The instructions will be
5411 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005412 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005413 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005414 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5415 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005416 return Error(Operands[2]->getStartLoc(),
5417 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005418 break;
5419 }
5420 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005421 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005422 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5423 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005424 return Error(Operands[2]->getStartLoc(),
5425 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005426 break;
5427 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005428 case ARM::tSTMIA_UPD: {
5429 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005430 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005431 return Error(Operands[4]->getStartLoc(),
5432 "registers must be in range r0-r7");
5433 break;
5434 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005435 case ARM::tADDrSP: {
5436 // If the non-SP source operand and the destination operand are not the
5437 // same, we need thumb2 (for the wide encoding), or we have an error.
5438 if (!isThumbTwo() &&
5439 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5440 return Error(Operands[4]->getStartLoc(),
5441 "source register must be the same as destination");
5442 }
5443 break;
5444 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005445 }
5446
5447 return false;
5448}
5449
Jim Grosbach1a747242012-01-23 23:45:44 +00005450static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005451 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005452 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005453 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005454 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5455 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5456 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5457 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5458 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5459 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5460 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5461 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5462 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005463
5464 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005465 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5466 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5467 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5468 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5469 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005470
Jim Grosbach1e946a42012-01-24 00:43:12 +00005471 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5472 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5473 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5474 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5475 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005476
Jim Grosbach1e946a42012-01-24 00:43:12 +00005477 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5478 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5479 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5480 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5481 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005482
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005483 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005484 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5485 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5486 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5487 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5488 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5489 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5490 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5491 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5492 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5493 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5494 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5495 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5496 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5497 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5498 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005499
Jim Grosbach1a747242012-01-23 23:45:44 +00005500 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005501 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5502 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5503 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5504 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5505 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5506 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5507 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5508 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5509 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5510 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5511 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5512 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5513 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5514 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5515 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5516 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5517 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5518 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005519
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005520 // VST4LN
5521 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5522 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5523 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5524 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5525 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5526 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5527 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5528 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5529 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5530 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5531 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5532 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5533 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5534 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5535 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5536
Jim Grosbachda70eac2012-01-24 00:58:13 +00005537 // VST4
5538 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5539 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5540 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5541 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5542 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5543 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5544 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5545 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5546 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5547 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5548 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5549 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5550 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5551 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5552 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5553 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5554 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5555 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005556 }
5557}
5558
Jim Grosbach1a747242012-01-23 23:45:44 +00005559static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005560 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005561 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005562 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005563 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5564 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5565 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5566 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5567 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5568 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5569 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5570 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5571 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005572
5573 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005574 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5575 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5576 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5577 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5578 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5579 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5580 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5581 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5582 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5583 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5584 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5585 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5586 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5587 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5588 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005589
Jim Grosbachb78403c2012-01-24 23:47:04 +00005590 // VLD3DUP
5591 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5592 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5593 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5594 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5595 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5596 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5597 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5598 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5599 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5600 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5601 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5602 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5603 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5604 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5605 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5606 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5607 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5608 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5609
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005610 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005611 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5612 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5613 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5614 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5615 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5616 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5617 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5618 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5619 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5620 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5621 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5622 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5623 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5624 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5625 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005626
5627 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005628 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5629 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5630 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5631 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5632 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5633 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5634 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5635 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5636 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5637 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5638 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5639 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5640 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5641 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5642 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5643 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5644 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5645 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005646
Jim Grosbach14952a02012-01-24 18:37:25 +00005647 // VLD4LN
5648 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5649 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5650 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5651 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5652 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5653 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5654 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5655 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5656 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5657 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5658 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5659 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5660 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5661 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5662 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5663
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005664 // VLD4DUP
5665 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5666 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5667 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5668 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5669 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5670 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5671 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5672 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5673 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5674 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5675 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5676 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5677 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5678 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5679 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5680 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5681 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5682 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5683
Jim Grosbached561fc2012-01-24 00:43:17 +00005684 // VLD4
5685 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5686 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5687 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5688 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5689 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5690 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5691 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5692 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5693 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5694 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5695 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5696 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5697 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5698 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5699 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5700 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5701 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5702 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005703 }
5704}
5705
Jim Grosbachafad0532011-11-10 23:42:14 +00005706bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005707processInstruction(MCInst &Inst,
5708 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5709 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005710 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5711 case ARM::ADDri: {
5712 if (Inst.getOperand(1).getReg() != ARM::PC ||
5713 Inst.getOperand(5).getReg() != 0)
5714 return false;
5715 MCInst TmpInst;
5716 TmpInst.setOpcode(ARM::ADR);
5717 TmpInst.addOperand(Inst.getOperand(0));
5718 TmpInst.addOperand(Inst.getOperand(2));
5719 TmpInst.addOperand(Inst.getOperand(3));
5720 TmpInst.addOperand(Inst.getOperand(4));
5721 Inst = TmpInst;
5722 return true;
5723 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005724 // Aliases for alternate PC+imm syntax of LDR instructions.
5725 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005726 // Select the narrow version if the immediate will fit.
5727 if (Inst.getOperand(1).getImm() > 0 &&
5728 Inst.getOperand(1).getImm() <= 0xff)
5729 Inst.setOpcode(ARM::tLDRpci);
5730 else
5731 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005732 return true;
5733 case ARM::t2LDRBpcrel:
5734 Inst.setOpcode(ARM::t2LDRBpci);
5735 return true;
5736 case ARM::t2LDRHpcrel:
5737 Inst.setOpcode(ARM::t2LDRHpci);
5738 return true;
5739 case ARM::t2LDRSBpcrel:
5740 Inst.setOpcode(ARM::t2LDRSBpci);
5741 return true;
5742 case ARM::t2LDRSHpcrel:
5743 Inst.setOpcode(ARM::t2LDRSHpci);
5744 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005745 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005746 case ARM::VST1LNdWB_register_Asm_8:
5747 case ARM::VST1LNdWB_register_Asm_16:
5748 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005749 MCInst TmpInst;
5750 // Shuffle the operands around so the lane index operand is in the
5751 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005752 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005753 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005754 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5755 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5756 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5757 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5758 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5759 TmpInst.addOperand(Inst.getOperand(1)); // lane
5760 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5761 TmpInst.addOperand(Inst.getOperand(6));
5762 Inst = TmpInst;
5763 return true;
5764 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005765
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005766 case ARM::VST2LNdWB_register_Asm_8:
5767 case ARM::VST2LNdWB_register_Asm_16:
5768 case ARM::VST2LNdWB_register_Asm_32:
5769 case ARM::VST2LNqWB_register_Asm_16:
5770 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005771 MCInst TmpInst;
5772 // Shuffle the operands around so the lane index operand is in the
5773 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005774 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005775 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005776 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5777 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5778 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5779 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5780 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5782 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005783 TmpInst.addOperand(Inst.getOperand(1)); // lane
5784 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5785 TmpInst.addOperand(Inst.getOperand(6));
5786 Inst = TmpInst;
5787 return true;
5788 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005789
5790 case ARM::VST3LNdWB_register_Asm_8:
5791 case ARM::VST3LNdWB_register_Asm_16:
5792 case ARM::VST3LNdWB_register_Asm_32:
5793 case ARM::VST3LNqWB_register_Asm_16:
5794 case ARM::VST3LNqWB_register_Asm_32: {
5795 MCInst TmpInst;
5796 // Shuffle the operands around so the lane index operand is in the
5797 // right place.
5798 unsigned Spacing;
5799 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5800 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5801 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5802 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5803 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5804 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5805 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5806 Spacing));
5807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5808 Spacing * 2));
5809 TmpInst.addOperand(Inst.getOperand(1)); // lane
5810 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5811 TmpInst.addOperand(Inst.getOperand(6));
5812 Inst = TmpInst;
5813 return true;
5814 }
5815
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005816 case ARM::VST4LNdWB_register_Asm_8:
5817 case ARM::VST4LNdWB_register_Asm_16:
5818 case ARM::VST4LNdWB_register_Asm_32:
5819 case ARM::VST4LNqWB_register_Asm_16:
5820 case ARM::VST4LNqWB_register_Asm_32: {
5821 MCInst TmpInst;
5822 // Shuffle the operands around so the lane index operand is in the
5823 // right place.
5824 unsigned Spacing;
5825 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5826 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5827 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5828 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5829 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5830 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5831 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5832 Spacing));
5833 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5834 Spacing * 2));
5835 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5836 Spacing * 3));
5837 TmpInst.addOperand(Inst.getOperand(1)); // lane
5838 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5839 TmpInst.addOperand(Inst.getOperand(6));
5840 Inst = TmpInst;
5841 return true;
5842 }
5843
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005844 case ARM::VST1LNdWB_fixed_Asm_8:
5845 case ARM::VST1LNdWB_fixed_Asm_16:
5846 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005847 MCInst TmpInst;
5848 // Shuffle the operands around so the lane index operand is in the
5849 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005850 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005851 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005852 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5853 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5854 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5855 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5856 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5857 TmpInst.addOperand(Inst.getOperand(1)); // lane
5858 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5859 TmpInst.addOperand(Inst.getOperand(5));
5860 Inst = TmpInst;
5861 return true;
5862 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005863
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005864 case ARM::VST2LNdWB_fixed_Asm_8:
5865 case ARM::VST2LNdWB_fixed_Asm_16:
5866 case ARM::VST2LNdWB_fixed_Asm_32:
5867 case ARM::VST2LNqWB_fixed_Asm_16:
5868 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005869 MCInst TmpInst;
5870 // Shuffle the operands around so the lane index operand is in the
5871 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005872 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005873 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005874 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5875 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5876 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5877 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5878 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5880 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005881 TmpInst.addOperand(Inst.getOperand(1)); // lane
5882 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5883 TmpInst.addOperand(Inst.getOperand(5));
5884 Inst = TmpInst;
5885 return true;
5886 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005887
5888 case ARM::VST3LNdWB_fixed_Asm_8:
5889 case ARM::VST3LNdWB_fixed_Asm_16:
5890 case ARM::VST3LNdWB_fixed_Asm_32:
5891 case ARM::VST3LNqWB_fixed_Asm_16:
5892 case ARM::VST3LNqWB_fixed_Asm_32: {
5893 MCInst TmpInst;
5894 // Shuffle the operands around so the lane index operand is in the
5895 // right place.
5896 unsigned Spacing;
5897 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5898 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5899 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5900 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5901 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5902 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5903 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5904 Spacing));
5905 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5906 Spacing * 2));
5907 TmpInst.addOperand(Inst.getOperand(1)); // lane
5908 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5909 TmpInst.addOperand(Inst.getOperand(5));
5910 Inst = TmpInst;
5911 return true;
5912 }
5913
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005914 case ARM::VST4LNdWB_fixed_Asm_8:
5915 case ARM::VST4LNdWB_fixed_Asm_16:
5916 case ARM::VST4LNdWB_fixed_Asm_32:
5917 case ARM::VST4LNqWB_fixed_Asm_16:
5918 case ARM::VST4LNqWB_fixed_Asm_32: {
5919 MCInst TmpInst;
5920 // Shuffle the operands around so the lane index operand is in the
5921 // right place.
5922 unsigned Spacing;
5923 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5924 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5925 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5926 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5927 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5928 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5929 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5930 Spacing));
5931 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5932 Spacing * 2));
5933 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5934 Spacing * 3));
5935 TmpInst.addOperand(Inst.getOperand(1)); // lane
5936 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5937 TmpInst.addOperand(Inst.getOperand(5));
5938 Inst = TmpInst;
5939 return true;
5940 }
5941
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005942 case ARM::VST1LNdAsm_8:
5943 case ARM::VST1LNdAsm_16:
5944 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005945 MCInst TmpInst;
5946 // Shuffle the operands around so the lane index operand is in the
5947 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005948 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005949 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005950 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5951 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5952 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5953 TmpInst.addOperand(Inst.getOperand(1)); // lane
5954 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5955 TmpInst.addOperand(Inst.getOperand(5));
5956 Inst = TmpInst;
5957 return true;
5958 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005959
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005960 case ARM::VST2LNdAsm_8:
5961 case ARM::VST2LNdAsm_16:
5962 case ARM::VST2LNdAsm_32:
5963 case ARM::VST2LNqAsm_16:
5964 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005965 MCInst TmpInst;
5966 // Shuffle the operands around so the lane index operand is in the
5967 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005968 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005969 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005970 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5971 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5972 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005973 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5974 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005975 TmpInst.addOperand(Inst.getOperand(1)); // lane
5976 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5977 TmpInst.addOperand(Inst.getOperand(5));
5978 Inst = TmpInst;
5979 return true;
5980 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005981
5982 case ARM::VST3LNdAsm_8:
5983 case ARM::VST3LNdAsm_16:
5984 case ARM::VST3LNdAsm_32:
5985 case ARM::VST3LNqAsm_16:
5986 case ARM::VST3LNqAsm_32: {
5987 MCInst TmpInst;
5988 // Shuffle the operands around so the lane index operand is in the
5989 // right place.
5990 unsigned Spacing;
5991 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5992 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5993 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5994 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5995 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5996 Spacing));
5997 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5998 Spacing * 2));
5999 TmpInst.addOperand(Inst.getOperand(1)); // lane
6000 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6001 TmpInst.addOperand(Inst.getOperand(5));
6002 Inst = TmpInst;
6003 return true;
6004 }
6005
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006006 case ARM::VST4LNdAsm_8:
6007 case ARM::VST4LNdAsm_16:
6008 case ARM::VST4LNdAsm_32:
6009 case ARM::VST4LNqAsm_16:
6010 case ARM::VST4LNqAsm_32: {
6011 MCInst TmpInst;
6012 // Shuffle the operands around so the lane index operand is in the
6013 // right place.
6014 unsigned Spacing;
6015 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6016 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6017 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6018 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6019 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6020 Spacing));
6021 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6022 Spacing * 2));
6023 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6024 Spacing * 3));
6025 TmpInst.addOperand(Inst.getOperand(1)); // lane
6026 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6027 TmpInst.addOperand(Inst.getOperand(5));
6028 Inst = TmpInst;
6029 return true;
6030 }
6031
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006032 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006033 case ARM::VLD1LNdWB_register_Asm_8:
6034 case ARM::VLD1LNdWB_register_Asm_16:
6035 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006036 MCInst TmpInst;
6037 // Shuffle the operands around so the lane index operand is in the
6038 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006039 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006040 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006041 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6042 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6043 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6044 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6045 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6046 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6047 TmpInst.addOperand(Inst.getOperand(1)); // lane
6048 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6049 TmpInst.addOperand(Inst.getOperand(6));
6050 Inst = TmpInst;
6051 return true;
6052 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006053
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006054 case ARM::VLD2LNdWB_register_Asm_8:
6055 case ARM::VLD2LNdWB_register_Asm_16:
6056 case ARM::VLD2LNdWB_register_Asm_32:
6057 case ARM::VLD2LNqWB_register_Asm_16:
6058 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006059 MCInst TmpInst;
6060 // Shuffle the operands around so the lane index operand is in the
6061 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006062 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006063 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006064 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006065 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6066 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006067 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6068 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6069 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6070 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6071 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006072 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6073 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006074 TmpInst.addOperand(Inst.getOperand(1)); // lane
6075 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6076 TmpInst.addOperand(Inst.getOperand(6));
6077 Inst = TmpInst;
6078 return true;
6079 }
6080
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006081 case ARM::VLD3LNdWB_register_Asm_8:
6082 case ARM::VLD3LNdWB_register_Asm_16:
6083 case ARM::VLD3LNdWB_register_Asm_32:
6084 case ARM::VLD3LNqWB_register_Asm_16:
6085 case ARM::VLD3LNqWB_register_Asm_32: {
6086 MCInst TmpInst;
6087 // Shuffle the operands around so the lane index operand is in the
6088 // right place.
6089 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006090 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006091 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6092 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6093 Spacing));
6094 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006095 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006096 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6097 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6098 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6099 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6100 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6101 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6102 Spacing));
6103 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006104 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006105 TmpInst.addOperand(Inst.getOperand(1)); // lane
6106 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6107 TmpInst.addOperand(Inst.getOperand(6));
6108 Inst = TmpInst;
6109 return true;
6110 }
6111
Jim Grosbach14952a02012-01-24 18:37:25 +00006112 case ARM::VLD4LNdWB_register_Asm_8:
6113 case ARM::VLD4LNdWB_register_Asm_16:
6114 case ARM::VLD4LNdWB_register_Asm_32:
6115 case ARM::VLD4LNqWB_register_Asm_16:
6116 case ARM::VLD4LNqWB_register_Asm_32: {
6117 MCInst TmpInst;
6118 // Shuffle the operands around so the lane index operand is in the
6119 // right place.
6120 unsigned Spacing;
6121 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6122 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6123 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6124 Spacing));
6125 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6126 Spacing * 2));
6127 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6128 Spacing * 3));
6129 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6130 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6131 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6132 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6133 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6134 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6135 Spacing));
6136 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6137 Spacing * 2));
6138 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6139 Spacing * 3));
6140 TmpInst.addOperand(Inst.getOperand(1)); // lane
6141 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6142 TmpInst.addOperand(Inst.getOperand(6));
6143 Inst = TmpInst;
6144 return true;
6145 }
6146
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006147 case ARM::VLD1LNdWB_fixed_Asm_8:
6148 case ARM::VLD1LNdWB_fixed_Asm_16:
6149 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006150 MCInst TmpInst;
6151 // Shuffle the operands around so the lane index operand is in the
6152 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006153 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006154 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006155 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6156 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6157 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6158 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6159 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6160 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6161 TmpInst.addOperand(Inst.getOperand(1)); // lane
6162 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6163 TmpInst.addOperand(Inst.getOperand(5));
6164 Inst = TmpInst;
6165 return true;
6166 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006167
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006168 case ARM::VLD2LNdWB_fixed_Asm_8:
6169 case ARM::VLD2LNdWB_fixed_Asm_16:
6170 case ARM::VLD2LNdWB_fixed_Asm_32:
6171 case ARM::VLD2LNqWB_fixed_Asm_16:
6172 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006173 MCInst TmpInst;
6174 // Shuffle the operands around so the lane index operand is in the
6175 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006176 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006177 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006178 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006179 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6180 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006181 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6182 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6183 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6184 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6185 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006186 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6187 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006188 TmpInst.addOperand(Inst.getOperand(1)); // lane
6189 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6190 TmpInst.addOperand(Inst.getOperand(5));
6191 Inst = TmpInst;
6192 return true;
6193 }
6194
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006195 case ARM::VLD3LNdWB_fixed_Asm_8:
6196 case ARM::VLD3LNdWB_fixed_Asm_16:
6197 case ARM::VLD3LNdWB_fixed_Asm_32:
6198 case ARM::VLD3LNqWB_fixed_Asm_16:
6199 case ARM::VLD3LNqWB_fixed_Asm_32: {
6200 MCInst TmpInst;
6201 // Shuffle the operands around so the lane index operand is in the
6202 // right place.
6203 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006204 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006205 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6206 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6207 Spacing));
6208 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006209 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006210 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6211 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6212 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6213 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6214 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6215 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6216 Spacing));
6217 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006218 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006219 TmpInst.addOperand(Inst.getOperand(1)); // lane
6220 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6221 TmpInst.addOperand(Inst.getOperand(5));
6222 Inst = TmpInst;
6223 return true;
6224 }
6225
Jim Grosbach14952a02012-01-24 18:37:25 +00006226 case ARM::VLD4LNdWB_fixed_Asm_8:
6227 case ARM::VLD4LNdWB_fixed_Asm_16:
6228 case ARM::VLD4LNdWB_fixed_Asm_32:
6229 case ARM::VLD4LNqWB_fixed_Asm_16:
6230 case ARM::VLD4LNqWB_fixed_Asm_32: {
6231 MCInst TmpInst;
6232 // Shuffle the operands around so the lane index operand is in the
6233 // right place.
6234 unsigned Spacing;
6235 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6236 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6237 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6238 Spacing));
6239 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6240 Spacing * 2));
6241 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6242 Spacing * 3));
6243 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6244 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6245 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6246 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6247 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6248 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6249 Spacing));
6250 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6251 Spacing * 2));
6252 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 Spacing * 3));
6254 TmpInst.addOperand(Inst.getOperand(1)); // lane
6255 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6256 TmpInst.addOperand(Inst.getOperand(5));
6257 Inst = TmpInst;
6258 return true;
6259 }
6260
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006261 case ARM::VLD1LNdAsm_8:
6262 case ARM::VLD1LNdAsm_16:
6263 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006264 MCInst TmpInst;
6265 // Shuffle the operands around so the lane index operand is in the
6266 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006267 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006268 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006269 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6270 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6271 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6272 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6273 TmpInst.addOperand(Inst.getOperand(1)); // lane
6274 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6275 TmpInst.addOperand(Inst.getOperand(5));
6276 Inst = TmpInst;
6277 return true;
6278 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006279
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006280 case ARM::VLD2LNdAsm_8:
6281 case ARM::VLD2LNdAsm_16:
6282 case ARM::VLD2LNdAsm_32:
6283 case ARM::VLD2LNqAsm_16:
6284 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006285 MCInst TmpInst;
6286 // Shuffle the operands around so the lane index operand is in the
6287 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006288 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006289 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006290 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6292 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006293 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6294 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6295 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6297 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006298 TmpInst.addOperand(Inst.getOperand(1)); // lane
6299 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6300 TmpInst.addOperand(Inst.getOperand(5));
6301 Inst = TmpInst;
6302 return true;
6303 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006304
6305 case ARM::VLD3LNdAsm_8:
6306 case ARM::VLD3LNdAsm_16:
6307 case ARM::VLD3LNdAsm_32:
6308 case ARM::VLD3LNqAsm_16:
6309 case ARM::VLD3LNqAsm_32: {
6310 MCInst TmpInst;
6311 // Shuffle the operands around so the lane index operand is in the
6312 // right place.
6313 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006314 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006315 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6316 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6317 Spacing));
6318 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006319 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006320 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6321 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6322 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6323 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6324 Spacing));
6325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006326 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006327 TmpInst.addOperand(Inst.getOperand(1)); // lane
6328 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6329 TmpInst.addOperand(Inst.getOperand(5));
6330 Inst = TmpInst;
6331 return true;
6332 }
6333
Jim Grosbach14952a02012-01-24 18:37:25 +00006334 case ARM::VLD4LNdAsm_8:
6335 case ARM::VLD4LNdAsm_16:
6336 case ARM::VLD4LNdAsm_32:
6337 case ARM::VLD4LNqAsm_16:
6338 case ARM::VLD4LNqAsm_32: {
6339 MCInst TmpInst;
6340 // Shuffle the operands around so the lane index operand is in the
6341 // right place.
6342 unsigned Spacing;
6343 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6344 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6346 Spacing));
6347 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6348 Spacing * 2));
6349 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6350 Spacing * 3));
6351 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6352 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6353 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6354 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6355 Spacing));
6356 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6357 Spacing * 2));
6358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6359 Spacing * 3));
6360 TmpInst.addOperand(Inst.getOperand(1)); // lane
6361 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6362 TmpInst.addOperand(Inst.getOperand(5));
6363 Inst = TmpInst;
6364 return true;
6365 }
6366
Jim Grosbachb78403c2012-01-24 23:47:04 +00006367 // VLD3DUP single 3-element structure to all lanes instructions.
6368 case ARM::VLD3DUPdAsm_8:
6369 case ARM::VLD3DUPdAsm_16:
6370 case ARM::VLD3DUPdAsm_32:
6371 case ARM::VLD3DUPqAsm_8:
6372 case ARM::VLD3DUPqAsm_16:
6373 case ARM::VLD3DUPqAsm_32: {
6374 MCInst TmpInst;
6375 unsigned Spacing;
6376 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6377 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6378 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6379 Spacing));
6380 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6381 Spacing * 2));
6382 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6383 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6384 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6385 TmpInst.addOperand(Inst.getOperand(4));
6386 Inst = TmpInst;
6387 return true;
6388 }
6389
6390 case ARM::VLD3DUPdWB_fixed_Asm_8:
6391 case ARM::VLD3DUPdWB_fixed_Asm_16:
6392 case ARM::VLD3DUPdWB_fixed_Asm_32:
6393 case ARM::VLD3DUPqWB_fixed_Asm_8:
6394 case ARM::VLD3DUPqWB_fixed_Asm_16:
6395 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6396 MCInst TmpInst;
6397 unsigned Spacing;
6398 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6399 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6401 Spacing));
6402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6403 Spacing * 2));
6404 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6405 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6406 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6407 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6408 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6409 TmpInst.addOperand(Inst.getOperand(4));
6410 Inst = TmpInst;
6411 return true;
6412 }
6413
6414 case ARM::VLD3DUPdWB_register_Asm_8:
6415 case ARM::VLD3DUPdWB_register_Asm_16:
6416 case ARM::VLD3DUPdWB_register_Asm_32:
6417 case ARM::VLD3DUPqWB_register_Asm_8:
6418 case ARM::VLD3DUPqWB_register_Asm_16:
6419 case ARM::VLD3DUPqWB_register_Asm_32: {
6420 MCInst TmpInst;
6421 unsigned Spacing;
6422 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6423 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6425 Spacing));
6426 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6427 Spacing * 2));
6428 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6429 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6430 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6431 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6432 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6433 TmpInst.addOperand(Inst.getOperand(5));
6434 Inst = TmpInst;
6435 return true;
6436 }
6437
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006438 // VLD3 multiple 3-element structure instructions.
6439 case ARM::VLD3dAsm_8:
6440 case ARM::VLD3dAsm_16:
6441 case ARM::VLD3dAsm_32:
6442 case ARM::VLD3qAsm_8:
6443 case ARM::VLD3qAsm_16:
6444 case ARM::VLD3qAsm_32: {
6445 MCInst TmpInst;
6446 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006447 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006448 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6449 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6450 Spacing));
6451 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6452 Spacing * 2));
6453 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6454 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6455 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6456 TmpInst.addOperand(Inst.getOperand(4));
6457 Inst = TmpInst;
6458 return true;
6459 }
6460
6461 case ARM::VLD3dWB_fixed_Asm_8:
6462 case ARM::VLD3dWB_fixed_Asm_16:
6463 case ARM::VLD3dWB_fixed_Asm_32:
6464 case ARM::VLD3qWB_fixed_Asm_8:
6465 case ARM::VLD3qWB_fixed_Asm_16:
6466 case ARM::VLD3qWB_fixed_Asm_32: {
6467 MCInst TmpInst;
6468 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006469 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006470 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6472 Spacing));
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6474 Spacing * 2));
6475 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6476 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6477 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6478 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6479 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6480 TmpInst.addOperand(Inst.getOperand(4));
6481 Inst = TmpInst;
6482 return true;
6483 }
6484
6485 case ARM::VLD3dWB_register_Asm_8:
6486 case ARM::VLD3dWB_register_Asm_16:
6487 case ARM::VLD3dWB_register_Asm_32:
6488 case ARM::VLD3qWB_register_Asm_8:
6489 case ARM::VLD3qWB_register_Asm_16:
6490 case ARM::VLD3qWB_register_Asm_32: {
6491 MCInst TmpInst;
6492 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006493 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006494 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6496 Spacing));
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6498 Spacing * 2));
6499 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6500 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6501 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6502 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6503 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6504 TmpInst.addOperand(Inst.getOperand(5));
6505 Inst = TmpInst;
6506 return true;
6507 }
6508
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006509 // VLD4DUP single 3-element structure to all lanes instructions.
6510 case ARM::VLD4DUPdAsm_8:
6511 case ARM::VLD4DUPdAsm_16:
6512 case ARM::VLD4DUPdAsm_32:
6513 case ARM::VLD4DUPqAsm_8:
6514 case ARM::VLD4DUPqAsm_16:
6515 case ARM::VLD4DUPqAsm_32: {
6516 MCInst TmpInst;
6517 unsigned Spacing;
6518 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6519 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6520 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6521 Spacing));
6522 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6523 Spacing * 2));
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6525 Spacing * 3));
6526 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6527 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6528 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6529 TmpInst.addOperand(Inst.getOperand(4));
6530 Inst = TmpInst;
6531 return true;
6532 }
6533
6534 case ARM::VLD4DUPdWB_fixed_Asm_8:
6535 case ARM::VLD4DUPdWB_fixed_Asm_16:
6536 case ARM::VLD4DUPdWB_fixed_Asm_32:
6537 case ARM::VLD4DUPqWB_fixed_Asm_8:
6538 case ARM::VLD4DUPqWB_fixed_Asm_16:
6539 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6540 MCInst TmpInst;
6541 unsigned Spacing;
6542 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6543 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6544 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6545 Spacing));
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6547 Spacing * 2));
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6549 Spacing * 3));
6550 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6551 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6552 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6553 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6554 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6555 TmpInst.addOperand(Inst.getOperand(4));
6556 Inst = TmpInst;
6557 return true;
6558 }
6559
6560 case ARM::VLD4DUPdWB_register_Asm_8:
6561 case ARM::VLD4DUPdWB_register_Asm_16:
6562 case ARM::VLD4DUPdWB_register_Asm_32:
6563 case ARM::VLD4DUPqWB_register_Asm_8:
6564 case ARM::VLD4DUPqWB_register_Asm_16:
6565 case ARM::VLD4DUPqWB_register_Asm_32: {
6566 MCInst TmpInst;
6567 unsigned Spacing;
6568 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6569 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6570 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6571 Spacing));
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6573 Spacing * 2));
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6575 Spacing * 3));
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
6586 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006587 case ARM::VLD4dAsm_8:
6588 case ARM::VLD4dAsm_16:
6589 case ARM::VLD4dAsm_32:
6590 case ARM::VLD4qAsm_8:
6591 case ARM::VLD4qAsm_16:
6592 case ARM::VLD4qAsm_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::VLD4dWB_fixed_Asm_8:
6612 case ARM::VLD4dWB_fixed_Asm_16:
6613 case ARM::VLD4dWB_fixed_Asm_32:
6614 case ARM::VLD4qWB_fixed_Asm_8:
6615 case ARM::VLD4qWB_fixed_Asm_16:
6616 case ARM::VLD4qWB_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::VLD4dWB_register_Asm_8:
6638 case ARM::VLD4dWB_register_Asm_16:
6639 case ARM::VLD4dWB_register_Asm_32:
6640 case ARM::VLD4qWB_register_Asm_8:
6641 case ARM::VLD4qWB_register_Asm_16:
6642 case ARM::VLD4qWB_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
Jim Grosbach1a747242012-01-23 23:45:44 +00006663 // VST3 multiple 3-element structure instructions.
6664 case ARM::VST3dAsm_8:
6665 case ARM::VST3dAsm_16:
6666 case ARM::VST3dAsm_32:
6667 case ARM::VST3qAsm_8:
6668 case ARM::VST3qAsm_16:
6669 case ARM::VST3qAsm_32: {
6670 MCInst TmpInst;
6671 unsigned Spacing;
6672 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6673 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6674 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6675 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6677 Spacing));
6678 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6679 Spacing * 2));
6680 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6681 TmpInst.addOperand(Inst.getOperand(4));
6682 Inst = TmpInst;
6683 return true;
6684 }
6685
6686 case ARM::VST3dWB_fixed_Asm_8:
6687 case ARM::VST3dWB_fixed_Asm_16:
6688 case ARM::VST3dWB_fixed_Asm_32:
6689 case ARM::VST3qWB_fixed_Asm_8:
6690 case ARM::VST3qWB_fixed_Asm_16:
6691 case ARM::VST3qWB_fixed_Asm_32: {
6692 MCInst TmpInst;
6693 unsigned Spacing;
6694 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6695 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6696 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6697 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6698 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6699 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6700 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6701 Spacing));
6702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6703 Spacing * 2));
6704 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6705 TmpInst.addOperand(Inst.getOperand(4));
6706 Inst = TmpInst;
6707 return true;
6708 }
6709
6710 case ARM::VST3dWB_register_Asm_8:
6711 case ARM::VST3dWB_register_Asm_16:
6712 case ARM::VST3dWB_register_Asm_32:
6713 case ARM::VST3qWB_register_Asm_8:
6714 case ARM::VST3qWB_register_Asm_16:
6715 case ARM::VST3qWB_register_Asm_32: {
6716 MCInst TmpInst;
6717 unsigned Spacing;
6718 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6719 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6720 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6721 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6722 TmpInst.addOperand(Inst.getOperand(3)); // Rm
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(Inst.getOperand(4)); // CondCode
6729 TmpInst.addOperand(Inst.getOperand(5));
6730 Inst = TmpInst;
6731 return true;
6732 }
6733
Jim Grosbachda70eac2012-01-24 00:58:13 +00006734 // VST4 multiple 3-element structure instructions.
6735 case ARM::VST4dAsm_8:
6736 case ARM::VST4dAsm_16:
6737 case ARM::VST4dAsm_32:
6738 case ARM::VST4qAsm_8:
6739 case ARM::VST4qAsm_16:
6740 case ARM::VST4qAsm_32: {
6741 MCInst TmpInst;
6742 unsigned Spacing;
6743 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6744 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6745 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6746 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6748 Spacing));
6749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6750 Spacing * 2));
6751 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6752 Spacing * 3));
6753 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6754 TmpInst.addOperand(Inst.getOperand(4));
6755 Inst = TmpInst;
6756 return true;
6757 }
6758
6759 case ARM::VST4dWB_fixed_Asm_8:
6760 case ARM::VST4dWB_fixed_Asm_16:
6761 case ARM::VST4dWB_fixed_Asm_32:
6762 case ARM::VST4qWB_fixed_Asm_8:
6763 case ARM::VST4qWB_fixed_Asm_16:
6764 case ARM::VST4qWB_fixed_Asm_32: {
6765 MCInst TmpInst;
6766 unsigned Spacing;
6767 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6768 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6769 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6770 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6771 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6772 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6773 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6774 Spacing));
6775 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6776 Spacing * 2));
6777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6778 Spacing * 3));
6779 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6780 TmpInst.addOperand(Inst.getOperand(4));
6781 Inst = TmpInst;
6782 return true;
6783 }
6784
6785 case ARM::VST4dWB_register_Asm_8:
6786 case ARM::VST4dWB_register_Asm_16:
6787 case ARM::VST4dWB_register_Asm_32:
6788 case ARM::VST4qWB_register_Asm_8:
6789 case ARM::VST4qWB_register_Asm_16:
6790 case ARM::VST4qWB_register_Asm_32: {
6791 MCInst TmpInst;
6792 unsigned Spacing;
6793 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6794 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6795 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6796 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6797 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6798 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6799 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6800 Spacing));
6801 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6802 Spacing * 2));
6803 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6804 Spacing * 3));
6805 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6806 TmpInst.addOperand(Inst.getOperand(5));
6807 Inst = TmpInst;
6808 return true;
6809 }
6810
Jim Grosbachad66de12012-04-11 00:15:16 +00006811 // Handle encoding choice for the shift-immediate instructions.
6812 case ARM::t2LSLri:
6813 case ARM::t2LSRri:
6814 case ARM::t2ASRri: {
6815 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6816 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6817 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6818 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6819 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6820 unsigned NewOpc;
6821 switch (Inst.getOpcode()) {
6822 default: llvm_unreachable("unexpected opcode");
6823 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6824 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6825 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6826 }
6827 // The Thumb1 operands aren't in the same order. Awesome, eh?
6828 MCInst TmpInst;
6829 TmpInst.setOpcode(NewOpc);
6830 TmpInst.addOperand(Inst.getOperand(0));
6831 TmpInst.addOperand(Inst.getOperand(5));
6832 TmpInst.addOperand(Inst.getOperand(1));
6833 TmpInst.addOperand(Inst.getOperand(2));
6834 TmpInst.addOperand(Inst.getOperand(3));
6835 TmpInst.addOperand(Inst.getOperand(4));
6836 Inst = TmpInst;
6837 return true;
6838 }
6839 return false;
6840 }
6841
Jim Grosbach485e5622011-12-13 22:45:11 +00006842 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006843 case ARM::t2MOVsr:
6844 case ARM::t2MOVSsr: {
6845 // Which instruction to expand to depends on the CCOut operand and
6846 // whether we're in an IT block if the register operands are low
6847 // registers.
6848 bool isNarrow = false;
6849 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6850 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6851 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6852 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6853 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6854 isNarrow = true;
6855 MCInst TmpInst;
6856 unsigned newOpc;
6857 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6858 default: llvm_unreachable("unexpected opcode!");
6859 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6860 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6861 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6862 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6863 }
6864 TmpInst.setOpcode(newOpc);
6865 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6866 if (isNarrow)
6867 TmpInst.addOperand(MCOperand::CreateReg(
6868 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6869 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6870 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6871 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6872 TmpInst.addOperand(Inst.getOperand(5));
6873 if (!isNarrow)
6874 TmpInst.addOperand(MCOperand::CreateReg(
6875 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6876 Inst = TmpInst;
6877 return true;
6878 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006879 case ARM::t2MOVsi:
6880 case ARM::t2MOVSsi: {
6881 // Which instruction to expand to depends on the CCOut operand and
6882 // whether we're in an IT block if the register operands are low
6883 // registers.
6884 bool isNarrow = false;
6885 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6886 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6887 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6888 isNarrow = true;
6889 MCInst TmpInst;
6890 unsigned newOpc;
6891 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6892 default: llvm_unreachable("unexpected opcode!");
6893 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6894 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6895 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6896 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006897 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006898 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006899 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6900 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006901 TmpInst.setOpcode(newOpc);
6902 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6903 if (isNarrow)
6904 TmpInst.addOperand(MCOperand::CreateReg(
6905 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6906 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006907 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006908 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006909 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6910 TmpInst.addOperand(Inst.getOperand(4));
6911 if (!isNarrow)
6912 TmpInst.addOperand(MCOperand::CreateReg(
6913 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6914 Inst = TmpInst;
6915 return true;
6916 }
6917 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006918 case ARM::ASRr:
6919 case ARM::LSRr:
6920 case ARM::LSLr:
6921 case ARM::RORr: {
6922 ARM_AM::ShiftOpc ShiftTy;
6923 switch(Inst.getOpcode()) {
6924 default: llvm_unreachable("unexpected opcode!");
6925 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6926 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6927 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6928 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6929 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006930 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6931 MCInst TmpInst;
6932 TmpInst.setOpcode(ARM::MOVsr);
6933 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6934 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6935 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6936 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6937 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6938 TmpInst.addOperand(Inst.getOperand(4));
6939 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6940 Inst = TmpInst;
6941 return true;
6942 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006943 case ARM::ASRi:
6944 case ARM::LSRi:
6945 case ARM::LSLi:
6946 case ARM::RORi: {
6947 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006948 switch(Inst.getOpcode()) {
6949 default: llvm_unreachable("unexpected opcode!");
6950 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6951 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6952 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6953 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6954 }
6955 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006956 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00006957 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00006958 // A shift by 32 should be encoded as 0 when permitted
6959 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6960 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006961 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006962 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006963 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006964 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6965 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00006966 if (Opc == ARM::MOVsi)
6967 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00006968 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6969 TmpInst.addOperand(Inst.getOperand(4));
6970 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6971 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006972 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00006973 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006974 case ARM::RRXi: {
6975 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6976 MCInst TmpInst;
6977 TmpInst.setOpcode(ARM::MOVsi);
6978 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6979 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6980 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6981 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6982 TmpInst.addOperand(Inst.getOperand(3));
6983 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6984 Inst = TmpInst;
6985 return true;
6986 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00006987 case ARM::t2LDMIA_UPD: {
6988 // If this is a load of a single register, then we should use
6989 // a post-indexed LDR instruction instead, per the ARM ARM.
6990 if (Inst.getNumOperands() != 5)
6991 return false;
6992 MCInst TmpInst;
6993 TmpInst.setOpcode(ARM::t2LDR_POST);
6994 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6995 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6996 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6997 TmpInst.addOperand(MCOperand::CreateImm(4));
6998 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6999 TmpInst.addOperand(Inst.getOperand(3));
7000 Inst = TmpInst;
7001 return true;
7002 }
7003 case ARM::t2STMDB_UPD: {
7004 // If this is a store of a single register, then we should use
7005 // a pre-indexed STR instruction instead, per the ARM ARM.
7006 if (Inst.getNumOperands() != 5)
7007 return false;
7008 MCInst TmpInst;
7009 TmpInst.setOpcode(ARM::t2STR_PRE);
7010 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7011 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7012 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7013 TmpInst.addOperand(MCOperand::CreateImm(-4));
7014 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7015 TmpInst.addOperand(Inst.getOperand(3));
7016 Inst = TmpInst;
7017 return true;
7018 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007019 case ARM::LDMIA_UPD:
7020 // If this is a load of a single register via a 'pop', then we should use
7021 // a post-indexed LDR instruction instead, per the ARM ARM.
7022 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7023 Inst.getNumOperands() == 5) {
7024 MCInst TmpInst;
7025 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7026 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7027 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7028 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7029 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7030 TmpInst.addOperand(MCOperand::CreateImm(4));
7031 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7032 TmpInst.addOperand(Inst.getOperand(3));
7033 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007034 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007035 }
7036 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007037 case ARM::STMDB_UPD:
7038 // If this is a store of a single register via a 'push', then we should use
7039 // a pre-indexed STR instruction instead, per the ARM ARM.
7040 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7041 Inst.getNumOperands() == 5) {
7042 MCInst TmpInst;
7043 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7044 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7045 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7046 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7047 TmpInst.addOperand(MCOperand::CreateImm(-4));
7048 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7049 TmpInst.addOperand(Inst.getOperand(3));
7050 Inst = TmpInst;
7051 }
7052 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007053 case ARM::t2ADDri12:
7054 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7055 // mnemonic was used (not "addw"), encoding T3 is preferred.
7056 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7057 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7058 break;
7059 Inst.setOpcode(ARM::t2ADDri);
7060 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7061 break;
7062 case ARM::t2SUBri12:
7063 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7064 // mnemonic was used (not "subw"), encoding T3 is preferred.
7065 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7066 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7067 break;
7068 Inst.setOpcode(ARM::t2SUBri);
7069 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7070 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007071 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007072 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007073 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7074 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7075 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007076 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007077 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007078 return true;
7079 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007080 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007081 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007082 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007083 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7084 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7085 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007086 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007087 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007088 return true;
7089 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007090 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007091 case ARM::t2ADDri:
7092 case ARM::t2SUBri: {
7093 // If the destination and first source operand are the same, and
7094 // the flags are compatible with the current IT status, use encoding T2
7095 // instead of T3. For compatibility with the system 'as'. Make sure the
7096 // wide encoding wasn't explicit.
7097 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007098 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007099 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7100 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7101 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7102 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7103 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7104 break;
7105 MCInst TmpInst;
7106 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7107 ARM::tADDi8 : ARM::tSUBi8);
7108 TmpInst.addOperand(Inst.getOperand(0));
7109 TmpInst.addOperand(Inst.getOperand(5));
7110 TmpInst.addOperand(Inst.getOperand(0));
7111 TmpInst.addOperand(Inst.getOperand(2));
7112 TmpInst.addOperand(Inst.getOperand(3));
7113 TmpInst.addOperand(Inst.getOperand(4));
7114 Inst = TmpInst;
7115 return true;
7116 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007117 case ARM::t2ADDrr: {
7118 // If the destination and first source operand are the same, and
7119 // there's no setting of the flags, use encoding T2 instead of T3.
7120 // Note that this is only for ADD, not SUB. This mirrors the system
7121 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7122 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7123 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007124 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7125 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007126 break;
7127 MCInst TmpInst;
7128 TmpInst.setOpcode(ARM::tADDhirr);
7129 TmpInst.addOperand(Inst.getOperand(0));
7130 TmpInst.addOperand(Inst.getOperand(0));
7131 TmpInst.addOperand(Inst.getOperand(2));
7132 TmpInst.addOperand(Inst.getOperand(3));
7133 TmpInst.addOperand(Inst.getOperand(4));
7134 Inst = TmpInst;
7135 return true;
7136 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007137 case ARM::tADDrSP: {
7138 // If the non-SP source operand and the destination operand are not the
7139 // same, we need to use the 32-bit encoding if it's available.
7140 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7141 Inst.setOpcode(ARM::t2ADDrr);
7142 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7143 return true;
7144 }
7145 break;
7146 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007147 case ARM::tB:
7148 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007149 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007150 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007151 return true;
7152 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007153 break;
7154 case ARM::t2B:
7155 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007156 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007157 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007158 return true;
7159 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007160 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007161 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007162 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007163 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007164 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007165 return true;
7166 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007167 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007168 case ARM::tBcc:
7169 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007170 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007171 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007172 return true;
7173 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007174 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007175 case ARM::tLDMIA: {
7176 // If the register list contains any high registers, or if the writeback
7177 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7178 // instead if we're in Thumb2. Otherwise, this should have generated
7179 // an error in validateInstruction().
7180 unsigned Rn = Inst.getOperand(0).getReg();
7181 bool hasWritebackToken =
7182 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7183 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7184 bool listContainsBase;
7185 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7186 (!listContainsBase && !hasWritebackToken) ||
7187 (listContainsBase && hasWritebackToken)) {
7188 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7189 assert (isThumbTwo());
7190 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7191 // If we're switching to the updating version, we need to insert
7192 // the writeback tied operand.
7193 if (hasWritebackToken)
7194 Inst.insert(Inst.begin(),
7195 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007196 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007197 }
7198 break;
7199 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007200 case ARM::tSTMIA_UPD: {
7201 // If the register list contains any high registers, we need to use
7202 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7203 // should have generated an error in validateInstruction().
7204 unsigned Rn = Inst.getOperand(0).getReg();
7205 bool listContainsBase;
7206 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7207 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7208 assert (isThumbTwo());
7209 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007210 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007211 }
7212 break;
7213 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007214 case ARM::tPOP: {
7215 bool listContainsBase;
7216 // If the register list contains any high registers, we need to use
7217 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7218 // should have generated an error in validateInstruction().
7219 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007220 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007221 assert (isThumbTwo());
7222 Inst.setOpcode(ARM::t2LDMIA_UPD);
7223 // Add the base register and writeback operands.
7224 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7225 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007226 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007227 }
7228 case ARM::tPUSH: {
7229 bool listContainsBase;
7230 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007231 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007232 assert (isThumbTwo());
7233 Inst.setOpcode(ARM::t2STMDB_UPD);
7234 // Add the base register and writeback operands.
7235 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7236 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007237 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007238 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007239 case ARM::t2MOVi: {
7240 // If we can use the 16-bit encoding and the user didn't explicitly
7241 // request the 32-bit variant, transform it here.
7242 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007243 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007244 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7245 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7246 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007247 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7248 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7249 // The operands aren't in the same order for tMOVi8...
7250 MCInst TmpInst;
7251 TmpInst.setOpcode(ARM::tMOVi8);
7252 TmpInst.addOperand(Inst.getOperand(0));
7253 TmpInst.addOperand(Inst.getOperand(4));
7254 TmpInst.addOperand(Inst.getOperand(1));
7255 TmpInst.addOperand(Inst.getOperand(2));
7256 TmpInst.addOperand(Inst.getOperand(3));
7257 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007258 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007259 }
7260 break;
7261 }
7262 case ARM::t2MOVr: {
7263 // If we can use the 16-bit encoding and the user didn't explicitly
7264 // request the 32-bit variant, transform it here.
7265 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7266 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7267 Inst.getOperand(2).getImm() == ARMCC::AL &&
7268 Inst.getOperand(4).getReg() == ARM::CPSR &&
7269 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7270 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7271 // The operands aren't the same for tMOV[S]r... (no cc_out)
7272 MCInst TmpInst;
7273 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7274 TmpInst.addOperand(Inst.getOperand(0));
7275 TmpInst.addOperand(Inst.getOperand(1));
7276 TmpInst.addOperand(Inst.getOperand(2));
7277 TmpInst.addOperand(Inst.getOperand(3));
7278 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007279 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007280 }
7281 break;
7282 }
Jim Grosbach82213192011-09-19 20:29:33 +00007283 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007284 case ARM::t2SXTB:
7285 case ARM::t2UXTH:
7286 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007287 // If we can use the 16-bit encoding and the user didn't explicitly
7288 // request the 32-bit variant, transform it here.
7289 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7290 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7291 Inst.getOperand(2).getImm() == 0 &&
7292 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7293 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007294 unsigned NewOpc;
7295 switch (Inst.getOpcode()) {
7296 default: llvm_unreachable("Illegal opcode!");
7297 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7298 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7299 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7300 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7301 }
Jim Grosbach82213192011-09-19 20:29:33 +00007302 // The operands aren't the same for thumb1 (no rotate operand).
7303 MCInst TmpInst;
7304 TmpInst.setOpcode(NewOpc);
7305 TmpInst.addOperand(Inst.getOperand(0));
7306 TmpInst.addOperand(Inst.getOperand(1));
7307 TmpInst.addOperand(Inst.getOperand(3));
7308 TmpInst.addOperand(Inst.getOperand(4));
7309 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007310 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007311 }
7312 break;
7313 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007314 case ARM::MOVsi: {
7315 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007316 // rrx shifts and asr/lsr of #32 is encoded as 0
7317 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7318 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007319 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7320 // Shifting by zero is accepted as a vanilla 'MOVr'
7321 MCInst TmpInst;
7322 TmpInst.setOpcode(ARM::MOVr);
7323 TmpInst.addOperand(Inst.getOperand(0));
7324 TmpInst.addOperand(Inst.getOperand(1));
7325 TmpInst.addOperand(Inst.getOperand(3));
7326 TmpInst.addOperand(Inst.getOperand(4));
7327 TmpInst.addOperand(Inst.getOperand(5));
7328 Inst = TmpInst;
7329 return true;
7330 }
7331 return false;
7332 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007333 case ARM::ANDrsi:
7334 case ARM::ORRrsi:
7335 case ARM::EORrsi:
7336 case ARM::BICrsi:
7337 case ARM::SUBrsi:
7338 case ARM::ADDrsi: {
7339 unsigned newOpc;
7340 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7341 if (SOpc == ARM_AM::rrx) return false;
7342 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007343 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007344 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7345 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7346 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7347 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7348 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7349 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7350 }
7351 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007352 // The exception is for right shifts, where 0 == 32
7353 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7354 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007355 MCInst TmpInst;
7356 TmpInst.setOpcode(newOpc);
7357 TmpInst.addOperand(Inst.getOperand(0));
7358 TmpInst.addOperand(Inst.getOperand(1));
7359 TmpInst.addOperand(Inst.getOperand(2));
7360 TmpInst.addOperand(Inst.getOperand(4));
7361 TmpInst.addOperand(Inst.getOperand(5));
7362 TmpInst.addOperand(Inst.getOperand(6));
7363 Inst = TmpInst;
7364 return true;
7365 }
7366 return false;
7367 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007368 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007369 case ARM::t2IT: {
7370 // The mask bits for all but the first condition are represented as
7371 // the low bit of the condition code value implies 't'. We currently
7372 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007373 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007374 MCOperand &MO = Inst.getOperand(1);
7375 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007376 unsigned OrigMask = Mask;
7377 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007378 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007379 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7380 for (unsigned i = 3; i != TZ; --i)
7381 Mask ^= 1 << i;
Richard Bartonf435b092012-04-27 08:42:59 +00007382 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007383 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007384
7385 // Set up the IT block state according to the IT instruction we just
7386 // matched.
7387 assert(!inITBlock() && "nested IT blocks?!");
7388 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7389 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7390 ITState.CurPosition = 0;
7391 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007392 break;
7393 }
Richard Bartona39625e2012-07-09 16:12:24 +00007394 case ARM::t2LSLrr:
7395 case ARM::t2LSRrr:
7396 case ARM::t2ASRrr:
7397 case ARM::t2SBCrr:
7398 case ARM::t2RORrr:
7399 case ARM::t2BICrr:
7400 {
Richard Bartond5660372012-07-09 16:14:28 +00007401 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007402 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7403 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7404 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007405 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7406 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007407 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7408 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7409 unsigned NewOpc;
7410 switch (Inst.getOpcode()) {
7411 default: llvm_unreachable("unexpected opcode");
7412 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7413 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7414 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7415 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7416 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7417 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7418 }
7419 MCInst TmpInst;
7420 TmpInst.setOpcode(NewOpc);
7421 TmpInst.addOperand(Inst.getOperand(0));
7422 TmpInst.addOperand(Inst.getOperand(5));
7423 TmpInst.addOperand(Inst.getOperand(1));
7424 TmpInst.addOperand(Inst.getOperand(2));
7425 TmpInst.addOperand(Inst.getOperand(3));
7426 TmpInst.addOperand(Inst.getOperand(4));
7427 Inst = TmpInst;
7428 return true;
7429 }
7430 return false;
7431 }
7432 case ARM::t2ANDrr:
7433 case ARM::t2EORrr:
7434 case ARM::t2ADCrr:
7435 case ARM::t2ORRrr:
7436 {
Richard Bartond5660372012-07-09 16:14:28 +00007437 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007438 // These instructions are special in that they are commutable, so shorter encodings
7439 // are available more often.
7440 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7441 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7442 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7443 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007444 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7445 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007446 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7447 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7448 unsigned NewOpc;
7449 switch (Inst.getOpcode()) {
7450 default: llvm_unreachable("unexpected opcode");
7451 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7452 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7453 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7454 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7455 }
7456 MCInst TmpInst;
7457 TmpInst.setOpcode(NewOpc);
7458 TmpInst.addOperand(Inst.getOperand(0));
7459 TmpInst.addOperand(Inst.getOperand(5));
7460 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7461 TmpInst.addOperand(Inst.getOperand(1));
7462 TmpInst.addOperand(Inst.getOperand(2));
7463 } else {
7464 TmpInst.addOperand(Inst.getOperand(2));
7465 TmpInst.addOperand(Inst.getOperand(1));
7466 }
7467 TmpInst.addOperand(Inst.getOperand(3));
7468 TmpInst.addOperand(Inst.getOperand(4));
7469 Inst = TmpInst;
7470 return true;
7471 }
7472 return false;
7473 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007474 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007475 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007476}
7477
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007478unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7479 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7480 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007481 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007482 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007483 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7484 assert(MCID.hasOptionalDef() &&
7485 "optionally flag setting instruction missing optional def operand");
7486 assert(MCID.NumOperands == Inst.getNumOperands() &&
7487 "operand count mismatch!");
7488 // Find the optional-def operand (cc_out).
7489 unsigned OpNo;
7490 for (OpNo = 0;
7491 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7492 ++OpNo)
7493 ;
7494 // If we're parsing Thumb1, reject it completely.
7495 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7496 return Match_MnemonicFail;
7497 // If we're parsing Thumb2, which form is legal depends on whether we're
7498 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007499 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7500 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007501 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007502 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7503 inITBlock())
7504 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007505 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007506 // Some high-register supporting Thumb1 encodings only allow both registers
7507 // to be from r0-r7 when in Thumb2.
7508 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7509 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7510 isARMLowRegister(Inst.getOperand(2).getReg()))
7511 return Match_RequiresThumb2;
7512 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007513 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007514 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7515 isARMLowRegister(Inst.getOperand(1).getReg()))
7516 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007517 return Match_Success;
7518}
7519
Jim Grosbach5117ef72012-04-24 22:40:08 +00007520static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007521bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007522MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007523 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007524 MCStreamer &Out, unsigned &ErrorInfo,
7525 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007526 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007527 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007528
Chad Rosier2f480a82012-10-12 22:53:36 +00007529 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007530 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007531 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007532 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007533 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007534 // Context sensitive operand constraints aren't handled by the matcher,
7535 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007536 if (validateInstruction(Inst, Operands)) {
7537 // Still progress the IT block, otherwise one wrong condition causes
7538 // nasty cascading errors.
7539 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007540 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007541 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007542
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007543 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007544 // encoding is selected. Loop on it while changes happen so the
7545 // individual transformations can chain off each other. E.g.,
7546 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7547 while (processInstruction(Inst, Operands))
7548 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007549
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007550 // Only move forward at the very end so that everything in validate
7551 // and process gets a consistent answer about whether we're in an IT
7552 // block.
7553 forwardITPosition();
7554
Jim Grosbach82f76d12012-01-25 19:52:01 +00007555 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7556 // doesn't actually encode.
7557 if (Inst.getOpcode() == ARM::ITasm)
7558 return false;
7559
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007560 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007561 Out.EmitInstruction(Inst);
7562 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007563 case Match_MissingFeature: {
7564 assert(ErrorInfo && "Unknown missing feature!");
7565 // Special case the error message for the very common case where only
7566 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7567 std::string Msg = "instruction requires:";
7568 unsigned Mask = 1;
7569 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7570 if (ErrorInfo & Mask) {
7571 Msg += " ";
7572 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7573 }
7574 Mask <<= 1;
7575 }
7576 return Error(IDLoc, Msg);
7577 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007578 case Match_InvalidOperand: {
7579 SMLoc ErrorLoc = IDLoc;
7580 if (ErrorInfo != ~0U) {
7581 if (ErrorInfo >= Operands.size())
7582 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007583
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007584 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7585 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7586 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007587
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007588 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007589 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007590 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007591 return Error(IDLoc, "invalid instruction",
7592 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007593 case Match_RequiresNotITBlock:
7594 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007595 case Match_RequiresITBlock:
7596 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007597 case Match_RequiresV6:
7598 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7599 case Match_RequiresThumb2:
7600 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007601 case Match_ImmRange0_15: {
7602 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7603 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7604 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7605 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007606 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007607
Eric Christopher91d7b902010-10-29 09:26:59 +00007608 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007609}
7610
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007611/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007612bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7613 StringRef IDVal = DirectiveID.getIdentifier();
7614 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007615 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007616 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007617 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007618 else if (IDVal == ".arm")
7619 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007620 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007621 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007622 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007623 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007624 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007625 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007626 else if (IDVal == ".unreq")
7627 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007628 else if (IDVal == ".arch")
7629 return parseDirectiveArch(DirectiveID.getLoc());
7630 else if (IDVal == ".eabi_attribute")
7631 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyccab3172009-09-15 00:27:25 +00007632 return true;
7633}
7634
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007635/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007636/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007637bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007638 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7639 for (;;) {
7640 const MCExpr *Value;
7641 if (getParser().ParseExpression(Value))
7642 return true;
7643
Chris Lattnerc35681b2010-01-19 19:46:13 +00007644 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007645
7646 if (getLexer().is(AsmToken::EndOfStatement))
7647 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007648
Kevin Enderbyccab3172009-09-15 00:27:25 +00007649 // FIXME: Improve diagnostic.
7650 if (getLexer().isNot(AsmToken::Comma))
7651 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007652 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007653 }
7654 }
7655
Sean Callanana83fd7d2010-01-19 20:27:46 +00007656 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007657 return false;
7658}
7659
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007660/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007661/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007662bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007663 if (getLexer().isNot(AsmToken::EndOfStatement))
7664 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007665 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007666
Jim Grosbach7f882392011-12-07 18:04:19 +00007667 if (!isThumb())
7668 SwitchMode();
7669 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7670 return false;
7671}
7672
7673/// parseDirectiveARM
7674/// ::= .arm
7675bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7676 if (getLexer().isNot(AsmToken::EndOfStatement))
7677 return Error(L, "unexpected token in directive");
7678 Parser.Lex();
7679
7680 if (isThumb())
7681 SwitchMode();
7682 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007683 return false;
7684}
7685
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007686/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007687/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007688bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007689 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7690 bool isMachO = MAI.hasSubsectionsViaSymbols();
7691 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007692 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007693
Jim Grosbach1152cc02011-12-21 22:30:16 +00007694 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007695 // ELF doesn't
7696 if (isMachO) {
7697 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007698 if (Tok.isNot(AsmToken::EndOfStatement)) {
7699 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7700 return Error(L, "unexpected token in .thumb_func directive");
7701 Name = Tok.getIdentifier();
7702 Parser.Lex(); // Consume the identifier token.
7703 needFuncName = false;
7704 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007705 }
7706
Jim Grosbach1152cc02011-12-21 22:30:16 +00007707 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007708 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007709
7710 // Eat the end of statement and any blank lines that follow.
7711 while (getLexer().is(AsmToken::EndOfStatement))
7712 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007713
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007714 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007715 // We really should be checking the next symbol definition even if there's
7716 // stuff in between.
7717 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007718 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007719 }
7720
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007721 // Mark symbol as a thumb symbol.
7722 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7723 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007724 return false;
7725}
7726
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007727/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007728/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007729bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007730 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007731 if (Tok.isNot(AsmToken::Identifier))
7732 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007733 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007734 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007735 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007736 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007737 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007738 else
7739 return Error(L, "unrecognized syntax mode in .syntax directive");
7740
7741 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007742 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007743 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007744
7745 // TODO tell the MC streamer the mode
7746 // getParser().getStreamer().Emit???();
7747 return false;
7748}
7749
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007750/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007751/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007752bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007753 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007754 if (Tok.isNot(AsmToken::Integer))
7755 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007756 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007757 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007758 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007759 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007760 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007761 else
7762 return Error(L, "invalid operand to .code directive");
7763
7764 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007765 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007766 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007767
Evan Cheng284b4672011-07-08 22:36:29 +00007768 if (Val == 16) {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007769 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007770 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007771 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007772 } else {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007773 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007774 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007775 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007776 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007777
Kevin Enderby146dcf22009-10-15 20:48:48 +00007778 return false;
7779}
7780
Jim Grosbachab5830e2011-12-14 02:16:11 +00007781/// parseDirectiveReq
7782/// ::= name .req registername
7783bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7784 Parser.Lex(); // Eat the '.req' token.
7785 unsigned Reg;
7786 SMLoc SRegLoc, ERegLoc;
7787 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7788 Parser.EatToEndOfStatement();
7789 return Error(SRegLoc, "register name expected");
7790 }
7791
7792 // Shouldn't be anything else.
7793 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7794 Parser.EatToEndOfStatement();
7795 return Error(Parser.getTok().getLoc(),
7796 "unexpected input in .req directive.");
7797 }
7798
7799 Parser.Lex(); // Consume the EndOfStatement
7800
7801 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7802 return Error(SRegLoc, "redefinition of '" + Name +
7803 "' does not match original.");
7804
7805 return false;
7806}
7807
7808/// parseDirectiveUneq
7809/// ::= .unreq registername
7810bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7811 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7812 Parser.EatToEndOfStatement();
7813 return Error(L, "unexpected input in .unreq directive.");
7814 }
7815 RegisterReqs.erase(Parser.getTok().getIdentifier());
7816 Parser.Lex(); // Eat the identifier.
7817 return false;
7818}
7819
Jason W Kim135d2442011-12-20 17:38:12 +00007820/// parseDirectiveArch
7821/// ::= .arch token
7822bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7823 return true;
7824}
7825
7826/// parseDirectiveEabiAttr
7827/// ::= .eabi_attribute int, int
7828bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7829 return true;
7830}
7831
Sean Callanan643a5572010-04-07 20:29:34 +00007832extern "C" void LLVMInitializeARMAsmLexer();
7833
Kevin Enderby8be42bd2009-10-30 22:55:57 +00007834/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00007835extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00007836 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7837 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan643a5572010-04-07 20:29:34 +00007838 LLVMInitializeARMAsmLexer();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007839}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007840
Chris Lattner3e4582a2010-09-06 19:11:01 +00007841#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00007842#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00007843#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007844#include "ARMGenAsmMatcher.inc"