blob: 4d3bf34d48d3799b3ebe4deae19e5994bba59f10 [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Evan Cheng11424442011-07-26 00:24:13 +000010#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMBaseInfo.h"
13#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000014#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000015#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000018#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000019#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000021#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000023#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/MC/MCExpr.h"
25#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCInstrDesc.h"
27#include "llvm/MC/MCParser/MCAsmLexer.h"
28#include "llvm/MC/MCParser/MCAsmParser.h"
29#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
30#include "llvm/MC/MCRegisterInfo.h"
31#include "llvm/MC/MCStreamer.h"
32#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000033#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/Support/MathExtras.h"
35#include "llvm/Support/SourceMgr.h"
36#include "llvm/Support/TargetRegistry.h"
37#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000038
Kevin Enderbyccab3172009-09-15 00:27:25 +000039using namespace llvm;
40
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000041namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000042
43class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000044
Jim Grosbach04945c42011-12-02 00:35:16 +000045enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000046
Evan Cheng11424442011-07-26 00:24:13 +000047class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000048 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000049 MCAsmParser &Parser;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000050 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000051
Logan Chien4ea23b52013-05-10 16:17:24 +000052 // Unwind directives state
53 SMLoc FnStartLoc;
54 SMLoc CantUnwindLoc;
55 SMLoc PersonalityLoc;
56 SMLoc HandlerDataLoc;
57 int FPReg;
58 void resetUnwindDirectiveParserState() {
59 FnStartLoc = SMLoc();
60 CantUnwindLoc = SMLoc();
61 PersonalityLoc = SMLoc();
62 HandlerDataLoc = SMLoc();
63 FPReg = -1;
64 }
65
Jim Grosbachab5830e2011-12-14 02:16:11 +000066 // Map of register aliases registers via the .req directive.
67 StringMap<unsigned> RegisterReqs;
68
Jim Grosbached16ec42011-08-29 22:24:09 +000069 struct {
70 ARMCC::CondCodes Cond; // Condition for IT block.
71 unsigned Mask:4; // Condition mask for instructions.
72 // Starting at first 1 (from lsb).
73 // '1' condition as indicated in IT.
74 // '0' inverse of condition (else).
75 // Count of instructions in IT block is
76 // 4 - trailingzeroes(mask)
77
78 bool FirstCond; // Explicit flag for when we're parsing the
79 // First instruction in the IT block. It's
80 // implied in the mask, so needs special
81 // handling.
82
83 unsigned CurPosition; // Current position in parsing of IT
84 // block. In range [0,3]. Initialized
85 // according to count of instructions in block.
86 // ~0U if no active IT block.
87 } ITState;
88 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000089 void forwardITPosition() {
90 if (!inITBlock()) return;
91 // Move to the next instruction in the IT block, if there is one. If not,
92 // mark the block as done.
93 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
94 if (++ITState.CurPosition == 5 - TZ)
95 ITState.CurPosition = ~0U; // Done with the IT block after this.
96 }
Jim Grosbached16ec42011-08-29 22:24:09 +000097
98
Kevin Enderbyccab3172009-09-15 00:27:25 +000099 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000100 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
101
Benjamin Kramer673824b2012-04-15 17:04:27 +0000102 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000103 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000104 return Parser.Warning(L, Msg, Ranges);
105 }
106 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000107 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000108 return Parser.Error(L, Msg, Ranges);
109 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000110
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000111 int tryParseRegister();
112 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000113 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000115 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000116 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
117 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000118 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
119 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000120 bool parseDirectiveWord(unsigned Size, SMLoc L);
121 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000122 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000123 bool parseDirectiveThumbFunc(SMLoc L);
124 bool parseDirectiveCode(SMLoc L);
125 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000126 bool parseDirectiveReq(StringRef Name, SMLoc L);
127 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000128 bool parseDirectiveArch(SMLoc L);
129 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000130 bool parseDirectiveFnStart(SMLoc L);
131 bool parseDirectiveFnEnd(SMLoc L);
132 bool parseDirectiveCantUnwind(SMLoc L);
133 bool parseDirectivePersonality(SMLoc L);
134 bool parseDirectiveHandlerData(SMLoc L);
135 bool parseDirectiveSetFP(SMLoc L);
136 bool parseDirectivePad(SMLoc L);
137 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000138
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000139 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000140 bool &CarrySetting, unsigned &ProcessorIMod,
141 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000142 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000143 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000144
Evan Cheng4d1ca962011-07-08 01:53:10 +0000145 bool isThumb() const {
146 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000147 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000148 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000149 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000150 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000151 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000152 bool isThumbTwo() const {
153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
154 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000155 bool hasV6Ops() const {
156 return STI.getFeatureBits() & ARM::HasV6Ops;
157 }
James Molloy21efa7d2011-09-28 14:21:38 +0000158 bool hasV7Ops() const {
159 return STI.getFeatureBits() & ARM::HasV7Ops;
160 }
Evan Cheng284b4672011-07-08 22:36:29 +0000161 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000162 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
163 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000164 }
James Molloy21efa7d2011-09-28 14:21:38 +0000165 bool isMClass() const {
166 return STI.getFeatureBits() & ARM::FeatureMClass;
167 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000168
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000169 /// @name Auto-generated Match Functions
170 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000171
Chris Lattner3e4582a2010-09-06 19:11:01 +0000172#define GET_ASSEMBLER_HEADER
173#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000174
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000175 /// }
176
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000177 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000178 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000179 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000180 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000181 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000182 OperandMatchResultTy parseCoprocOptionOperand(
183 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000184 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000185 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000186 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000187 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000188 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000189 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000190 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
191 StringRef Op, int Low, int High);
192 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
193 return parsePKHImm(O, "lsl", 0, 31);
194 }
195 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
196 return parsePKHImm(O, "asr", 1, 32);
197 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000198 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000199 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000200 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000201 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000202 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000203 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000204 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000205 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000206 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
207 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000208
209 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000210 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
211 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
212 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +0000213 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000214 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +0000215 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000216 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000217 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000218 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +0000219 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000220 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +0000221 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000222 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000223 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000224 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +0000225 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000226 void cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000227 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000228 void cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000229 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000230 void cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000231 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000232 void cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000233 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000234 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
235 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
236 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +0000237 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000238 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000239 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000240 void cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000241 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000242 void cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000243 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000244 void cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000245 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000246 void cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000247 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000248 bool validateInstruction(MCInst &Inst,
249 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000250 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000251 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000252 bool shouldOmitCCOutOperand(StringRef Mnemonic,
253 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000254
Kevin Enderbyccab3172009-09-15 00:27:25 +0000255public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000256 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000257 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000258 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000259 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000260 Match_RequiresThumb2,
261#define GET_OPERAND_DIAGNOSTIC_TYPES
262#include "ARMGenAsmMatcher.inc"
263
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000264 };
265
Evan Cheng91111d22011-07-09 05:47:46 +0000266 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Logan Chien4ea23b52013-05-10 16:17:24 +0000267 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000268 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000269
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000270 // Cache the MCRegisterInfo.
271 MRI = &getContext().getRegisterInfo();
272
Evan Cheng4d1ca962011-07-08 01:53:10 +0000273 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000274 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000275
276 // Not in an ITBlock to start with.
277 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000278
279 // Set ELF header flags.
280 // FIXME: This should eventually end up somewhere else where more
281 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000282 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
283 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
284 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000285 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000286
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000287 // Implementation of the MCTargetAsmParser interface:
288 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000289 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
290 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000291 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000292 bool ParseDirective(AsmToken DirectiveID);
293
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000294 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000295 unsigned checkTargetMatchPredicate(MCInst &Inst);
296
Chad Rosier49963552012-10-13 00:26:04 +0000297 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000298 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000299 MCStreamer &Out, unsigned &ErrorInfo,
300 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000301};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000302} // end anonymous namespace
303
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000304namespace {
305
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000306/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000307/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000308class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000309 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000310 k_CondCode,
311 k_CCOut,
312 k_ITCondMask,
313 k_CoprocNum,
314 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000315 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000316 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000317 k_MemBarrierOpt,
318 k_Memory,
319 k_PostIndexRegister,
320 k_MSRMask,
321 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000322 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000323 k_Register,
324 k_RegisterList,
325 k_DPRRegisterList,
326 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000327 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000328 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000329 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000330 k_ShiftedRegister,
331 k_ShiftedImmediate,
332 k_ShifterImmediate,
333 k_RotateImmediate,
334 k_BitfieldDescriptor,
335 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000336 } Kind;
337
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000338 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000339 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000340
Eric Christopher8996c5d2013-03-15 00:42:55 +0000341 struct CCOp {
342 ARMCC::CondCodes Val;
343 };
344
345 struct CopOp {
346 unsigned Val;
347 };
348
349 struct CoprocOptionOp {
350 unsigned Val;
351 };
352
353 struct ITMaskOp {
354 unsigned Mask:4;
355 };
356
357 struct MBOptOp {
358 ARM_MB::MemBOpt Val;
359 };
360
361 struct IFlagsOp {
362 ARM_PROC::IFlags Val;
363 };
364
365 struct MMaskOp {
366 unsigned Val;
367 };
368
369 struct TokOp {
370 const char *Data;
371 unsigned Length;
372 };
373
374 struct RegOp {
375 unsigned RegNum;
376 };
377
378 // A vector register list is a sequential list of 1 to 4 registers.
379 struct VectorListOp {
380 unsigned RegNum;
381 unsigned Count;
382 unsigned LaneIndex;
383 bool isDoubleSpaced;
384 };
385
386 struct VectorIndexOp {
387 unsigned Val;
388 };
389
390 struct ImmOp {
391 const MCExpr *Val;
392 };
393
394 /// Combined record for all forms of ARM address expressions.
395 struct MemoryOp {
396 unsigned BaseRegNum;
397 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
398 // was specified.
399 const MCConstantExpr *OffsetImm; // Offset immediate value
400 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
401 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
402 unsigned ShiftImm; // shift for OffsetReg.
403 unsigned Alignment; // 0 = no alignment specified
404 // n = alignment in bytes (2, 4, 8, 16, or 32)
405 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
406 };
407
408 struct PostIdxRegOp {
409 unsigned RegNum;
410 bool isAdd;
411 ARM_AM::ShiftOpc ShiftTy;
412 unsigned ShiftImm;
413 };
414
415 struct ShifterImmOp {
416 bool isASR;
417 unsigned Imm;
418 };
419
420 struct RegShiftedRegOp {
421 ARM_AM::ShiftOpc ShiftTy;
422 unsigned SrcReg;
423 unsigned ShiftReg;
424 unsigned ShiftImm;
425 };
426
427 struct RegShiftedImmOp {
428 ARM_AM::ShiftOpc ShiftTy;
429 unsigned SrcReg;
430 unsigned ShiftImm;
431 };
432
433 struct RotImmOp {
434 unsigned Imm;
435 };
436
437 struct BitfieldOp {
438 unsigned LSB;
439 unsigned Width;
440 };
441
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000442 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000443 struct CCOp CC;
444 struct CopOp Cop;
445 struct CoprocOptionOp CoprocOption;
446 struct MBOptOp MBOpt;
447 struct ITMaskOp ITMask;
448 struct IFlagsOp IFlags;
449 struct MMaskOp MMask;
450 struct TokOp Tok;
451 struct RegOp Reg;
452 struct VectorListOp VectorList;
453 struct VectorIndexOp VectorIndex;
454 struct ImmOp Imm;
455 struct MemoryOp Memory;
456 struct PostIdxRegOp PostIdxReg;
457 struct ShifterImmOp ShifterImm;
458 struct RegShiftedRegOp RegShiftedReg;
459 struct RegShiftedImmOp RegShiftedImm;
460 struct RotImmOp RotImm;
461 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000462 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000463
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000464 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
465public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000466 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
467 Kind = o.Kind;
468 StartLoc = o.StartLoc;
469 EndLoc = o.EndLoc;
470 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000471 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000472 CC = o.CC;
473 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000474 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000475 ITMask = o.ITMask;
476 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000477 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000478 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000479 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000480 case k_CCOut:
481 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000482 Reg = o.Reg;
483 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000484 case k_RegisterList:
485 case k_DPRRegisterList:
486 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000487 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000488 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000489 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000490 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000491 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000492 VectorList = o.VectorList;
493 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000494 case k_CoprocNum:
495 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000496 Cop = o.Cop;
497 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000498 case k_CoprocOption:
499 CoprocOption = o.CoprocOption;
500 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000501 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000502 Imm = o.Imm;
503 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000504 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000505 MBOpt = o.MBOpt;
506 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000507 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000508 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000509 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000510 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000511 PostIdxReg = o.PostIdxReg;
512 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000513 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000514 MMask = o.MMask;
515 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000516 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000517 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000518 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000519 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000520 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000521 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000522 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000523 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000524 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000525 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000526 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000527 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000528 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000529 RotImm = o.RotImm;
530 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000531 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000532 Bitfield = o.Bitfield;
533 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000534 case k_VectorIndex:
535 VectorIndex = o.VectorIndex;
536 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000537 }
538 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000539
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000540 /// getStartLoc - Get the location of the first token of this operand.
541 SMLoc getStartLoc() const { return StartLoc; }
542 /// getEndLoc - Get the location of the last token of this operand.
543 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000544 /// getLocRange - Get the range between the first and last token of this
545 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000546 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
547
Daniel Dunbard8042b72010-08-11 06:36:53 +0000548 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000549 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000550 return CC.Val;
551 }
552
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000553 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000554 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000555 return Cop.Val;
556 }
557
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000558 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000559 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000560 return StringRef(Tok.Data, Tok.Length);
561 }
562
563 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000564 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000565 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000566 }
567
Bill Wendlingbed94652010-11-09 23:28:44 +0000568 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000569 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
570 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000571 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000572 }
573
Kevin Enderbyf5079942009-10-13 22:19:02 +0000574 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000575 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000576 return Imm.Val;
577 }
578
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000579 unsigned getVectorIndex() const {
580 assert(Kind == k_VectorIndex && "Invalid access!");
581 return VectorIndex.Val;
582 }
583
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000584 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000585 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000586 return MBOpt.Val;
587 }
588
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000589 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000590 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000591 return IFlags.Val;
592 }
593
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000594 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000595 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000596 return MMask.Val;
597 }
598
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000599 bool isCoprocNum() const { return Kind == k_CoprocNum; }
600 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000601 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000602 bool isCondCode() const { return Kind == k_CondCode; }
603 bool isCCOut() const { return Kind == k_CCOut; }
604 bool isITMask() const { return Kind == k_ITCondMask; }
605 bool isITCondCode() const { return Kind == k_CondCode; }
606 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000607 bool isFPImm() const {
608 if (!isImm()) return false;
609 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
610 if (!CE) return false;
611 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
612 return Val != -1;
613 }
Jim Grosbachea231912011-12-22 22:19:05 +0000614 bool isFBits16() const {
615 if (!isImm()) return false;
616 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
617 if (!CE) return false;
618 int64_t Value = CE->getValue();
619 return Value >= 0 && Value <= 16;
620 }
621 bool isFBits32() const {
622 if (!isImm()) return false;
623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
624 if (!CE) return false;
625 int64_t Value = CE->getValue();
626 return Value >= 1 && Value <= 32;
627 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000628 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000629 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000630 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
631 if (!CE) return false;
632 int64_t Value = CE->getValue();
633 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
634 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000635 bool isImm0_4() const {
636 if (!isImm()) return false;
637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
638 if (!CE) return false;
639 int64_t Value = CE->getValue();
640 return Value >= 0 && Value < 5;
641 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000642 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000643 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
645 if (!CE) return false;
646 int64_t Value = CE->getValue();
647 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
648 }
649 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000650 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000651 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
652 if (!CE) return false;
653 int64_t Value = CE->getValue();
654 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
655 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000656 bool isImm0_508s4Neg() const {
657 if (!isImm()) return false;
658 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
659 if (!CE) return false;
660 int64_t Value = -CE->getValue();
661 // explicitly exclude zero. we want that to use the normal 0_508 version.
662 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
663 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000664 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000665 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000666 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
667 if (!CE) return false;
668 int64_t Value = CE->getValue();
669 return Value >= 0 && Value < 256;
670 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000671 bool isImm0_4095() const {
672 if (!isImm()) return false;
673 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
674 if (!CE) return false;
675 int64_t Value = CE->getValue();
676 return Value >= 0 && Value < 4096;
677 }
678 bool isImm0_4095Neg() const {
679 if (!isImm()) return false;
680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
681 if (!CE) return false;
682 int64_t Value = -CE->getValue();
683 return Value > 0 && Value < 4096;
684 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000685 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000686 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000687 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
688 if (!CE) return false;
689 int64_t Value = CE->getValue();
690 return Value >= 0 && Value < 2;
691 }
692 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000693 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000694 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
695 if (!CE) return false;
696 int64_t Value = CE->getValue();
697 return Value >= 0 && Value < 4;
698 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000699 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000700 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000701 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
702 if (!CE) return false;
703 int64_t Value = CE->getValue();
704 return Value >= 0 && Value < 8;
705 }
706 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000707 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
709 if (!CE) return false;
710 int64_t Value = CE->getValue();
711 return Value >= 0 && Value < 16;
712 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000713 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000714 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000715 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
716 if (!CE) return false;
717 int64_t Value = CE->getValue();
718 return Value >= 0 && Value < 32;
719 }
Jim Grosbach00326402011-12-08 01:30:04 +0000720 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000721 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000722 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
723 if (!CE) return false;
724 int64_t Value = CE->getValue();
725 return Value >= 0 && Value < 64;
726 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000727 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000728 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000729 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
730 if (!CE) return false;
731 int64_t Value = CE->getValue();
732 return Value == 8;
733 }
734 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000735 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
737 if (!CE) return false;
738 int64_t Value = CE->getValue();
739 return Value == 16;
740 }
741 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000742 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000743 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
744 if (!CE) return false;
745 int64_t Value = CE->getValue();
746 return Value == 32;
747 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000748 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000749 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000750 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
751 if (!CE) return false;
752 int64_t Value = CE->getValue();
753 return Value > 0 && Value <= 8;
754 }
755 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000756 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000757 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
758 if (!CE) return false;
759 int64_t Value = CE->getValue();
760 return Value > 0 && Value <= 16;
761 }
762 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000763 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
765 if (!CE) return false;
766 int64_t Value = CE->getValue();
767 return Value > 0 && Value <= 32;
768 }
769 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000770 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000771 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
772 if (!CE) return false;
773 int64_t Value = CE->getValue();
774 return Value > 0 && Value <= 64;
775 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000776 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000777 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
779 if (!CE) return false;
780 int64_t Value = CE->getValue();
781 return Value > 0 && Value < 8;
782 }
783 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000784 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
786 if (!CE) return false;
787 int64_t Value = CE->getValue();
788 return Value > 0 && Value < 16;
789 }
790 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000791 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +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 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000797 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000798 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000799 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
800 if (!CE) return false;
801 int64_t Value = CE->getValue();
802 return Value > 0 && Value < 17;
803 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000804 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000805 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
807 if (!CE) return false;
808 int64_t Value = CE->getValue();
809 return Value > 0 && Value < 33;
810 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000811 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000812 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000813 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
814 if (!CE) return false;
815 int64_t Value = CE->getValue();
816 return Value >= 0 && Value < 33;
817 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000818 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000819 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = CE->getValue();
823 return Value >= 0 && Value < 65536;
824 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000825 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000826 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
828 // If it's not a constant expression, it'll generate a fixup and be
829 // handled later.
830 if (!CE) return true;
831 int64_t Value = CE->getValue();
832 return Value >= 0 && Value < 65536;
833 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000834 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000835 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000836 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
837 if (!CE) return false;
838 int64_t Value = CE->getValue();
839 return Value >= 0 && Value <= 0xffffff;
840 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000841 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000842 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000843 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
844 if (!CE) return false;
845 int64_t Value = CE->getValue();
846 return Value > 0 && Value < 33;
847 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000848 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000849 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
851 if (!CE) return false;
852 int64_t Value = CE->getValue();
853 return Value >= 0 && Value < 32;
854 }
855 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000856 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000857 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
858 if (!CE) return false;
859 int64_t Value = CE->getValue();
860 return Value > 0 && Value <= 32;
861 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000862 bool isAdrLabel() const {
863 // If we have an immediate that's not a constant, treat it as a label
864 // reference needing a fixup. If it is a constant, but it can't fit
865 // into shift immediate encoding, we reject it.
866 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
867 else return (isARMSOImm() || isARMSOImmNeg());
868 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000869 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000870 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000871 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
872 if (!CE) return false;
873 int64_t Value = CE->getValue();
874 return ARM_AM::getSOImmVal(Value) != -1;
875 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000876 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000877 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000878 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
879 if (!CE) return false;
880 int64_t Value = CE->getValue();
881 return ARM_AM::getSOImmVal(~Value) != -1;
882 }
Jim Grosbach30506252011-12-08 00:31:07 +0000883 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000884 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000885 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
886 if (!CE) return false;
887 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000888 // Only use this when not representable as a plain so_imm.
889 return ARM_AM::getSOImmVal(Value) == -1 &&
890 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000891 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000892 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000893 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000894 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
895 if (!CE) return false;
896 int64_t Value = CE->getValue();
897 return ARM_AM::getT2SOImmVal(Value) != -1;
898 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000899 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000900 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000901 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
902 if (!CE) return false;
903 int64_t Value = CE->getValue();
904 return ARM_AM::getT2SOImmVal(~Value) != -1;
905 }
Jim Grosbach30506252011-12-08 00:31:07 +0000906 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000907 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
909 if (!CE) return false;
910 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000911 // Only use this when not representable as a plain so_imm.
912 return ARM_AM::getT2SOImmVal(Value) == -1 &&
913 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000914 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000915 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000916 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
918 if (!CE) return false;
919 int64_t Value = CE->getValue();
920 return Value == 1 || Value == 0;
921 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000922 bool isReg() const { return Kind == k_Register; }
923 bool isRegList() const { return Kind == k_RegisterList; }
924 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
925 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
926 bool isToken() const { return Kind == k_Token; }
927 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000928 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000929 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
930 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
931 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
932 bool isRotImm() const { return Kind == k_RotateImmediate; }
933 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
934 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000935 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000936 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000937 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000938 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000939 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000940 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000941 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000942 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
943 (alignOK || Memory.Alignment == 0);
944 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000945 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000946 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000947 return false;
948 // Base register must be PC.
949 if (Memory.BaseRegNum != ARM::PC)
950 return false;
951 // Immediate offset in range [-4095, 4095].
952 if (!Memory.OffsetImm) return true;
953 int64_t Val = Memory.OffsetImm->getValue();
954 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
955 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000956 bool isAlignedMemory() const {
957 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000958 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000959 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000960 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000961 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000962 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000963 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000964 if (!Memory.OffsetImm) return true;
965 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000966 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000967 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000968 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000969 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000970 // Immediate offset in range [-4095, 4095].
971 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
972 if (!CE) return false;
973 int64_t Val = CE->getValue();
974 return Val > -4096 && Val < 4096;
975 }
Jim Grosbach5b96b802011-08-10 20:29:19 +0000976 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +0000977 // If we have an immediate that's not a constant, treat it as a label
978 // reference needing a fixup. If it is a constant, it's something else
979 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000980 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +0000981 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000982 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000983 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +0000984 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000985 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000986 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000987 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +0000988 if (!Memory.OffsetImm) return true;
989 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +0000990 // The #-0 offset is encoded as INT32_MIN, and we have to check
991 // for this too.
992 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000993 }
994 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000995 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000996 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000997 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000998 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
999 // Immediate offset in range [-255, 255].
1000 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1001 if (!CE) return false;
1002 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001003 // Special case, #-0 is INT32_MIN.
1004 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001005 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001006 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001007 // If we have an immediate that's not a constant, treat it as a label
1008 // reference needing a fixup. If it is a constant, it's something else
1009 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001010 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001011 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001012 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001013 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001014 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001015 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001016 if (!Memory.OffsetImm) return true;
1017 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001018 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001019 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001020 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001021 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001022 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001023 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001024 return false;
1025 return true;
1026 }
1027 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001028 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001029 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1030 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001031 return false;
1032 return true;
1033 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001034 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001035 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001036 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001037 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001038 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001039 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001040 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001041 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001042 return false;
1043 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001044 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001045 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001046 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001047 return false;
1048 return true;
1049 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001050 bool isMemThumbRR() const {
1051 // Thumb reg+reg addressing is simple. Just two registers, a base and
1052 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001053 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001054 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001055 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001056 return isARMLowRegister(Memory.BaseRegNum) &&
1057 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001058 }
1059 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001060 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001061 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001062 return false;
1063 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001064 if (!Memory.OffsetImm) return true;
1065 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001066 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1067 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001068 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001069 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001070 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001071 return false;
1072 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001073 if (!Memory.OffsetImm) return true;
1074 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001075 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1076 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001077 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001078 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001079 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001080 return false;
1081 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001082 if (!Memory.OffsetImm) return true;
1083 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001084 return Val >= 0 && Val <= 31;
1085 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001086 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001087 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001088 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001089 return false;
1090 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001091 if (!Memory.OffsetImm) return true;
1092 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001093 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001094 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001095 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001096 // If we have an immediate that's not a constant, treat it as a label
1097 // reference needing a fixup. If it is a constant, it's something else
1098 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001099 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001100 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001101 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001102 return false;
1103 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001104 if (!Memory.OffsetImm) return true;
1105 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001106 // Special case, #-0 is INT32_MIN.
1107 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001108 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001109 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001110 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001111 return false;
1112 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001113 if (!Memory.OffsetImm) return true;
1114 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001115 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1116 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001117 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001118 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001119 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001120 // Base reg of PC isn't allowed for these encodings.
1121 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001122 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001123 if (!Memory.OffsetImm) return true;
1124 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001125 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001126 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001127 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001128 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001129 return false;
1130 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001131 if (!Memory.OffsetImm) return true;
1132 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001133 return Val >= 0 && Val < 256;
1134 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001135 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001136 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001137 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001138 // Base reg of PC isn't allowed for these encodings.
1139 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001140 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001141 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001142 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001143 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001144 }
1145 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001146 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001147 return false;
1148 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001149 if (!Memory.OffsetImm) return true;
1150 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001151 return (Val >= 0 && Val < 4096);
1152 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001153 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001154 // If we have an immediate that's not a constant, treat it as a label
1155 // reference needing a fixup. If it is a constant, it's something else
1156 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001157 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001158 return true;
1159
Chad Rosier41099832012-09-11 23:02:35 +00001160 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001161 return false;
1162 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001163 if (!Memory.OffsetImm) return true;
1164 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001165 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001166 }
1167 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001168 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001169 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1170 if (!CE) return false;
1171 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001172 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001173 }
Jim Grosbach93981412011-10-11 21:55:36 +00001174 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001175 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1177 if (!CE) return false;
1178 int64_t Val = CE->getValue();
1179 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1180 (Val == INT32_MIN);
1181 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001182
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001183 bool isMSRMask() const { return Kind == k_MSRMask; }
1184 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001185
Jim Grosbach741cd732011-10-17 22:26:03 +00001186 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001187 bool isSingleSpacedVectorList() const {
1188 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1189 }
1190 bool isDoubleSpacedVectorList() const {
1191 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1192 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001193 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001194 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001195 return VectorList.Count == 1;
1196 }
1197
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001198 bool isVecListDPair() const {
1199 if (!isSingleSpacedVectorList()) return false;
1200 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1201 .contains(VectorList.RegNum));
1202 }
1203
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001204 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001205 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001206 return VectorList.Count == 3;
1207 }
1208
Jim Grosbach846bcff2011-10-21 20:35:01 +00001209 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001210 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001211 return VectorList.Count == 4;
1212 }
1213
Jim Grosbache5307f92012-03-05 21:43:40 +00001214 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001215 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001216 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1217 .contains(VectorList.RegNum));
1218 }
1219
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001220 bool isVecListThreeQ() const {
1221 if (!isDoubleSpacedVectorList()) return false;
1222 return VectorList.Count == 3;
1223 }
1224
Jim Grosbach1e946a42012-01-24 00:43:12 +00001225 bool isVecListFourQ() const {
1226 if (!isDoubleSpacedVectorList()) return false;
1227 return VectorList.Count == 4;
1228 }
1229
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001230 bool isSingleSpacedVectorAllLanes() const {
1231 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1232 }
1233 bool isDoubleSpacedVectorAllLanes() const {
1234 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1235 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001236 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001237 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001238 return VectorList.Count == 1;
1239 }
1240
Jim Grosbach13a292c2012-03-06 22:01:44 +00001241 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001242 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001243 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1244 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001245 }
1246
Jim Grosbached428bc2012-03-06 23:10:38 +00001247 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001248 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001249 return VectorList.Count == 2;
1250 }
1251
Jim Grosbachb78403c2012-01-24 23:47:04 +00001252 bool isVecListThreeDAllLanes() const {
1253 if (!isSingleSpacedVectorAllLanes()) return false;
1254 return VectorList.Count == 3;
1255 }
1256
1257 bool isVecListThreeQAllLanes() const {
1258 if (!isDoubleSpacedVectorAllLanes()) return false;
1259 return VectorList.Count == 3;
1260 }
1261
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001262 bool isVecListFourDAllLanes() const {
1263 if (!isSingleSpacedVectorAllLanes()) return false;
1264 return VectorList.Count == 4;
1265 }
1266
1267 bool isVecListFourQAllLanes() const {
1268 if (!isDoubleSpacedVectorAllLanes()) return false;
1269 return VectorList.Count == 4;
1270 }
1271
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001272 bool isSingleSpacedVectorIndexed() const {
1273 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1274 }
1275 bool isDoubleSpacedVectorIndexed() const {
1276 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1277 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001278 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001279 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001280 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1281 }
1282
Jim Grosbachda511042011-12-14 23:35:06 +00001283 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001284 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001285 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1286 }
1287
1288 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001289 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001290 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1291 }
1292
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001293 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001294 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001295 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1296 }
1297
Jim Grosbachda511042011-12-14 23:35:06 +00001298 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001299 if (!isSingleSpacedVectorIndexed()) return false;
1300 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1301 }
1302
1303 bool isVecListTwoQWordIndexed() const {
1304 if (!isDoubleSpacedVectorIndexed()) return false;
1305 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1306 }
1307
1308 bool isVecListTwoQHWordIndexed() const {
1309 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001310 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1311 }
1312
1313 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001314 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001315 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1316 }
1317
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001318 bool isVecListThreeDByteIndexed() const {
1319 if (!isSingleSpacedVectorIndexed()) return false;
1320 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1321 }
1322
1323 bool isVecListThreeDHWordIndexed() const {
1324 if (!isSingleSpacedVectorIndexed()) return false;
1325 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1326 }
1327
1328 bool isVecListThreeQWordIndexed() const {
1329 if (!isDoubleSpacedVectorIndexed()) return false;
1330 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1331 }
1332
1333 bool isVecListThreeQHWordIndexed() const {
1334 if (!isDoubleSpacedVectorIndexed()) return false;
1335 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1336 }
1337
1338 bool isVecListThreeDWordIndexed() const {
1339 if (!isSingleSpacedVectorIndexed()) return false;
1340 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1341 }
1342
Jim Grosbach14952a02012-01-24 18:37:25 +00001343 bool isVecListFourDByteIndexed() const {
1344 if (!isSingleSpacedVectorIndexed()) return false;
1345 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1346 }
1347
1348 bool isVecListFourDHWordIndexed() const {
1349 if (!isSingleSpacedVectorIndexed()) return false;
1350 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1351 }
1352
1353 bool isVecListFourQWordIndexed() const {
1354 if (!isDoubleSpacedVectorIndexed()) return false;
1355 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1356 }
1357
1358 bool isVecListFourQHWordIndexed() const {
1359 if (!isDoubleSpacedVectorIndexed()) return false;
1360 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1361 }
1362
1363 bool isVecListFourDWordIndexed() const {
1364 if (!isSingleSpacedVectorIndexed()) return false;
1365 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1366 }
1367
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001368 bool isVectorIndex8() const {
1369 if (Kind != k_VectorIndex) return false;
1370 return VectorIndex.Val < 8;
1371 }
1372 bool isVectorIndex16() const {
1373 if (Kind != k_VectorIndex) return false;
1374 return VectorIndex.Val < 4;
1375 }
1376 bool isVectorIndex32() const {
1377 if (Kind != k_VectorIndex) return false;
1378 return VectorIndex.Val < 2;
1379 }
1380
Jim Grosbach741cd732011-10-17 22:26:03 +00001381 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001382 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001383 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1384 // Must be a constant.
1385 if (!CE) return false;
1386 int64_t Value = CE->getValue();
1387 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1388 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001389 return Value >= 0 && Value < 256;
1390 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001391
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001392 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001393 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001394 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1395 // Must be a constant.
1396 if (!CE) return false;
1397 int64_t Value = CE->getValue();
1398 // i16 value in the range [0,255] or [0x0100, 0xff00]
1399 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1400 }
1401
Jim Grosbach8211c052011-10-18 00:22:00 +00001402 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001403 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001404 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1405 // Must be a constant.
1406 if (!CE) return false;
1407 int64_t Value = CE->getValue();
1408 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1409 return (Value >= 0 && Value < 256) ||
1410 (Value >= 0x0100 && Value <= 0xff00) ||
1411 (Value >= 0x010000 && Value <= 0xff0000) ||
1412 (Value >= 0x01000000 && Value <= 0xff000000);
1413 }
1414
1415 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001416 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001417 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1418 // Must be a constant.
1419 if (!CE) return false;
1420 int64_t Value = CE->getValue();
1421 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1422 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1423 return (Value >= 0 && Value < 256) ||
1424 (Value >= 0x0100 && Value <= 0xff00) ||
1425 (Value >= 0x010000 && Value <= 0xff0000) ||
1426 (Value >= 0x01000000 && Value <= 0xff000000) ||
1427 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1428 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1429 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001430 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001431 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001432 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1433 // Must be a constant.
1434 if (!CE) return false;
1435 int64_t Value = ~CE->getValue();
1436 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1437 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1438 return (Value >= 0 && Value < 256) ||
1439 (Value >= 0x0100 && Value <= 0xff00) ||
1440 (Value >= 0x010000 && Value <= 0xff0000) ||
1441 (Value >= 0x01000000 && Value <= 0xff000000) ||
1442 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1443 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1444 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001445
Jim Grosbache4454e02011-10-18 16:18:11 +00001446 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001447 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001448 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1449 // Must be a constant.
1450 if (!CE) return false;
1451 uint64_t Value = CE->getValue();
1452 // i64 value with each byte being either 0 or 0xff.
1453 for (unsigned i = 0; i < 8; ++i)
1454 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1455 return true;
1456 }
1457
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001458 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001459 // Add as immediates when possible. Null MCExpr = 0.
1460 if (Expr == 0)
1461 Inst.addOperand(MCOperand::CreateImm(0));
1462 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001463 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1464 else
1465 Inst.addOperand(MCOperand::CreateExpr(Expr));
1466 }
1467
Daniel Dunbard8042b72010-08-11 06:36:53 +00001468 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001469 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001470 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001471 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1472 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001473 }
1474
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001475 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1476 assert(N == 1 && "Invalid number of operands!");
1477 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1478 }
1479
Jim Grosbach48399582011-10-12 17:34:41 +00001480 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1481 assert(N == 1 && "Invalid number of operands!");
1482 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1483 }
1484
1485 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1486 assert(N == 1 && "Invalid number of operands!");
1487 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1488 }
1489
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001490 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1491 assert(N == 1 && "Invalid number of operands!");
1492 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1493 }
1494
1495 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1496 assert(N == 1 && "Invalid number of operands!");
1497 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1498 }
1499
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001500 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1501 assert(N == 1 && "Invalid number of operands!");
1502 Inst.addOperand(MCOperand::CreateReg(getReg()));
1503 }
1504
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001505 void addRegOperands(MCInst &Inst, unsigned N) const {
1506 assert(N == 1 && "Invalid number of operands!");
1507 Inst.addOperand(MCOperand::CreateReg(getReg()));
1508 }
1509
Jim Grosbachac798e12011-07-25 20:49:51 +00001510 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001511 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001512 assert(isRegShiftedReg() &&
1513 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001514 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1515 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001516 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001517 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001518 }
1519
Jim Grosbachac798e12011-07-25 20:49:51 +00001520 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001521 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001522 assert(isRegShiftedImm() &&
1523 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001524 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001525 // Shift of #32 is encoded as 0 where permitted
1526 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001527 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001528 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001529 }
1530
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001531 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001532 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001533 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1534 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001535 }
1536
Bill Wendling8d2aa032010-11-08 23:49:57 +00001537 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001538 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001539 const SmallVectorImpl<unsigned> &RegList = getRegList();
1540 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001541 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1542 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001543 }
1544
Bill Wendling9898ac92010-11-17 04:32:08 +00001545 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1546 addRegListOperands(Inst, N);
1547 }
1548
1549 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1550 addRegListOperands(Inst, N);
1551 }
1552
Jim Grosbach833b9d32011-07-27 20:15:40 +00001553 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1556 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1557 }
1558
Jim Grosbach864b6092011-07-28 21:34:26 +00001559 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1560 assert(N == 1 && "Invalid number of operands!");
1561 // Munge the lsb/width into a bitfield mask.
1562 unsigned lsb = Bitfield.LSB;
1563 unsigned width = Bitfield.Width;
1564 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1565 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1566 (32 - (lsb + width)));
1567 Inst.addOperand(MCOperand::CreateImm(Mask));
1568 }
1569
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001570 void addImmOperands(MCInst &Inst, unsigned N) const {
1571 assert(N == 1 && "Invalid number of operands!");
1572 addExpr(Inst, getImm());
1573 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001574
Jim Grosbachea231912011-12-22 22:19:05 +00001575 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1576 assert(N == 1 && "Invalid number of operands!");
1577 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1578 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1579 }
1580
1581 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1582 assert(N == 1 && "Invalid number of operands!");
1583 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1584 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1585 }
1586
Jim Grosbache7fbce72011-10-03 23:38:36 +00001587 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1588 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001589 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1590 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1591 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001592 }
1593
Jim Grosbach7db8d692011-09-08 22:07:06 +00001594 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1595 assert(N == 1 && "Invalid number of operands!");
1596 // FIXME: We really want to scale the value here, but the LDRD/STRD
1597 // instruction don't encode operands that way yet.
1598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1599 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1600 }
1601
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001602 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1603 assert(N == 1 && "Invalid number of operands!");
1604 // The immediate is scaled by four in the encoding and is stored
1605 // in the MCInst as such. Lop off the low two bits here.
1606 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1607 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1608 }
1609
Jim Grosbach930f2f62012-04-05 20:57:13 +00001610 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1611 assert(N == 1 && "Invalid number of operands!");
1612 // The immediate is scaled by four in the encoding and is stored
1613 // in the MCInst as such. Lop off the low two bits here.
1614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1615 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1616 }
1617
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001618 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1619 assert(N == 1 && "Invalid number of operands!");
1620 // The immediate is scaled by four in the encoding and is stored
1621 // in the MCInst as such. Lop off the low two bits here.
1622 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1623 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1624 }
1625
Jim Grosbach475c6db2011-07-25 23:09:14 +00001626 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1627 assert(N == 1 && "Invalid number of operands!");
1628 // The constant encodes as the immediate-1, and we store in the instruction
1629 // the bits as encoded, so subtract off one here.
1630 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1631 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1632 }
1633
Jim Grosbach801e0a32011-07-22 23:16:18 +00001634 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1635 assert(N == 1 && "Invalid number of operands!");
1636 // The constant encodes as the immediate-1, and we store in the instruction
1637 // the bits as encoded, so subtract off one here.
1638 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1639 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1640 }
1641
Jim Grosbach46dd4132011-08-17 21:51:27 +00001642 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1643 assert(N == 1 && "Invalid number of operands!");
1644 // The constant encodes as the immediate, except for 32, which encodes as
1645 // zero.
1646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1647 unsigned Imm = CE->getValue();
1648 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1649 }
1650
Jim Grosbach27c1e252011-07-21 17:23:04 +00001651 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1652 assert(N == 1 && "Invalid number of operands!");
1653 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1654 // the instruction as well.
1655 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1656 int Val = CE->getValue();
1657 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1658 }
1659
Jim Grosbachb009a872011-10-28 22:36:30 +00001660 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1661 assert(N == 1 && "Invalid number of operands!");
1662 // The operand is actually a t2_so_imm, but we have its bitwise
1663 // negation in the assembly source, so twiddle it here.
1664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1665 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1666 }
1667
Jim Grosbach30506252011-12-08 00:31:07 +00001668 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1669 assert(N == 1 && "Invalid number of operands!");
1670 // The operand is actually a t2_so_imm, but we have its
1671 // negation in the assembly source, so twiddle it here.
1672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1673 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1674 }
1675
Jim Grosbach930f2f62012-04-05 20:57:13 +00001676 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1677 assert(N == 1 && "Invalid number of operands!");
1678 // The operand is actually an imm0_4095, but we have its
1679 // negation in the assembly source, so twiddle it here.
1680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1681 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1682 }
1683
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001684 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1685 assert(N == 1 && "Invalid number of operands!");
1686 // The operand is actually a so_imm, but we have its bitwise
1687 // negation in the assembly source, so twiddle it here.
1688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1689 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1690 }
1691
Jim Grosbach30506252011-12-08 00:31:07 +00001692 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1693 assert(N == 1 && "Invalid number of operands!");
1694 // The operand is actually a so_imm, but we have its
1695 // negation in the assembly source, so twiddle it here.
1696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1697 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1698 }
1699
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001700 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1701 assert(N == 1 && "Invalid number of operands!");
1702 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1703 }
1704
Jim Grosbachd3595712011-08-03 23:50:40 +00001705 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1706 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001707 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001708 }
1709
Jim Grosbach94298a92012-01-18 22:46:46 +00001710 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1711 assert(N == 1 && "Invalid number of operands!");
1712 int32_t Imm = Memory.OffsetImm->getValue();
1713 // FIXME: Handle #-0
1714 if (Imm == INT32_MIN) Imm = 0;
1715 Inst.addOperand(MCOperand::CreateImm(Imm));
1716 }
1717
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001718 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1719 assert(N == 1 && "Invalid number of operands!");
1720 assert(isImm() && "Not an immediate!");
1721
1722 // If we have an immediate that's not a constant, treat it as a label
1723 // reference needing a fixup.
1724 if (!isa<MCConstantExpr>(getImm())) {
1725 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1726 return;
1727 }
1728
1729 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1730 int Val = CE->getValue();
1731 Inst.addOperand(MCOperand::CreateImm(Val));
1732 }
1733
Jim Grosbacha95ec992011-10-11 17:29:55 +00001734 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1735 assert(N == 2 && "Invalid number of operands!");
1736 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1737 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1738 }
1739
Jim Grosbachd3595712011-08-03 23:50:40 +00001740 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1741 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001742 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1743 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001744 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1745 // Special case for #-0
1746 if (Val == INT32_MIN) Val = 0;
1747 if (Val < 0) Val = -Val;
1748 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1749 } else {
1750 // For register offset, we encode the shift type and negation flag
1751 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001752 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1753 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001754 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001755 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1756 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001757 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001758 }
1759
Jim Grosbachcd17c122011-08-04 23:01:30 +00001760 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1761 assert(N == 2 && "Invalid number of operands!");
1762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1763 assert(CE && "non-constant AM2OffsetImm operand!");
1764 int32_t Val = CE->getValue();
1765 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1766 // Special case for #-0
1767 if (Val == INT32_MIN) Val = 0;
1768 if (Val < 0) Val = -Val;
1769 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1770 Inst.addOperand(MCOperand::CreateReg(0));
1771 Inst.addOperand(MCOperand::CreateImm(Val));
1772 }
1773
Jim Grosbach5b96b802011-08-10 20:29:19 +00001774 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1775 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001776 // If we have an immediate that's not a constant, treat it as a label
1777 // reference needing a fixup. If it is a constant, it's something else
1778 // and we reject it.
1779 if (isImm()) {
1780 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1781 Inst.addOperand(MCOperand::CreateReg(0));
1782 Inst.addOperand(MCOperand::CreateImm(0));
1783 return;
1784 }
1785
Jim Grosbach871dff72011-10-11 15:59:20 +00001786 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1787 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001788 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1789 // Special case for #-0
1790 if (Val == INT32_MIN) Val = 0;
1791 if (Val < 0) Val = -Val;
1792 Val = ARM_AM::getAM3Opc(AddSub, Val);
1793 } else {
1794 // For register offset, we encode the shift type and negation flag
1795 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001796 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001797 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001798 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1799 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001800 Inst.addOperand(MCOperand::CreateImm(Val));
1801 }
1802
1803 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1804 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001805 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001806 int32_t Val =
1807 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1808 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1809 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001810 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001811 }
1812
1813 // Constant offset.
1814 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1815 int32_t Val = CE->getValue();
1816 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1817 // Special case for #-0
1818 if (Val == INT32_MIN) Val = 0;
1819 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001820 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001821 Inst.addOperand(MCOperand::CreateReg(0));
1822 Inst.addOperand(MCOperand::CreateImm(Val));
1823 }
1824
Jim Grosbachd3595712011-08-03 23:50:40 +00001825 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1826 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001827 // If we have an immediate that's not a constant, treat it as a label
1828 // reference needing a fixup. If it is a constant, it's something else
1829 // and we reject it.
1830 if (isImm()) {
1831 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1832 Inst.addOperand(MCOperand::CreateImm(0));
1833 return;
1834 }
1835
Jim Grosbachd3595712011-08-03 23:50:40 +00001836 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001837 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001838 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1839 // Special case for #-0
1840 if (Val == INT32_MIN) Val = 0;
1841 if (Val < 0) Val = -Val;
1842 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001843 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001844 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001845 }
1846
Jim Grosbach7db8d692011-09-08 22:07:06 +00001847 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1848 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001849 // If we have an immediate that's not a constant, treat it as a label
1850 // reference needing a fixup. If it is a constant, it's something else
1851 // and we reject it.
1852 if (isImm()) {
1853 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1854 Inst.addOperand(MCOperand::CreateImm(0));
1855 return;
1856 }
1857
Jim Grosbach871dff72011-10-11 15:59:20 +00001858 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1859 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001860 Inst.addOperand(MCOperand::CreateImm(Val));
1861 }
1862
Jim Grosbacha05627e2011-09-09 18:37:27 +00001863 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1864 assert(N == 2 && "Invalid number of operands!");
1865 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001866 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1867 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001868 Inst.addOperand(MCOperand::CreateImm(Val));
1869 }
1870
Jim Grosbachd3595712011-08-03 23:50:40 +00001871 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1872 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001873 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1874 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001875 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001876 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001877
Jim Grosbach2392c532011-09-07 23:39:14 +00001878 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1879 addMemImm8OffsetOperands(Inst, N);
1880 }
1881
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001882 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001883 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001884 }
1885
1886 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1887 assert(N == 2 && "Invalid number of operands!");
1888 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001889 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001890 addExpr(Inst, getImm());
1891 Inst.addOperand(MCOperand::CreateImm(0));
1892 return;
1893 }
1894
1895 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001896 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1897 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001898 Inst.addOperand(MCOperand::CreateImm(Val));
1899 }
1900
Jim Grosbachd3595712011-08-03 23:50:40 +00001901 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1902 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001903 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001904 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001905 addExpr(Inst, getImm());
1906 Inst.addOperand(MCOperand::CreateImm(0));
1907 return;
1908 }
1909
1910 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001911 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1912 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001913 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001914 }
Bill Wendling811c9362010-11-30 07:44:32 +00001915
Jim Grosbach05541f42011-09-19 22:21:13 +00001916 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1917 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001918 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1919 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001920 }
1921
1922 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1923 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001924 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1925 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001926 }
1927
Jim Grosbachd3595712011-08-03 23:50:40 +00001928 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1929 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001930 unsigned Val =
1931 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1932 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001933 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1934 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001935 Inst.addOperand(MCOperand::CreateImm(Val));
1936 }
1937
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001938 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1939 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001940 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1941 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1942 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001943 }
1944
Jim Grosbachd3595712011-08-03 23:50:40 +00001945 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1946 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001947 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1948 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001949 }
1950
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001951 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1952 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001953 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1954 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001955 Inst.addOperand(MCOperand::CreateImm(Val));
1956 }
1957
Jim Grosbach26d35872011-08-19 18:55:51 +00001958 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1959 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001960 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1961 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00001962 Inst.addOperand(MCOperand::CreateImm(Val));
1963 }
1964
Jim Grosbacha32c7532011-08-19 18:49:59 +00001965 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1966 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001967 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1968 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00001969 Inst.addOperand(MCOperand::CreateImm(Val));
1970 }
1971
Jim Grosbach23983d62011-08-19 18:13:48 +00001972 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1973 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001974 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1975 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00001976 Inst.addOperand(MCOperand::CreateImm(Val));
1977 }
1978
Jim Grosbachd3595712011-08-03 23:50:40 +00001979 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1980 assert(N == 1 && "Invalid number of operands!");
1981 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1982 assert(CE && "non-constant post-idx-imm8 operand!");
1983 int Imm = CE->getValue();
1984 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00001985 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001986 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1987 Inst.addOperand(MCOperand::CreateImm(Imm));
1988 }
1989
Jim Grosbach93981412011-10-11 21:55:36 +00001990 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1991 assert(N == 1 && "Invalid number of operands!");
1992 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1993 assert(CE && "non-constant post-idx-imm8s4 operand!");
1994 int Imm = CE->getValue();
1995 bool isAdd = Imm >= 0;
1996 if (Imm == INT32_MIN) Imm = 0;
1997 // Immediate is scaled by 4.
1998 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1999 Inst.addOperand(MCOperand::CreateImm(Imm));
2000 }
2001
Jim Grosbachd3595712011-08-03 23:50:40 +00002002 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2003 assert(N == 2 && "Invalid number of operands!");
2004 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002005 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2006 }
2007
2008 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 2 && "Invalid number of operands!");
2010 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2011 // The sign, shift type, and shift amount are encoded in a single operand
2012 // using the AM2 encoding helpers.
2013 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2014 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2015 PostIdxReg.ShiftTy);
2016 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002017 }
2018
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002019 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2020 assert(N == 1 && "Invalid number of operands!");
2021 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2022 }
2023
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002024 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2025 assert(N == 1 && "Invalid number of operands!");
2026 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2027 }
2028
Jim Grosbach182b6a02011-11-29 23:51:09 +00002029 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002030 assert(N == 1 && "Invalid number of operands!");
2031 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2032 }
2033
Jim Grosbach04945c42011-12-02 00:35:16 +00002034 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2035 assert(N == 2 && "Invalid number of operands!");
2036 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2037 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2038 }
2039
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002040 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2041 assert(N == 1 && "Invalid number of operands!");
2042 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2043 }
2044
2045 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2046 assert(N == 1 && "Invalid number of operands!");
2047 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2048 }
2049
2050 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2051 assert(N == 1 && "Invalid number of operands!");
2052 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2053 }
2054
Jim Grosbach741cd732011-10-17 22:26:03 +00002055 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2056 assert(N == 1 && "Invalid number of operands!");
2057 // The immediate encodes the type of constant as well as the value.
2058 // Mask in that this is an i8 splat.
2059 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2060 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2061 }
2062
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002063 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2064 assert(N == 1 && "Invalid number of operands!");
2065 // The immediate encodes the type of constant as well as the value.
2066 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2067 unsigned Value = CE->getValue();
2068 if (Value >= 256)
2069 Value = (Value >> 8) | 0xa00;
2070 else
2071 Value |= 0x800;
2072 Inst.addOperand(MCOperand::CreateImm(Value));
2073 }
2074
Jim Grosbach8211c052011-10-18 00:22:00 +00002075 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2076 assert(N == 1 && "Invalid number of operands!");
2077 // The immediate encodes the type of constant as well as the value.
2078 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2079 unsigned Value = CE->getValue();
2080 if (Value >= 256 && Value <= 0xff00)
2081 Value = (Value >> 8) | 0x200;
2082 else if (Value > 0xffff && Value <= 0xff0000)
2083 Value = (Value >> 16) | 0x400;
2084 else if (Value > 0xffffff)
2085 Value = (Value >> 24) | 0x600;
2086 Inst.addOperand(MCOperand::CreateImm(Value));
2087 }
2088
2089 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2090 assert(N == 1 && "Invalid number of operands!");
2091 // The immediate encodes the type of constant as well as the value.
2092 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2093 unsigned Value = CE->getValue();
2094 if (Value >= 256 && Value <= 0xffff)
2095 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2096 else if (Value > 0xffff && Value <= 0xffffff)
2097 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2098 else if (Value > 0xffffff)
2099 Value = (Value >> 24) | 0x600;
2100 Inst.addOperand(MCOperand::CreateImm(Value));
2101 }
2102
Jim Grosbach045b6c72011-12-19 23:51:07 +00002103 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2104 assert(N == 1 && "Invalid number of operands!");
2105 // The immediate encodes the type of constant as well as the value.
2106 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2107 unsigned Value = ~CE->getValue();
2108 if (Value >= 256 && Value <= 0xffff)
2109 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2110 else if (Value > 0xffff && Value <= 0xffffff)
2111 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2112 else if (Value > 0xffffff)
2113 Value = (Value >> 24) | 0x600;
2114 Inst.addOperand(MCOperand::CreateImm(Value));
2115 }
2116
Jim Grosbache4454e02011-10-18 16:18:11 +00002117 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2118 assert(N == 1 && "Invalid number of operands!");
2119 // The immediate encodes the type of constant as well as the value.
2120 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2121 uint64_t Value = CE->getValue();
2122 unsigned Imm = 0;
2123 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2124 Imm |= (Value & 1) << i;
2125 }
2126 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2127 }
2128
Jim Grosbach602aa902011-07-13 15:34:57 +00002129 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002130
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002131 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002132 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002133 Op->ITMask.Mask = Mask;
2134 Op->StartLoc = S;
2135 Op->EndLoc = S;
2136 return Op;
2137 }
2138
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002139 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002140 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002141 Op->CC.Val = CC;
2142 Op->StartLoc = S;
2143 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002144 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002145 }
2146
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002147 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002148 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002149 Op->Cop.Val = CopVal;
2150 Op->StartLoc = S;
2151 Op->EndLoc = S;
2152 return Op;
2153 }
2154
2155 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002156 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002157 Op->Cop.Val = CopVal;
2158 Op->StartLoc = S;
2159 Op->EndLoc = S;
2160 return Op;
2161 }
2162
Jim Grosbach48399582011-10-12 17:34:41 +00002163 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2164 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2165 Op->Cop.Val = Val;
2166 Op->StartLoc = S;
2167 Op->EndLoc = E;
2168 return Op;
2169 }
2170
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002171 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002172 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002173 Op->Reg.RegNum = RegNum;
2174 Op->StartLoc = S;
2175 Op->EndLoc = S;
2176 return Op;
2177 }
2178
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002179 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002180 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002181 Op->Tok.Data = Str.data();
2182 Op->Tok.Length = Str.size();
2183 Op->StartLoc = S;
2184 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002185 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002186 }
2187
Bill Wendling2063b842010-11-18 23:43:05 +00002188 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002189 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002190 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002191 Op->StartLoc = S;
2192 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002193 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002194 }
2195
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002196 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2197 unsigned SrcReg,
2198 unsigned ShiftReg,
2199 unsigned ShiftImm,
2200 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002201 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002202 Op->RegShiftedReg.ShiftTy = ShTy;
2203 Op->RegShiftedReg.SrcReg = SrcReg;
2204 Op->RegShiftedReg.ShiftReg = ShiftReg;
2205 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002206 Op->StartLoc = S;
2207 Op->EndLoc = E;
2208 return Op;
2209 }
2210
Owen Andersonb595ed02011-07-21 18:54:16 +00002211 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2212 unsigned SrcReg,
2213 unsigned ShiftImm,
2214 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002215 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002216 Op->RegShiftedImm.ShiftTy = ShTy;
2217 Op->RegShiftedImm.SrcReg = SrcReg;
2218 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002219 Op->StartLoc = S;
2220 Op->EndLoc = E;
2221 return Op;
2222 }
2223
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002224 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002225 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002226 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002227 Op->ShifterImm.isASR = isASR;
2228 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002229 Op->StartLoc = S;
2230 Op->EndLoc = E;
2231 return Op;
2232 }
2233
Jim Grosbach833b9d32011-07-27 20:15:40 +00002234 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002235 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002236 Op->RotImm.Imm = Imm;
2237 Op->StartLoc = S;
2238 Op->EndLoc = E;
2239 return Op;
2240 }
2241
Jim Grosbach864b6092011-07-28 21:34:26 +00002242 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2243 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002244 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002245 Op->Bitfield.LSB = LSB;
2246 Op->Bitfield.Width = Width;
2247 Op->StartLoc = S;
2248 Op->EndLoc = E;
2249 return Op;
2250 }
2251
Bill Wendling2cae3272010-11-09 22:44:22 +00002252 static ARMOperand *
Bill Wendlingbed94652010-11-09 23:28:44 +00002253 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002254 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002255 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002256
Jim Grosbach75461af2011-09-13 22:56:44 +00002257 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002258 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002259 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng9eec7642011-07-25 21:32:49 +00002260 contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002261 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002262
2263 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendlingbed94652010-11-09 23:28:44 +00002264 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002265 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling0ab0f672010-11-18 21:50:54 +00002266 Op->Registers.push_back(I->first);
Bill Wendling20b5ea982010-11-19 00:38:19 +00002267 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002268 Op->StartLoc = StartLoc;
2269 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002270 return Op;
2271 }
2272
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002273 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002274 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002275 ARMOperand *Op = new ARMOperand(k_VectorList);
2276 Op->VectorList.RegNum = RegNum;
2277 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002278 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002279 Op->StartLoc = S;
2280 Op->EndLoc = E;
2281 return Op;
2282 }
2283
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002284 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002285 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002286 SMLoc S, SMLoc E) {
2287 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2288 Op->VectorList.RegNum = RegNum;
2289 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002290 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002291 Op->StartLoc = S;
2292 Op->EndLoc = E;
2293 return Op;
2294 }
2295
Jim Grosbach04945c42011-12-02 00:35:16 +00002296 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002297 unsigned Index,
2298 bool isDoubleSpaced,
2299 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002300 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2301 Op->VectorList.RegNum = RegNum;
2302 Op->VectorList.Count = Count;
2303 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002304 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002305 Op->StartLoc = S;
2306 Op->EndLoc = E;
2307 return Op;
2308 }
2309
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002310 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2311 MCContext &Ctx) {
2312 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2313 Op->VectorIndex.Val = Idx;
2314 Op->StartLoc = S;
2315 Op->EndLoc = E;
2316 return Op;
2317 }
2318
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002319 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002320 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002321 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002322 Op->StartLoc = S;
2323 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002324 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002325 }
2326
Jim Grosbachd3595712011-08-03 23:50:40 +00002327 static ARMOperand *CreateMem(unsigned BaseRegNum,
2328 const MCConstantExpr *OffsetImm,
2329 unsigned OffsetRegNum,
2330 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002331 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002332 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002333 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002334 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002335 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002336 Op->Memory.BaseRegNum = BaseRegNum;
2337 Op->Memory.OffsetImm = OffsetImm;
2338 Op->Memory.OffsetRegNum = OffsetRegNum;
2339 Op->Memory.ShiftType = ShiftType;
2340 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002341 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002342 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002343 Op->StartLoc = S;
2344 Op->EndLoc = E;
2345 return Op;
2346 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002347
Jim Grosbachc320c852011-08-05 21:28:30 +00002348 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2349 ARM_AM::ShiftOpc ShiftTy,
2350 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002351 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002352 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002353 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002354 Op->PostIdxReg.isAdd = isAdd;
2355 Op->PostIdxReg.ShiftTy = ShiftTy;
2356 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002357 Op->StartLoc = S;
2358 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002359 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002360 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002361
2362 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002363 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002364 Op->MBOpt.Val = Opt;
2365 Op->StartLoc = S;
2366 Op->EndLoc = S;
2367 return Op;
2368 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002369
2370 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002371 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002372 Op->IFlags.Val = IFlags;
2373 Op->StartLoc = S;
2374 Op->EndLoc = S;
2375 return Op;
2376 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002377
2378 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002379 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002380 Op->MMask.Val = MMask;
2381 Op->StartLoc = S;
2382 Op->EndLoc = S;
2383 return Op;
2384 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002385};
2386
2387} // end anonymous namespace.
2388
Jim Grosbach602aa902011-07-13 15:34:57 +00002389void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002390 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002391 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002392 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002393 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002394 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002395 OS << "<ccout " << getReg() << ">";
2396 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002397 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002398 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002399 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2400 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2401 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002402 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2403 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2404 break;
2405 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002406 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002407 OS << "<coprocessor number: " << getCoproc() << ">";
2408 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002409 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002410 OS << "<coprocessor register: " << getCoproc() << ">";
2411 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002412 case k_CoprocOption:
2413 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2414 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002415 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002416 OS << "<mask: " << getMSRMask() << ">";
2417 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002418 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002419 getImm()->print(OS);
2420 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002421 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002422 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2423 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002424 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002425 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002426 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002427 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002428 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002429 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002430 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2431 << PostIdxReg.RegNum;
2432 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2433 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2434 << PostIdxReg.ShiftImm;
2435 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002436 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002437 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002438 OS << "<ARM_PROC::";
2439 unsigned IFlags = getProcIFlags();
2440 for (int i=2; i >= 0; --i)
2441 if (IFlags & (1 << i))
2442 OS << ARM_PROC::IFlagsToString(1 << i);
2443 OS << ">";
2444 break;
2445 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002446 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002447 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002448 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002449 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002450 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2451 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002452 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002453 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002454 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002455 << RegShiftedReg.SrcReg << " "
2456 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2457 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002458 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002459 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002460 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002461 << RegShiftedImm.SrcReg << " "
2462 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2463 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002464 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002465 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002466 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2467 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002468 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002469 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2470 << ", width: " << Bitfield.Width << ">";
2471 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002472 case k_RegisterList:
2473 case k_DPRRegisterList:
2474 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002475 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002476
Bill Wendlingbed94652010-11-09 23:28:44 +00002477 const SmallVectorImpl<unsigned> &RegList = getRegList();
2478 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002479 I = RegList.begin(), E = RegList.end(); I != E; ) {
2480 OS << *I;
2481 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002482 }
2483
2484 OS << ">";
2485 break;
2486 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002487 case k_VectorList:
2488 OS << "<vector_list " << VectorList.Count << " * "
2489 << VectorList.RegNum << ">";
2490 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002491 case k_VectorListAllLanes:
2492 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2493 << VectorList.RegNum << ">";
2494 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002495 case k_VectorListIndexed:
2496 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2497 << VectorList.Count << " * " << VectorList.RegNum << ">";
2498 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002499 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002500 OS << "'" << getToken() << "'";
2501 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002502 case k_VectorIndex:
2503 OS << "<vectorindex " << getVectorIndex() << ">";
2504 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002505 }
2506}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002507
2508/// @name Auto-generated Match Functions
2509/// {
2510
2511static unsigned MatchRegisterName(StringRef Name);
2512
2513/// }
2514
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002515bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2516 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002517 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002518 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002519 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002520
2521 return (RegNo == (unsigned)-1);
2522}
2523
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002524/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002525/// and if it is a register name the token is eaten and the register number is
2526/// returned. Otherwise return -1.
2527///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002528int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002529 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002530 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002531
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002532 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002533 unsigned RegNum = MatchRegisterName(lowerCase);
2534 if (!RegNum) {
2535 RegNum = StringSwitch<unsigned>(lowerCase)
2536 .Case("r13", ARM::SP)
2537 .Case("r14", ARM::LR)
2538 .Case("r15", ARM::PC)
2539 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002540 // Additional register name aliases for 'gas' compatibility.
2541 .Case("a1", ARM::R0)
2542 .Case("a2", ARM::R1)
2543 .Case("a3", ARM::R2)
2544 .Case("a4", ARM::R3)
2545 .Case("v1", ARM::R4)
2546 .Case("v2", ARM::R5)
2547 .Case("v3", ARM::R6)
2548 .Case("v4", ARM::R7)
2549 .Case("v5", ARM::R8)
2550 .Case("v6", ARM::R9)
2551 .Case("v7", ARM::R10)
2552 .Case("v8", ARM::R11)
2553 .Case("sb", ARM::R9)
2554 .Case("sl", ARM::R10)
2555 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002556 .Default(0);
2557 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002558 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002559 // Check for aliases registered via .req. Canonicalize to lower case.
2560 // That's more consistent since register names are case insensitive, and
2561 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2562 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002563 // If no match, return failure.
2564 if (Entry == RegisterReqs.end())
2565 return -1;
2566 Parser.Lex(); // Eat identifier token.
2567 return Entry->getValue();
2568 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002569
Chris Lattner44e5981c2010-10-30 04:09:10 +00002570 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002571
Chris Lattner44e5981c2010-10-30 04:09:10 +00002572 return RegNum;
2573}
Jim Grosbach99710a82010-11-01 16:44:21 +00002574
Jim Grosbachbb24c592011-07-13 18:49:30 +00002575// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2576// If a recoverable error occurs, return 1. If an irrecoverable error
2577// occurs, return -1. An irrecoverable error is one where tokens have been
2578// consumed in the process of trying to parse the shifter (i.e., when it is
2579// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002580int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002581 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2582 SMLoc S = Parser.getTok().getLoc();
2583 const AsmToken &Tok = Parser.getTok();
2584 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2585
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002586 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002587 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002588 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002589 .Case("lsl", ARM_AM::lsl)
2590 .Case("lsr", ARM_AM::lsr)
2591 .Case("asr", ARM_AM::asr)
2592 .Case("ror", ARM_AM::ror)
2593 .Case("rrx", ARM_AM::rrx)
2594 .Default(ARM_AM::no_shift);
2595
2596 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002597 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002598
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002599 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002600
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002601 // The source register for the shift has already been added to the
2602 // operand list, so we need to pop it off and combine it into the shifted
2603 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002604 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002605 if (!PrevOp->isReg())
2606 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2607 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002608
2609 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002610 int64_t Imm = 0;
2611 int ShiftReg = 0;
2612 if (ShiftTy == ARM_AM::rrx) {
2613 // RRX Doesn't have an explicit shift amount. The encoder expects
2614 // the shift register to be the same as the source register. Seems odd,
2615 // but OK.
2616 ShiftReg = SrcReg;
2617 } else {
2618 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002619 if (Parser.getTok().is(AsmToken::Hash) ||
2620 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002621 Parser.Lex(); // Eat hash.
2622 SMLoc ImmLoc = Parser.getTok().getLoc();
2623 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002624 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002625 Error(ImmLoc, "invalid immediate shift value");
2626 return -1;
2627 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002628 // The expression must be evaluatable as an immediate.
2629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002630 if (!CE) {
2631 Error(ImmLoc, "invalid immediate shift value");
2632 return -1;
2633 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002634 // Range check the immediate.
2635 // lsl, ror: 0 <= imm <= 31
2636 // lsr, asr: 0 <= imm <= 32
2637 Imm = CE->getValue();
2638 if (Imm < 0 ||
2639 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2640 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002641 Error(ImmLoc, "immediate shift value out of range");
2642 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002643 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002644 // shift by zero is a nop. Always send it through as lsl.
2645 // ('as' compatibility)
2646 if (Imm == 0)
2647 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002648 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002649 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002650 EndLoc = Parser.getTok().getEndLoc();
2651 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002652 if (ShiftReg == -1) {
2653 Error (L, "expected immediate or register in shift operand");
2654 return -1;
2655 }
2656 } else {
2657 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002658 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002659 return -1;
2660 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002661 }
2662
Owen Andersonb595ed02011-07-21 18:54:16 +00002663 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2664 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002665 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002666 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002667 else
2668 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002669 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002670
Jim Grosbachbb24c592011-07-13 18:49:30 +00002671 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002672}
2673
2674
Bill Wendling2063b842010-11-18 23:43:05 +00002675/// Try to parse a register name. The token must be an Identifier when called.
2676/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2677/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002678///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002679/// TODO this is likely to change to allow different register types and or to
2680/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002681bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002682tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002683 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002684 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002685 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002686 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002687
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002688 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2689 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002690
Chris Lattner44e5981c2010-10-30 04:09:10 +00002691 const AsmToken &ExclaimTok = Parser.getTok();
2692 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002693 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2694 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002695 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002696 return false;
2697 }
2698
2699 // Also check for an index operand. This is only legal for vector registers,
2700 // but that'll get caught OK in operand matching, so we don't need to
2701 // explicitly filter everything else out here.
2702 if (Parser.getTok().is(AsmToken::LBrac)) {
2703 SMLoc SIdx = Parser.getTok().getLoc();
2704 Parser.Lex(); // Eat left bracket token.
2705
2706 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002707 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002708 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002709 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002710 if (!MCE)
2711 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002712
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002713 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002714 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002715
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002716 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002717 Parser.Lex(); // Eat right bracket token.
2718
2719 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2720 SIdx, E,
2721 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002722 }
2723
Bill Wendling2063b842010-11-18 23:43:05 +00002724 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002725}
2726
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002727/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2728/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2729/// "c5", ...
2730static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002731 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2732 // but efficient.
2733 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002734 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002735 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002736 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002737 return -1;
2738 switch (Name[1]) {
2739 default: return -1;
2740 case '0': return 0;
2741 case '1': return 1;
2742 case '2': return 2;
2743 case '3': return 3;
2744 case '4': return 4;
2745 case '5': return 5;
2746 case '6': return 6;
2747 case '7': return 7;
2748 case '8': return 8;
2749 case '9': return 9;
2750 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002751 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002752 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002753 return -1;
2754 switch (Name[2]) {
2755 default: return -1;
2756 case '0': return 10;
2757 case '1': return 11;
2758 case '2': return 12;
2759 case '3': return 13;
2760 case '4': return 14;
2761 case '5': return 15;
2762 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002763 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002764}
2765
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002766/// parseITCondCode - Try to parse a condition code for an IT instruction.
2767ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2768parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2769 SMLoc S = Parser.getTok().getLoc();
2770 const AsmToken &Tok = Parser.getTok();
2771 if (!Tok.is(AsmToken::Identifier))
2772 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002773 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002774 .Case("eq", ARMCC::EQ)
2775 .Case("ne", ARMCC::NE)
2776 .Case("hs", ARMCC::HS)
2777 .Case("cs", ARMCC::HS)
2778 .Case("lo", ARMCC::LO)
2779 .Case("cc", ARMCC::LO)
2780 .Case("mi", ARMCC::MI)
2781 .Case("pl", ARMCC::PL)
2782 .Case("vs", ARMCC::VS)
2783 .Case("vc", ARMCC::VC)
2784 .Case("hi", ARMCC::HI)
2785 .Case("ls", ARMCC::LS)
2786 .Case("ge", ARMCC::GE)
2787 .Case("lt", ARMCC::LT)
2788 .Case("gt", ARMCC::GT)
2789 .Case("le", ARMCC::LE)
2790 .Case("al", ARMCC::AL)
2791 .Default(~0U);
2792 if (CC == ~0U)
2793 return MatchOperand_NoMatch;
2794 Parser.Lex(); // Eat the token.
2795
2796 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2797
2798 return MatchOperand_Success;
2799}
2800
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002801/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002802/// token must be an Identifier when called, and if it is a coprocessor
2803/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002804ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002805parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002806 SMLoc S = Parser.getTok().getLoc();
2807 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002808 if (Tok.isNot(AsmToken::Identifier))
2809 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002810
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002811 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002812 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002813 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002814
2815 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002816 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002817 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002818}
2819
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002820/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002821/// token must be an Identifier when called, and if it is a coprocessor
2822/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002823ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002824parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002825 SMLoc S = Parser.getTok().getLoc();
2826 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002827 if (Tok.isNot(AsmToken::Identifier))
2828 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002829
2830 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2831 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002832 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002833
2834 Parser.Lex(); // Eat identifier token.
2835 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002836 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002837}
2838
Jim Grosbach48399582011-10-12 17:34:41 +00002839/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2840/// coproc_option : '{' imm0_255 '}'
2841ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2842parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2843 SMLoc S = Parser.getTok().getLoc();
2844
2845 // If this isn't a '{', this isn't a coprocessor immediate operand.
2846 if (Parser.getTok().isNot(AsmToken::LCurly))
2847 return MatchOperand_NoMatch;
2848 Parser.Lex(); // Eat the '{'
2849
2850 const MCExpr *Expr;
2851 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002852 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002853 Error(Loc, "illegal expression");
2854 return MatchOperand_ParseFail;
2855 }
2856 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2857 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2858 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2859 return MatchOperand_ParseFail;
2860 }
2861 int Val = CE->getValue();
2862
2863 // Check for and consume the closing '}'
2864 if (Parser.getTok().isNot(AsmToken::RCurly))
2865 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002866 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002867 Parser.Lex(); // Eat the '}'
2868
2869 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2870 return MatchOperand_Success;
2871}
2872
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002873// For register list parsing, we need to map from raw GPR register numbering
2874// to the enumeration values. The enumeration values aren't sorted by
2875// register number due to our using "sp", "lr" and "pc" as canonical names.
2876static unsigned getNextRegister(unsigned Reg) {
2877 // If this is a GPR, we need to do it manually, otherwise we can rely
2878 // on the sort ordering of the enumeration since the other reg-classes
2879 // are sane.
2880 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2881 return Reg + 1;
2882 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002883 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002884 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2885 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2886 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2887 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2888 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2889 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2890 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2891 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2892 }
2893}
2894
Jim Grosbach85a23432011-11-11 21:27:40 +00002895// Return the low-subreg of a given Q register.
2896static unsigned getDRegFromQReg(unsigned QReg) {
2897 switch (QReg) {
2898 default: llvm_unreachable("expected a Q register!");
2899 case ARM::Q0: return ARM::D0;
2900 case ARM::Q1: return ARM::D2;
2901 case ARM::Q2: return ARM::D4;
2902 case ARM::Q3: return ARM::D6;
2903 case ARM::Q4: return ARM::D8;
2904 case ARM::Q5: return ARM::D10;
2905 case ARM::Q6: return ARM::D12;
2906 case ARM::Q7: return ARM::D14;
2907 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002908 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002909 case ARM::Q10: return ARM::D20;
2910 case ARM::Q11: return ARM::D22;
2911 case ARM::Q12: return ARM::D24;
2912 case ARM::Q13: return ARM::D26;
2913 case ARM::Q14: return ARM::D28;
2914 case ARM::Q15: return ARM::D30;
2915 }
2916}
2917
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002918/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002919bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002920parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002921 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002922 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00002923 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002924 Parser.Lex(); // Eat '{' token.
2925 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00002926
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002927 // Check the first register in the list to see what register class
2928 // this is a list of.
2929 int Reg = tryParseRegister();
2930 if (Reg == -1)
2931 return Error(RegLoc, "register expected");
2932
Jim Grosbach85a23432011-11-11 21:27:40 +00002933 // The reglist instructions have at most 16 registers, so reserve
2934 // space for that many.
2935 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2936
2937 // Allow Q regs and just interpret them as the two D sub-registers.
2938 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2939 Reg = getDRegFromQReg(Reg);
2940 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2941 ++Reg;
2942 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002943 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002944 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2945 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2946 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2947 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2948 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2949 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2950 else
2951 return Error(RegLoc, "invalid register in register list");
2952
Jim Grosbach85a23432011-11-11 21:27:40 +00002953 // Store the register.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002954 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbya2b99102009-10-09 21:12:28 +00002955
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002956 // This starts immediately after the first register token in the list,
2957 // so we can see either a comma or a minus (range separator) as a legal
2958 // next token.
2959 while (Parser.getTok().is(AsmToken::Comma) ||
2960 Parser.getTok().is(AsmToken::Minus)) {
2961 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00002962 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002963 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002964 int EndReg = tryParseRegister();
2965 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002966 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002967 // Allow Q regs and just interpret them as the two D sub-registers.
2968 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2969 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002970 // If the register is the same as the start reg, there's nothing
2971 // more to do.
2972 if (Reg == EndReg)
2973 continue;
2974 // The register must be in the same register class as the first.
2975 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002976 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002977 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002978 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002979 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00002980
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002981 // Add all the registers in the range to the register list.
2982 while (Reg != EndReg) {
2983 Reg = getNextRegister(Reg);
2984 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2985 }
2986 continue;
2987 }
2988 Parser.Lex(); // Eat the comma.
2989 RegLoc = Parser.getTok().getLoc();
2990 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00002991 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002992 Reg = tryParseRegister();
2993 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00002994 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002995 // Allow Q regs and just interpret them as the two D sub-registers.
2996 bool isQReg = false;
2997 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2998 Reg = getDRegFromQReg(Reg);
2999 isQReg = true;
3000 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003001 // The register must be in the same register class as the first.
3002 if (!RC->contains(Reg))
3003 return Error(RegLoc, "invalid register in register list");
3004 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003005 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003006 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3007 Warning(RegLoc, "register list not in ascending order");
3008 else
3009 return Error(RegLoc, "register list not in ascending order");
3010 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003011 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003012 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3013 ") in register list");
3014 continue;
3015 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003016 // VFP register lists must also be contiguous.
3017 // It's OK to use the enumeration values directly here rather, as the
3018 // VFP register classes have the enum sorted properly.
3019 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3020 Reg != OldReg + 1)
3021 return Error(RegLoc, "non-contiguous register range");
3022 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbach85a23432011-11-11 21:27:40 +00003023 if (isQReg)
3024 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge18980a2010-11-06 22:36:58 +00003025 }
3026
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003027 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003028 return Error(Parser.getTok().getLoc(), "'}' expected");
3029 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003030 Parser.Lex(); // Eat '}' token.
3031
Jim Grosbach18bf3632011-12-13 21:48:29 +00003032 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003033 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003034
3035 // The ARM system instruction variants for LDM/STM have a '^' token here.
3036 if (Parser.getTok().is(AsmToken::Caret)) {
3037 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3038 Parser.Lex(); // Eat '^' token.
3039 }
3040
Bill Wendling2063b842010-11-18 23:43:05 +00003041 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003042}
3043
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003044// Helper function to parse the lane index for vector lists.
3045ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003046parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003047 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003048 if (Parser.getTok().is(AsmToken::LBrac)) {
3049 Parser.Lex(); // Eat the '['.
3050 if (Parser.getTok().is(AsmToken::RBrac)) {
3051 // "Dn[]" is the 'all lanes' syntax.
3052 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003053 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003054 Parser.Lex(); // Eat the ']'.
3055 return MatchOperand_Success;
3056 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003057
3058 // There's an optional '#' token here. Normally there wouldn't be, but
3059 // inline assemble puts one in, and it's friendly to accept that.
3060 if (Parser.getTok().is(AsmToken::Hash))
3061 Parser.Lex(); // Eat the '#'
3062
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003063 const MCExpr *LaneIndex;
3064 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003065 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003066 Error(Loc, "illegal expression");
3067 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003068 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003069 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3070 if (!CE) {
3071 Error(Loc, "lane index must be empty or an integer");
3072 return MatchOperand_ParseFail;
3073 }
3074 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3075 Error(Parser.getTok().getLoc(), "']' expected");
3076 return MatchOperand_ParseFail;
3077 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003078 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003079 Parser.Lex(); // Eat the ']'.
3080 int64_t Val = CE->getValue();
3081
3082 // FIXME: Make this range check context sensitive for .8, .16, .32.
3083 if (Val < 0 || Val > 7) {
3084 Error(Parser.getTok().getLoc(), "lane index out of range");
3085 return MatchOperand_ParseFail;
3086 }
3087 Index = Val;
3088 LaneKind = IndexedLane;
3089 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003090 }
3091 LaneKind = NoLanes;
3092 return MatchOperand_Success;
3093}
3094
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003095// parse a vector register list
3096ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3097parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003098 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003099 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003100 SMLoc S = Parser.getTok().getLoc();
3101 // As an extension (to match gas), support a plain D register or Q register
3102 // (without encosing curly braces) as a single or double entry list,
3103 // respectively.
3104 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003105 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003106 int Reg = tryParseRegister();
3107 if (Reg == -1)
3108 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003109 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003110 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003111 if (Res != MatchOperand_Success)
3112 return Res;
3113 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003114 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003115 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003116 break;
3117 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003118 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3119 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003120 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003121 case IndexedLane:
3122 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003123 LaneIndex,
3124 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003125 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003126 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003127 return MatchOperand_Success;
3128 }
3129 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3130 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003131 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003132 if (Res != MatchOperand_Success)
3133 return Res;
3134 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003135 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003136 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003137 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003138 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003139 break;
3140 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003141 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3142 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003143 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3144 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003145 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003146 case IndexedLane:
3147 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003148 LaneIndex,
3149 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003150 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003151 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003152 return MatchOperand_Success;
3153 }
3154 Error(S, "vector register expected");
3155 return MatchOperand_ParseFail;
3156 }
3157
3158 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003159 return MatchOperand_NoMatch;
3160
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003161 Parser.Lex(); // Eat '{' token.
3162 SMLoc RegLoc = Parser.getTok().getLoc();
3163
3164 int Reg = tryParseRegister();
3165 if (Reg == -1) {
3166 Error(RegLoc, "register expected");
3167 return MatchOperand_ParseFail;
3168 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003169 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003170 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003171 unsigned FirstReg = Reg;
3172 // The list is of D registers, but we also allow Q regs and just interpret
3173 // them as the two D sub-registers.
3174 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3175 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003176 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3177 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003178 ++Reg;
3179 ++Count;
3180 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003181
3182 SMLoc E;
3183 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003184 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003185
Jim Grosbache891fe82011-11-15 23:19:15 +00003186 while (Parser.getTok().is(AsmToken::Comma) ||
3187 Parser.getTok().is(AsmToken::Minus)) {
3188 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003189 if (!Spacing)
3190 Spacing = 1; // Register range implies a single spaced list.
3191 else if (Spacing == 2) {
3192 Error(Parser.getTok().getLoc(),
3193 "sequential registers in double spaced list");
3194 return MatchOperand_ParseFail;
3195 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003196 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003197 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003198 int EndReg = tryParseRegister();
3199 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003200 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003201 return MatchOperand_ParseFail;
3202 }
3203 // Allow Q regs and just interpret them as the two D sub-registers.
3204 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3205 EndReg = getDRegFromQReg(EndReg) + 1;
3206 // If the register is the same as the start reg, there's nothing
3207 // more to do.
3208 if (Reg == EndReg)
3209 continue;
3210 // The register must be in the same register class as the first.
3211 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003212 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003213 return MatchOperand_ParseFail;
3214 }
3215 // Ranges must go from low to high.
3216 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003217 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003218 return MatchOperand_ParseFail;
3219 }
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;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003223 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3224 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) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003227 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003228 return MatchOperand_ParseFail;
3229 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003230
3231 // Add all the registers in the range to the register list.
3232 Count += EndReg - Reg;
3233 Reg = EndReg;
3234 continue;
3235 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003236 Parser.Lex(); // Eat the comma.
3237 RegLoc = Parser.getTok().getLoc();
3238 int OldReg = Reg;
3239 Reg = tryParseRegister();
3240 if (Reg == -1) {
3241 Error(RegLoc, "register expected");
3242 return MatchOperand_ParseFail;
3243 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003244 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003245 // It's OK to use the enumeration values directly here rather, as the
3246 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003247 //
3248 // The list is of D registers, but we also allow Q regs and just interpret
3249 // them as the two D sub-registers.
3250 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003251 if (!Spacing)
3252 Spacing = 1; // Register range implies a single spaced list.
3253 else if (Spacing == 2) {
3254 Error(RegLoc,
3255 "invalid register in double-spaced list (must be 'D' register')");
3256 return MatchOperand_ParseFail;
3257 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003258 Reg = getDRegFromQReg(Reg);
3259 if (Reg != OldReg + 1) {
3260 Error(RegLoc, "non-contiguous register range");
3261 return MatchOperand_ParseFail;
3262 }
3263 ++Reg;
3264 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003265 // Parse the lane specifier if present.
3266 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003267 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003268 SMLoc LaneLoc = Parser.getTok().getLoc();
3269 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3270 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003271 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003272 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003273 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003274 return MatchOperand_ParseFail;
3275 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003276 continue;
3277 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003278 // Normal D register.
3279 // Figure out the register spacing (single or double) of the list if
3280 // we don't know it already.
3281 if (!Spacing)
3282 Spacing = 1 + (Reg == OldReg + 2);
3283
3284 // Just check that it's contiguous and keep going.
3285 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003286 Error(RegLoc, "non-contiguous register range");
3287 return MatchOperand_ParseFail;
3288 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003289 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003290 // Parse the lane specifier if present.
3291 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003292 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003293 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003294 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003295 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003296 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003297 Error(EndLoc, "mismatched lane index in register list");
3298 return MatchOperand_ParseFail;
3299 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003300 }
3301
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003302 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003303 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003304 return MatchOperand_ParseFail;
3305 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003306 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003307 Parser.Lex(); // Eat '}' token.
3308
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003309 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003310 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003311 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003312 // composite register classes.
3313 if (Count == 2) {
3314 const MCRegisterClass *RC = (Spacing == 1) ?
3315 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3316 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3317 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3318 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003319
Jim Grosbach2f50e922011-12-15 21:44:33 +00003320 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3321 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003322 break;
3323 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003324 // Two-register operands have been converted to the
3325 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003326 if (Count == 2) {
3327 const MCRegisterClass *RC = (Spacing == 1) ?
3328 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3329 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003330 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3331 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003332 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003333 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003334 S, E));
3335 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003336 case IndexedLane:
3337 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003338 LaneIndex,
3339 (Spacing == 2),
3340 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003341 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003342 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003343 return MatchOperand_Success;
3344}
3345
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003346/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003347ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003348parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003349 SMLoc S = Parser.getTok().getLoc();
3350 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003351 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003352
Jiangning Liu288e1af2012-08-02 08:21:27 +00003353 if (Tok.is(AsmToken::Identifier)) {
3354 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003355
Jiangning Liu288e1af2012-08-02 08:21:27 +00003356 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3357 .Case("sy", ARM_MB::SY)
3358 .Case("st", ARM_MB::ST)
3359 .Case("sh", ARM_MB::ISH)
3360 .Case("ish", ARM_MB::ISH)
3361 .Case("shst", ARM_MB::ISHST)
3362 .Case("ishst", ARM_MB::ISHST)
3363 .Case("nsh", ARM_MB::NSH)
3364 .Case("un", ARM_MB::NSH)
3365 .Case("nshst", ARM_MB::NSHST)
3366 .Case("unst", ARM_MB::NSHST)
3367 .Case("osh", ARM_MB::OSH)
3368 .Case("oshst", ARM_MB::OSHST)
3369 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003370
Jiangning Liu288e1af2012-08-02 08:21:27 +00003371 if (Opt == ~0U)
3372 return MatchOperand_NoMatch;
3373
3374 Parser.Lex(); // Eat identifier token.
3375 } else if (Tok.is(AsmToken::Hash) ||
3376 Tok.is(AsmToken::Dollar) ||
3377 Tok.is(AsmToken::Integer)) {
3378 if (Parser.getTok().isNot(AsmToken::Integer))
3379 Parser.Lex(); // Eat the '#'.
3380 SMLoc Loc = Parser.getTok().getLoc();
3381
3382 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003383 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003384 Error(Loc, "illegal expression");
3385 return MatchOperand_ParseFail;
3386 }
3387
3388 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3389 if (!CE) {
3390 Error(Loc, "constant expression expected");
3391 return MatchOperand_ParseFail;
3392 }
3393
3394 int Val = CE->getValue();
3395 if (Val & ~0xf) {
3396 Error(Loc, "immediate value out of range");
3397 return MatchOperand_ParseFail;
3398 }
3399
3400 Opt = ARM_MB::RESERVED_0 + Val;
3401 } else
3402 return MatchOperand_ParseFail;
3403
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003404 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003405 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003406}
3407
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003408/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003409ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003410parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003411 SMLoc S = Parser.getTok().getLoc();
3412 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003413 if (!Tok.is(AsmToken::Identifier))
3414 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003415 StringRef IFlagsStr = Tok.getString();
3416
Owen Anderson10c5b122011-10-05 17:16:40 +00003417 // An iflags string of "none" is interpreted to mean that none of the AIF
3418 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003419 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003420 if (IFlagsStr != "none") {
3421 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3422 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3423 .Case("a", ARM_PROC::A)
3424 .Case("i", ARM_PROC::I)
3425 .Case("f", ARM_PROC::F)
3426 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003427
Owen Anderson10c5b122011-10-05 17:16:40 +00003428 // If some specific iflag is already set, it means that some letter is
3429 // present more than once, this is not acceptable.
3430 if (Flag == ~0U || (IFlags & Flag))
3431 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003432
Owen Anderson10c5b122011-10-05 17:16:40 +00003433 IFlags |= Flag;
3434 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003435 }
3436
3437 Parser.Lex(); // Eat identifier token.
3438 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3439 return MatchOperand_Success;
3440}
3441
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003442/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003443ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003444parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003445 SMLoc S = Parser.getTok().getLoc();
3446 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003447 if (!Tok.is(AsmToken::Identifier))
3448 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003449 StringRef Mask = Tok.getString();
3450
James Molloy21efa7d2011-09-28 14:21:38 +00003451 if (isMClass()) {
3452 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003453 std::string Name = Mask.lower();
3454 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003455 // Note: in the documentation:
3456 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3457 // for MSR APSR_nzcvq.
3458 // but we do make it an alias here. This is so to get the "mask encoding"
3459 // bits correct on MSR APSR writes.
3460 //
3461 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3462 // should really only be allowed when writing a special register. Note
3463 // they get dropped in the MRS instruction reading a special register as
3464 // the SYSm field is only 8 bits.
3465 //
3466 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3467 // includes the DSP extension but that is not checked.
3468 .Case("apsr", 0x800)
3469 .Case("apsr_nzcvq", 0x800)
3470 .Case("apsr_g", 0x400)
3471 .Case("apsr_nzcvqg", 0xc00)
3472 .Case("iapsr", 0x801)
3473 .Case("iapsr_nzcvq", 0x801)
3474 .Case("iapsr_g", 0x401)
3475 .Case("iapsr_nzcvqg", 0xc01)
3476 .Case("eapsr", 0x802)
3477 .Case("eapsr_nzcvq", 0x802)
3478 .Case("eapsr_g", 0x402)
3479 .Case("eapsr_nzcvqg", 0xc02)
3480 .Case("xpsr", 0x803)
3481 .Case("xpsr_nzcvq", 0x803)
3482 .Case("xpsr_g", 0x403)
3483 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003484 .Case("ipsr", 0x805)
3485 .Case("epsr", 0x806)
3486 .Case("iepsr", 0x807)
3487 .Case("msp", 0x808)
3488 .Case("psp", 0x809)
3489 .Case("primask", 0x810)
3490 .Case("basepri", 0x811)
3491 .Case("basepri_max", 0x812)
3492 .Case("faultmask", 0x813)
3493 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003494 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003495
James Molloy21efa7d2011-09-28 14:21:38 +00003496 if (FlagsVal == ~0U)
3497 return MatchOperand_NoMatch;
3498
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003499 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003500 // basepri, basepri_max and faultmask only valid for V7m.
3501 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003502
James Molloy21efa7d2011-09-28 14:21:38 +00003503 Parser.Lex(); // Eat identifier token.
3504 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3505 return MatchOperand_Success;
3506 }
3507
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003508 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3509 size_t Start = 0, Next = Mask.find('_');
3510 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003511 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003512 if (Next != StringRef::npos)
3513 Flags = Mask.slice(Next+1, Mask.size());
3514
3515 // FlagsVal contains the complete mask:
3516 // 3-0: Mask
3517 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3518 unsigned FlagsVal = 0;
3519
3520 if (SpecReg == "apsr") {
3521 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003522 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003523 .Case("g", 0x4) // same as CPSR_s
3524 .Case("nzcvqg", 0xc) // same as CPSR_fs
3525 .Default(~0U);
3526
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003527 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003528 if (!Flags.empty())
3529 return MatchOperand_NoMatch;
3530 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003531 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003532 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003533 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003534 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3535 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003536 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003537 for (int i = 0, e = Flags.size(); i != e; ++i) {
3538 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3539 .Case("c", 1)
3540 .Case("x", 2)
3541 .Case("s", 4)
3542 .Case("f", 8)
3543 .Default(~0U);
3544
3545 // If some specific flag is already set, it means that some letter is
3546 // present more than once, this is not acceptable.
3547 if (FlagsVal == ~0U || (FlagsVal & Flag))
3548 return MatchOperand_NoMatch;
3549 FlagsVal |= Flag;
3550 }
3551 } else // No match for special register.
3552 return MatchOperand_NoMatch;
3553
Owen Anderson03a173e2011-10-21 18:43:28 +00003554 // Special register without flags is NOT equivalent to "fc" flags.
3555 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3556 // two lines would enable gas compatibility at the expense of breaking
3557 // round-tripping.
3558 //
3559 // if (!FlagsVal)
3560 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003561
3562 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3563 if (SpecReg == "spsr")
3564 FlagsVal |= 16;
3565
3566 Parser.Lex(); // Eat identifier token.
3567 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3568 return MatchOperand_Success;
3569}
3570
Jim Grosbach27c1e252011-07-21 17:23:04 +00003571ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3572parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3573 int Low, int High) {
3574 const AsmToken &Tok = Parser.getTok();
3575 if (Tok.isNot(AsmToken::Identifier)) {
3576 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3577 return MatchOperand_ParseFail;
3578 }
3579 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003580 std::string LowerOp = Op.lower();
3581 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003582 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3583 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3584 return MatchOperand_ParseFail;
3585 }
3586 Parser.Lex(); // Eat shift type token.
3587
3588 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003589 if (Parser.getTok().isNot(AsmToken::Hash) &&
3590 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003591 Error(Parser.getTok().getLoc(), "'#' expected");
3592 return MatchOperand_ParseFail;
3593 }
3594 Parser.Lex(); // Eat hash token.
3595
3596 const MCExpr *ShiftAmount;
3597 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003598 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003599 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003600 Error(Loc, "illegal expression");
3601 return MatchOperand_ParseFail;
3602 }
3603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3604 if (!CE) {
3605 Error(Loc, "constant expression expected");
3606 return MatchOperand_ParseFail;
3607 }
3608 int Val = CE->getValue();
3609 if (Val < Low || Val > High) {
3610 Error(Loc, "immediate value out of range");
3611 return MatchOperand_ParseFail;
3612 }
3613
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003614 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003615
3616 return MatchOperand_Success;
3617}
3618
Jim Grosbach0a547702011-07-22 17:44:50 +00003619ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3620parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3621 const AsmToken &Tok = Parser.getTok();
3622 SMLoc S = Tok.getLoc();
3623 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003624 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003625 return MatchOperand_ParseFail;
3626 }
3627 int Val = StringSwitch<int>(Tok.getString())
3628 .Case("be", 1)
3629 .Case("le", 0)
3630 .Default(-1);
3631 Parser.Lex(); // Eat the token.
3632
3633 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003634 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003635 return MatchOperand_ParseFail;
3636 }
3637 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3638 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003639 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003640 return MatchOperand_Success;
3641}
3642
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003643/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3644/// instructions. Legal values are:
3645/// lsl #n 'n' in [0,31]
3646/// asr #n 'n' in [1,32]
3647/// n == 32 encoded as n == 0.
3648ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3649parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3650 const AsmToken &Tok = Parser.getTok();
3651 SMLoc S = Tok.getLoc();
3652 if (Tok.isNot(AsmToken::Identifier)) {
3653 Error(S, "shift operator 'asr' or 'lsl' expected");
3654 return MatchOperand_ParseFail;
3655 }
3656 StringRef ShiftName = Tok.getString();
3657 bool isASR;
3658 if (ShiftName == "lsl" || ShiftName == "LSL")
3659 isASR = false;
3660 else if (ShiftName == "asr" || ShiftName == "ASR")
3661 isASR = true;
3662 else {
3663 Error(S, "shift operator 'asr' or 'lsl' expected");
3664 return MatchOperand_ParseFail;
3665 }
3666 Parser.Lex(); // Eat the operator.
3667
3668 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003669 if (Parser.getTok().isNot(AsmToken::Hash) &&
3670 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003671 Error(Parser.getTok().getLoc(), "'#' expected");
3672 return MatchOperand_ParseFail;
3673 }
3674 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003675 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003676
3677 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003678 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003679 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003680 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003681 return MatchOperand_ParseFail;
3682 }
3683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3684 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003685 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003686 return MatchOperand_ParseFail;
3687 }
3688
3689 int64_t Val = CE->getValue();
3690 if (isASR) {
3691 // Shift amount must be in [1,32]
3692 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003693 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003694 return MatchOperand_ParseFail;
3695 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003696 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3697 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003698 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003699 return MatchOperand_ParseFail;
3700 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003701 if (Val == 32) Val = 0;
3702 } else {
3703 // Shift amount must be in [1,32]
3704 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003705 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003706 return MatchOperand_ParseFail;
3707 }
3708 }
3709
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003710 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003711
3712 return MatchOperand_Success;
3713}
3714
Jim Grosbach833b9d32011-07-27 20:15:40 +00003715/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3716/// of instructions. Legal values are:
3717/// ror #n 'n' in {0, 8, 16, 24}
3718ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3719parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3720 const AsmToken &Tok = Parser.getTok();
3721 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003722 if (Tok.isNot(AsmToken::Identifier))
3723 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003724 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003725 if (ShiftName != "ror" && ShiftName != "ROR")
3726 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003727 Parser.Lex(); // Eat the operator.
3728
3729 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003730 if (Parser.getTok().isNot(AsmToken::Hash) &&
3731 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003732 Error(Parser.getTok().getLoc(), "'#' expected");
3733 return MatchOperand_ParseFail;
3734 }
3735 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003736 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003737
3738 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003739 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003740 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003741 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003742 return MatchOperand_ParseFail;
3743 }
3744 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3745 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003746 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003747 return MatchOperand_ParseFail;
3748 }
3749
3750 int64_t Val = CE->getValue();
3751 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3752 // normally, zero is represented in asm by omitting the rotate operand
3753 // entirely.
3754 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003755 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003756 return MatchOperand_ParseFail;
3757 }
3758
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003759 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003760
3761 return MatchOperand_Success;
3762}
3763
Jim Grosbach864b6092011-07-28 21:34:26 +00003764ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3765parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3766 SMLoc S = Parser.getTok().getLoc();
3767 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003768 if (Parser.getTok().isNot(AsmToken::Hash) &&
3769 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003770 Error(Parser.getTok().getLoc(), "'#' expected");
3771 return MatchOperand_ParseFail;
3772 }
3773 Parser.Lex(); // Eat hash token.
3774
3775 const MCExpr *LSBExpr;
3776 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003777 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003778 Error(E, "malformed immediate expression");
3779 return MatchOperand_ParseFail;
3780 }
3781 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3782 if (!CE) {
3783 Error(E, "'lsb' operand must be an immediate");
3784 return MatchOperand_ParseFail;
3785 }
3786
3787 int64_t LSB = CE->getValue();
3788 // The LSB must be in the range [0,31]
3789 if (LSB < 0 || LSB > 31) {
3790 Error(E, "'lsb' operand must be in the range [0,31]");
3791 return MatchOperand_ParseFail;
3792 }
3793 E = Parser.getTok().getLoc();
3794
3795 // Expect another immediate operand.
3796 if (Parser.getTok().isNot(AsmToken::Comma)) {
3797 Error(Parser.getTok().getLoc(), "too few operands");
3798 return MatchOperand_ParseFail;
3799 }
3800 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003801 if (Parser.getTok().isNot(AsmToken::Hash) &&
3802 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003803 Error(Parser.getTok().getLoc(), "'#' expected");
3804 return MatchOperand_ParseFail;
3805 }
3806 Parser.Lex(); // Eat hash token.
3807
3808 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003809 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003810 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003811 Error(E, "malformed immediate expression");
3812 return MatchOperand_ParseFail;
3813 }
3814 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3815 if (!CE) {
3816 Error(E, "'width' operand must be an immediate");
3817 return MatchOperand_ParseFail;
3818 }
3819
3820 int64_t Width = CE->getValue();
3821 // The LSB must be in the range [1,32-lsb]
3822 if (Width < 1 || Width > 32 - LSB) {
3823 Error(E, "'width' operand must be in the range [1,32-lsb]");
3824 return MatchOperand_ParseFail;
3825 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003826
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003827 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003828
3829 return MatchOperand_Success;
3830}
3831
Jim Grosbachd3595712011-08-03 23:50:40 +00003832ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3833parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3834 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003835 // postidx_reg := '+' register {, shift}
3836 // | '-' register {, shift}
3837 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003838
3839 // This method must return MatchOperand_NoMatch without consuming any tokens
3840 // in the case where there is no match, as other alternatives take other
3841 // parse methods.
3842 AsmToken Tok = Parser.getTok();
3843 SMLoc S = Tok.getLoc();
3844 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003845 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003846 if (Tok.is(AsmToken::Plus)) {
3847 Parser.Lex(); // Eat the '+' token.
3848 haveEaten = true;
3849 } else if (Tok.is(AsmToken::Minus)) {
3850 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003851 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003852 haveEaten = true;
3853 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003854
3855 SMLoc E = Parser.getTok().getEndLoc();
3856 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00003857 if (Reg == -1) {
3858 if (!haveEaten)
3859 return MatchOperand_NoMatch;
3860 Error(Parser.getTok().getLoc(), "register expected");
3861 return MatchOperand_ParseFail;
3862 }
Jim Grosbachd3595712011-08-03 23:50:40 +00003863
Jim Grosbachc320c852011-08-05 21:28:30 +00003864 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3865 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003866 if (Parser.getTok().is(AsmToken::Comma)) {
3867 Parser.Lex(); // Eat the ','.
3868 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3869 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003870
3871 // FIXME: Only approximates end...may include intervening whitespace.
3872 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003873 }
Jim Grosbachc320c852011-08-05 21:28:30 +00003874
3875 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3876 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00003877
3878 return MatchOperand_Success;
3879}
3880
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003881ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3882parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3883 // Check for a post-index addressing register operand. Specifically:
3884 // am3offset := '+' register
3885 // | '-' register
3886 // | register
3887 // | # imm
3888 // | # + imm
3889 // | # - imm
3890
3891 // This method must return MatchOperand_NoMatch without consuming any tokens
3892 // in the case where there is no match, as other alternatives take other
3893 // parse methods.
3894 AsmToken Tok = Parser.getTok();
3895 SMLoc S = Tok.getLoc();
3896
3897 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003898 if (Parser.getTok().is(AsmToken::Hash) ||
3899 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003900 Parser.Lex(); // Eat the '#'.
3901 // Explicitly look for a '-', as we need to encode negative zero
3902 // differently.
3903 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3904 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003905 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003906 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003907 return MatchOperand_ParseFail;
3908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3909 if (!CE) {
3910 Error(S, "constant expression expected");
3911 return MatchOperand_ParseFail;
3912 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003913 // Negative zero is encoded as the flag value INT32_MIN.
3914 int32_t Val = CE->getValue();
3915 if (isNegative && Val == 0)
3916 Val = INT32_MIN;
3917
3918 Operands.push_back(
3919 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3920
3921 return MatchOperand_Success;
3922 }
3923
3924
3925 bool haveEaten = false;
3926 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003927 if (Tok.is(AsmToken::Plus)) {
3928 Parser.Lex(); // Eat the '+' token.
3929 haveEaten = true;
3930 } else if (Tok.is(AsmToken::Minus)) {
3931 Parser.Lex(); // Eat the '-' token.
3932 isAdd = false;
3933 haveEaten = true;
3934 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003935
3936 Tok = Parser.getTok();
3937 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003938 if (Reg == -1) {
3939 if (!haveEaten)
3940 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003941 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003942 return MatchOperand_ParseFail;
3943 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003944
3945 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003946 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003947
3948 return MatchOperand_Success;
3949}
3950
Jim Grosbach7db8d692011-09-08 22:07:06 +00003951/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3952/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3953/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003954void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003955cvtT2LdrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003956 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3957 // Rt, Rt2
3958 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3959 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3960 // Create a writeback register dummy placeholder.
3961 Inst.addOperand(MCOperand::CreateReg(0));
3962 // addr
3963 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3964 // pred
3965 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003966}
3967
3968/// cvtT2StrdPre - Convert parsed operands to MCInst.
3969/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3970/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003971void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003972cvtT2StrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003973 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3974 // Create a writeback register dummy placeholder.
3975 Inst.addOperand(MCOperand::CreateReg(0));
3976 // Rt, Rt2
3977 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3978 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3979 // addr
3980 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3981 // pred
3982 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003983}
3984
Jim Grosbachc086f682011-09-08 00:39:19 +00003985/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3986/// 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 +00003989cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +00003990 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3991 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3992
3993 // Create a writeback register dummy placeholder.
3994 Inst.addOperand(MCOperand::CreateImm(0));
3995
3996 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3997 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachc086f682011-09-08 00:39:19 +00003998}
3999
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004000/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4001/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4002/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004003void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004004cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004005 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4006 // Create a writeback register dummy placeholder.
4007 Inst.addOperand(MCOperand::CreateImm(0));
4008 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4009 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4010 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00004011}
4012
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004013/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004014/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4015/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004016void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004017cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004018 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4019 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4020
4021 // Create a writeback register dummy placeholder.
4022 Inst.addOperand(MCOperand::CreateImm(0));
4023
Jim Grosbachd3595712011-08-03 23:50:40 +00004024 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004025 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004026}
4027
Owen Anderson16d33f32011-08-26 20:43:14 +00004028/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4029/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4030/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004031void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004032cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +00004033 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4034 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4035
4036 // Create a writeback register dummy placeholder.
4037 Inst.addOperand(MCOperand::CreateImm(0));
4038
4039 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4040 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson16d33f32011-08-26 20:43:14 +00004041}
4042
4043
Jim Grosbachd564bf32011-08-11 19:22:40 +00004044/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4045/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4046/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004047void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004048cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +00004049 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4050 // Create a writeback register dummy placeholder.
4051 Inst.addOperand(MCOperand::CreateImm(0));
4052 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4053 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4054 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd564bf32011-08-11 19:22:40 +00004055}
4056
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004057/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004058/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4059/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004060void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004061cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004062 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4063 // Create a writeback register dummy placeholder.
4064 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd564bf32011-08-11 19:22:40 +00004065 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4066 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4067 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004068}
4069
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004070/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4071/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4072/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004073void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004074cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004075 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4076 // Create a writeback register dummy placeholder.
4077 Inst.addOperand(MCOperand::CreateImm(0));
4078 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4079 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4080 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004081}
4082
Jim Grosbachd3595712011-08-03 23:50:40 +00004083/// cvtLdExtTWriteBackImm - 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 +00004087cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004088 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4089 // Rt
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004090 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004091 // Create a writeback register dummy placeholder.
4092 Inst.addOperand(MCOperand::CreateImm(0));
4093 // addr
4094 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4095 // offset
4096 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4097 // pred
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004098 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004099}
4100
Jim Grosbachd3595712011-08-03 23:50:40 +00004101/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004102/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4103/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004104void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004105cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004106 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4107 // Rt
Owen Andersonb0e68992011-07-28 17:18:57 +00004108 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004109 // Create a writeback register dummy placeholder.
4110 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004111 // addr
4112 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4113 // offset
4114 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4115 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004116 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004117}
4118
Jim Grosbachd3595712011-08-03 23:50:40 +00004119/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004120/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4121/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004122void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004123cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004124 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004125 // Create a writeback register dummy placeholder.
4126 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004127 // Rt
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004128 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004129 // addr
4130 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4131 // offset
4132 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4133 // pred
4134 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004135}
4136
4137/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4138/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4139/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004140void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004141cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004142 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4143 // Create a writeback register dummy placeholder.
4144 Inst.addOperand(MCOperand::CreateImm(0));
4145 // Rt
4146 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4147 // addr
4148 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4149 // offset
4150 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4151 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004152 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004153}
4154
Jim Grosbach5b96b802011-08-10 20:29:19 +00004155/// cvtLdrdPre - Convert parsed operands to MCInst.
4156/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4157/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004158void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004159cvtLdrdPre(MCInst &Inst,
Jim Grosbach5b96b802011-08-10 20:29:19 +00004160 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4161 // Rt, Rt2
4162 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4163 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4164 // Create a writeback register dummy placeholder.
4165 Inst.addOperand(MCOperand::CreateImm(0));
4166 // addr
4167 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4168 // pred
4169 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach5b96b802011-08-10 20:29:19 +00004170}
4171
Jim Grosbacheb09f492011-08-11 20:28:23 +00004172/// cvtStrdPre - Convert parsed operands to MCInst.
4173/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4174/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004175void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004176cvtStrdPre(MCInst &Inst,
Jim Grosbacheb09f492011-08-11 20:28:23 +00004177 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4178 // Create a writeback register dummy placeholder.
4179 Inst.addOperand(MCOperand::CreateImm(0));
4180 // Rt, Rt2
4181 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4182 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4183 // addr
4184 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4185 // pred
4186 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheb09f492011-08-11 20:28:23 +00004187}
4188
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004189/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4190/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4191/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004192void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004193cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004194 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4195 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4196 // Create a writeback register dummy placeholder.
4197 Inst.addOperand(MCOperand::CreateImm(0));
4198 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4199 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004200}
4201
Chad Rosier5eec49f2012-08-30 23:00:00 +00004202/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach8e048492011-08-19 22:07:46 +00004203/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4204/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004205void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004206cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004207 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004208 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4209 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004210 // If we have a three-operand form, make sure to set Rn to be the operand
4211 // that isn't the same as Rd.
4212 unsigned RegOp = 4;
4213 if (Operands.size() == 6 &&
4214 ((ARMOperand*)Operands[4])->getReg() ==
4215 ((ARMOperand*)Operands[3])->getReg())
4216 RegOp = 5;
4217 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4218 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004219 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004220}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004221
Chad Rosier98cfa102012-08-31 00:03:31 +00004222void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004223cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004224 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4225 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004226 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004227 // Create a writeback register dummy placeholder.
4228 Inst.addOperand(MCOperand::CreateImm(0));
4229 // Vn
4230 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4231 // pred
4232 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004233}
4234
Chad Rosier98cfa102012-08-31 00:03:31 +00004235void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004236cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004237 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4238 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004239 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004240 // Create a writeback register dummy placeholder.
4241 Inst.addOperand(MCOperand::CreateImm(0));
4242 // Vn
4243 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4244 // Vm
4245 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4246 // pred
4247 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004248}
4249
Chad Rosier98cfa102012-08-31 00:03:31 +00004250void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004251cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004252 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4253 // Create a writeback register dummy placeholder.
4254 Inst.addOperand(MCOperand::CreateImm(0));
4255 // Vn
4256 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4257 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004258 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004259 // pred
4260 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004261}
4262
Chad Rosier98cfa102012-08-31 00:03:31 +00004263void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004264cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004265 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4266 // Create a writeback register dummy placeholder.
4267 Inst.addOperand(MCOperand::CreateImm(0));
4268 // Vn
4269 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4270 // Vm
4271 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4272 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004273 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004274 // pred
4275 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004276}
4277
Bill Wendlinge18980a2010-11-06 22:36:58 +00004278/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004279/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004280bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004281parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004282 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004283 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004284 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004285 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004286 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004287
Sean Callanan936b0d32010-01-19 21:44:56 +00004288 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004289 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004290 if (BaseRegNum == -1)
4291 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004292
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004293 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004294 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004295 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4296 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004297 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004298
Jim Grosbachd3595712011-08-03 23:50:40 +00004299 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004300 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004301 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004302
Jim Grosbachd3595712011-08-03 23:50:40 +00004303 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004304 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004305
Jim Grosbach40700e02011-09-19 18:42:21 +00004306 // If there's a pre-indexing writeback marker, '!', just add it as a token
4307 // operand. It's rather odd, but syntactically valid.
4308 if (Parser.getTok().is(AsmToken::Exclaim)) {
4309 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4310 Parser.Lex(); // Eat the '!'.
4311 }
4312
Jim Grosbachd3595712011-08-03 23:50:40 +00004313 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004314 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004315
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004316 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4317 "Lost colon or comma in memory operand?!");
4318 if (Tok.is(AsmToken::Comma)) {
4319 Parser.Lex(); // Eat the comma.
4320 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004321
Jim Grosbacha95ec992011-10-11 17:29:55 +00004322 // If we have a ':', it's an alignment specifier.
4323 if (Parser.getTok().is(AsmToken::Colon)) {
4324 Parser.Lex(); // Eat the ':'.
4325 E = Parser.getTok().getLoc();
4326
4327 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004328 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004329 return true;
4330
4331 // The expression has to be a constant. Memory references with relocations
4332 // don't come through here, as they use the <label> forms of the relevant
4333 // instructions.
4334 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4335 if (!CE)
4336 return Error (E, "constant expression expected");
4337
4338 unsigned Align = 0;
4339 switch (CE->getValue()) {
4340 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004341 return Error(E,
4342 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4343 case 16: Align = 2; break;
4344 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004345 case 64: Align = 8; break;
4346 case 128: Align = 16; break;
4347 case 256: Align = 32; break;
4348 }
4349
4350 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004351 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004352 return Error(Parser.getTok().getLoc(), "']' expected");
4353 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004354 Parser.Lex(); // Eat right bracket token.
4355
4356 // Don't worry about range checking the value here. That's handled by
4357 // the is*() predicates.
4358 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4359 ARM_AM::no_shift, 0, Align,
4360 false, S, E));
4361
4362 // If there's a pre-indexing writeback marker, '!', just add it as a token
4363 // operand.
4364 if (Parser.getTok().is(AsmToken::Exclaim)) {
4365 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4366 Parser.Lex(); // Eat the '!'.
4367 }
4368
4369 return false;
4370 }
4371
4372 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004373 // offset. Be friendly and also accept a plain integer (without a leading
4374 // hash) for gas compatibility.
4375 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004376 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004377 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004378 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach8279c182011-11-15 22:14:41 +00004379 Parser.Lex(); // Eat the '#'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004380 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004381
Owen Anderson967674d2011-08-29 19:36:44 +00004382 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004383 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004384 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004385 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004386
4387 // The expression has to be a constant. Memory references with relocations
4388 // don't come through here, as they use the <label> forms of the relevant
4389 // instructions.
4390 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4391 if (!CE)
4392 return Error (E, "constant expression expected");
4393
Owen Anderson967674d2011-08-29 19:36:44 +00004394 // If the constant was #-0, represent it as INT32_MIN.
4395 int32_t Val = CE->getValue();
4396 if (isNegative && Val == 0)
4397 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4398
Jim Grosbachd3595712011-08-03 23:50:40 +00004399 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004400 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004401 return Error(Parser.getTok().getLoc(), "']' expected");
4402 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004403 Parser.Lex(); // Eat right bracket token.
4404
4405 // Don't worry about range checking the value here. That's handled by
4406 // the is*() predicates.
4407 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004408 ARM_AM::no_shift, 0, 0,
4409 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004410
4411 // If there's a pre-indexing writeback marker, '!', just add it as a token
4412 // operand.
4413 if (Parser.getTok().is(AsmToken::Exclaim)) {
4414 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4415 Parser.Lex(); // Eat the '!'.
4416 }
4417
4418 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004419 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004420
4421 // The register offset is optionally preceded by a '+' or '-'
4422 bool isNegative = false;
4423 if (Parser.getTok().is(AsmToken::Minus)) {
4424 isNegative = true;
4425 Parser.Lex(); // Eat the '-'.
4426 } else if (Parser.getTok().is(AsmToken::Plus)) {
4427 // Nothing to do.
4428 Parser.Lex(); // Eat the '+'.
4429 }
4430
4431 E = Parser.getTok().getLoc();
4432 int OffsetRegNum = tryParseRegister();
4433 if (OffsetRegNum == -1)
4434 return Error(E, "register expected");
4435
4436 // If there's a shift operator, handle it.
4437 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004438 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004439 if (Parser.getTok().is(AsmToken::Comma)) {
4440 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004441 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004442 return true;
4443 }
4444
4445 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004446 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004447 return Error(Parser.getTok().getLoc(), "']' expected");
4448 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004449 Parser.Lex(); // Eat right bracket token.
4450
4451 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004452 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004453 S, E));
4454
Jim Grosbachc320c852011-08-05 21:28:30 +00004455 // If there's a pre-indexing writeback marker, '!', just add it as a token
4456 // operand.
4457 if (Parser.getTok().is(AsmToken::Exclaim)) {
4458 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4459 Parser.Lex(); // Eat the '!'.
4460 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004461
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004462 return false;
4463}
4464
Jim Grosbachd3595712011-08-03 23:50:40 +00004465/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004466/// ( lsl | lsr | asr | ror ) , # shift_amount
4467/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004468/// return true if it parses a shift otherwise it returns false.
4469bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4470 unsigned &Amount) {
4471 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004472 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004473 if (Tok.isNot(AsmToken::Identifier))
4474 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004475 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004476 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4477 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004478 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004479 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004480 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004481 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004482 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004483 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004484 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004485 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004486 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004487 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004488 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004489 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004490
Jim Grosbachd3595712011-08-03 23:50:40 +00004491 // rrx stands alone.
4492 Amount = 0;
4493 if (St != ARM_AM::rrx) {
4494 Loc = Parser.getTok().getLoc();
4495 // A '#' and a shift amount.
4496 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004497 if (HashTok.isNot(AsmToken::Hash) &&
4498 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004499 return Error(HashTok.getLoc(), "'#' expected");
4500 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004501
Jim Grosbachd3595712011-08-03 23:50:40 +00004502 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004503 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004504 return true;
4505 // Range check the immediate.
4506 // lsl, ror: 0 <= imm <= 31
4507 // lsr, asr: 0 <= imm <= 32
4508 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4509 if (!CE)
4510 return Error(Loc, "shift amount must be an immediate");
4511 int64_t Imm = CE->getValue();
4512 if (Imm < 0 ||
4513 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4514 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4515 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004516 // If <ShiftTy> #0, turn it into a no_shift.
4517 if (Imm == 0)
4518 St = ARM_AM::lsl;
4519 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4520 if (Imm == 32)
4521 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004522 Amount = Imm;
4523 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004524
4525 return false;
4526}
4527
Jim Grosbache7fbce72011-10-03 23:38:36 +00004528/// parseFPImm - A floating point immediate expression operand.
4529ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4530parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004531 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004532 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004533 // integer only.
4534 //
4535 // This routine still creates a generic Immediate operand, containing
4536 // a bitcast of the 64-bit floating point value. The various operands
4537 // that accept floats can check whether the value is valid for them
4538 // via the standard is*() predicates.
4539
Jim Grosbache7fbce72011-10-03 23:38:36 +00004540 SMLoc S = Parser.getTok().getLoc();
4541
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004542 if (Parser.getTok().isNot(AsmToken::Hash) &&
4543 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004544 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004545
4546 // Disambiguate the VMOV forms that can accept an FP immediate.
4547 // vmov.f32 <sreg>, #imm
4548 // vmov.f64 <dreg>, #imm
4549 // vmov.f32 <dreg>, #imm @ vector f32x2
4550 // vmov.f32 <qreg>, #imm @ vector f32x4
4551 //
4552 // There are also the NEON VMOV instructions which expect an
4553 // integer constant. Make sure we don't try to parse an FPImm
4554 // for these:
4555 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4556 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4557 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4558 TyOp->getToken() != ".f64"))
4559 return MatchOperand_NoMatch;
4560
Jim Grosbache7fbce72011-10-03 23:38:36 +00004561 Parser.Lex(); // Eat the '#'.
4562
4563 // Handle negation, as that still comes through as a separate token.
4564 bool isNegative = false;
4565 if (Parser.getTok().is(AsmToken::Minus)) {
4566 isNegative = true;
4567 Parser.Lex();
4568 }
4569 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004570 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004571 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004572 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004573 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4574 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004575 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004576 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004577 Operands.push_back(ARMOperand::CreateImm(
4578 MCConstantExpr::Create(IntVal, getContext()),
4579 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004580 return MatchOperand_Success;
4581 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004582 // Also handle plain integers. Instructions which allow floating point
4583 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004584 if (Tok.is(AsmToken::Integer)) {
4585 int64_t Val = Tok.getIntVal();
4586 Parser.Lex(); // Eat the token.
4587 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004588 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004589 return MatchOperand_ParseFail;
4590 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004591 double RealVal = ARM_AM::getFPImmFloat(Val);
4592 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4593 Operands.push_back(ARMOperand::CreateImm(
4594 MCConstantExpr::Create(Val, getContext()), S,
4595 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004596 return MatchOperand_Success;
4597 }
4598
Jim Grosbach235c8d22012-01-19 02:47:30 +00004599 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004600 return MatchOperand_ParseFail;
4601}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004602
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004603/// Parse a arm instruction operand. For now this parses the operand regardless
4604/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004605bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004606 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004607 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004608
4609 // Check if the current operand has a custom associated parser, if so, try to
4610 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004611 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4612 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004613 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004614 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4615 // there was a match, but an error occurred, in which case, just return that
4616 // the operand parsing failed.
4617 if (ResTy == MatchOperand_ParseFail)
4618 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004619
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004620 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004621 default:
4622 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004623 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004624 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004625 // If we've seen a branch mnemonic, the next operand must be a label. This
4626 // is true even if the label is a register name. So "br r1" means branch to
4627 // label "r1".
4628 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4629 if (!ExpectLabel) {
4630 if (!tryParseRegisterWithWriteBack(Operands))
4631 return false;
4632 int Res = tryParseShiftRegister(Operands);
4633 if (Res == 0) // success
4634 return false;
4635 else if (Res == -1) // irrecoverable error
4636 return true;
4637 // If this is VMRS, check for the apsr_nzcv operand.
4638 if (Mnemonic == "vmrs" &&
4639 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4640 S = Parser.getTok().getLoc();
4641 Parser.Lex();
4642 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4643 return false;
4644 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004645 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004646
4647 // Fall though for the Identifier case that is not a register or a
4648 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004649 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004650 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004651 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004652 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004653 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004654 // This was not a register so parse other operands that start with an
4655 // identifier (like labels) as expressions and create them as immediates.
4656 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004657 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004658 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004659 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004660 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004661 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4662 return false;
4663 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004664 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004665 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004666 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004667 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004668 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004669 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004670 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004671 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004672 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004673
4674 if (Parser.getTok().isNot(AsmToken::Colon)) {
4675 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4676 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004677 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004678 return true;
4679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4680 if (CE) {
4681 int32_t Val = CE->getValue();
4682 if (isNegative && Val == 0)
4683 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4684 }
4685 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4686 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004687
4688 // There can be a trailing '!' on operands that we want as a separate
4689 // '!' Token operand. Handle that here. For example, the compatibilty
4690 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4691 if (Parser.getTok().is(AsmToken::Exclaim)) {
4692 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4693 Parser.getTok().getLoc()));
4694 Parser.Lex(); // Eat exclaim token
4695 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004696 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004697 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004698 // w/ a ':' after the '#', it's just like a plain ':'.
4699 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004700 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004701 case AsmToken::Colon: {
4702 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004703 // FIXME: Check it's an expression prefix,
4704 // e.g. (FOO - :lower16:BAR) isn't legal.
4705 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004706 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004707 return true;
4708
Evan Cheng965b3c72011-01-13 07:58:56 +00004709 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004710 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004711 return true;
4712
Evan Cheng965b3c72011-01-13 07:58:56 +00004713 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004714 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004715 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004716 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004717 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004718 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004719 }
4720}
4721
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004722// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004723// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004724bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004725 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004726
4727 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004728 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004729 Parser.Lex(); // Eat ':'
4730
4731 if (getLexer().isNot(AsmToken::Identifier)) {
4732 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4733 return true;
4734 }
4735
4736 StringRef IDVal = Parser.getTok().getIdentifier();
4737 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004738 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004739 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004740 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004741 } else {
4742 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4743 return true;
4744 }
4745 Parser.Lex();
4746
4747 if (getLexer().isNot(AsmToken::Colon)) {
4748 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4749 return true;
4750 }
4751 Parser.Lex(); // Eat the last ':'
4752 return false;
4753}
4754
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004755/// \brief Given a mnemonic, split out possible predication code and carry
4756/// setting letters to form a canonical mnemonic and flags.
4757//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004758// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004759// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004760StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004761 unsigned &PredicationCode,
4762 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004763 unsigned &ProcessorIMod,
4764 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004765 PredicationCode = ARMCC::AL;
4766 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004767 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004768
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004769 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004770 //
4771 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004772 if ((Mnemonic == "movs" && isThumb()) ||
4773 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4774 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4775 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4776 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Jim Grosbach9b81a4f2013-04-15 22:42:50 +00004777 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004778 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4779 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004780 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4781 Mnemonic == "fmuls")
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004782 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004783
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004784 // First, split out any predication code. Ignore mnemonics we know aren't
4785 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004786 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004787 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004788 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004789 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004790 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4791 .Case("eq", ARMCC::EQ)
4792 .Case("ne", ARMCC::NE)
4793 .Case("hs", ARMCC::HS)
4794 .Case("cs", ARMCC::HS)
4795 .Case("lo", ARMCC::LO)
4796 .Case("cc", ARMCC::LO)
4797 .Case("mi", ARMCC::MI)
4798 .Case("pl", ARMCC::PL)
4799 .Case("vs", ARMCC::VS)
4800 .Case("vc", ARMCC::VC)
4801 .Case("hi", ARMCC::HI)
4802 .Case("ls", ARMCC::LS)
4803 .Case("ge", ARMCC::GE)
4804 .Case("lt", ARMCC::LT)
4805 .Case("gt", ARMCC::GT)
4806 .Case("le", ARMCC::LE)
4807 .Case("al", ARMCC::AL)
4808 .Default(~0U);
4809 if (CC != ~0U) {
4810 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4811 PredicationCode = CC;
4812 }
Bill Wendling193961b2010-10-29 23:50:21 +00004813 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004814
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004815 // Next, determine if we have a carry setting bit. We explicitly ignore all
4816 // the instructions we know end in 's'.
4817 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004818 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004819 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4820 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4821 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004822 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004823 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004824 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004825 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004826 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004827 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004828 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4829 CarrySetting = true;
4830 }
4831
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004832 // The "cps" instruction can have a interrupt mode operand which is glued into
4833 // the mnemonic. Check if this is the case, split it and parse the imod op
4834 if (Mnemonic.startswith("cps")) {
4835 // Split out any imod code.
4836 unsigned IMod =
4837 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4838 .Case("ie", ARM_PROC::IE)
4839 .Case("id", ARM_PROC::ID)
4840 .Default(~0U);
4841 if (IMod != ~0U) {
4842 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4843 ProcessorIMod = IMod;
4844 }
4845 }
4846
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004847 // The "it" instruction has the condition mask on the end of the mnemonic.
4848 if (Mnemonic.startswith("it")) {
4849 ITMask = Mnemonic.slice(2, Mnemonic.size());
4850 Mnemonic = Mnemonic.slice(0, 2);
4851 }
4852
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004853 return Mnemonic;
4854}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004855
4856/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4857/// inclusion of carry set or predication code operands.
4858//
4859// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004860void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004861getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004862 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004863 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4864 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004865 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004866 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004867 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004868 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004869 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004870 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004871 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004872 Mnemonic == "mla" || Mnemonic == "smlal" ||
4873 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004874 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004875 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004876 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004877
Daniel Dunbar09264122011-01-11 19:06:29 +00004878 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4879 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4880 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4881 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbach803898f2011-09-06 20:27:04 +00004882 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4883 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach25977222011-08-19 23:24:36 +00004884 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach93981412011-10-11 21:55:36 +00004885 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4886 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4887 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbachb9d4e372011-08-26 22:21:51 +00004888 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4889 !isThumb()) ||
Jim Grosbachb908b7a2011-09-10 00:15:36 +00004890 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004891 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004892 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004893 CanAcceptPredicationCode = true;
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004894
Jim Grosbach6c45b752011-09-16 16:39:25 +00004895 if (isThumb()) {
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004896 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbachb98ab912011-06-30 22:10:46 +00004897 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004898 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004899 }
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004900}
4901
Jim Grosbach7283da92011-08-16 21:12:37 +00004902bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4903 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004904 // FIXME: This is all horribly hacky. We really need a better way to deal
4905 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004906
4907 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4908 // another does not. Specifically, the MOVW instruction does not. So we
4909 // special case it here and remove the defaulted (non-setting) cc_out
4910 // operand if that's the instruction we're trying to match.
4911 //
4912 // We do this as post-processing of the explicit operands rather than just
4913 // conditionally adding the cc_out in the first place because we need
4914 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004915 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004916 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4917 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4918 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4919 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004920
4921 // Register-register 'add' for thumb does not have a cc_out operand
4922 // when there are only two register operands.
4923 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4924 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4925 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4926 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4927 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004928 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004929 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4930 // have to check the immediate range here since Thumb2 has a variant
4931 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004932 if (((isThumb() && Mnemonic == "add") ||
4933 (isThumbTwo() && Mnemonic == "sub")) &&
4934 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004935 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4936 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4937 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004938 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004939 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004940 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004941 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004942 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4943 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004944 // selecting via the generic "add" mnemonic, so to know that we
4945 // should remove the cc_out operand, we have to explicitly check that
4946 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004947 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4948 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004949 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4950 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4951 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4952 // Nest conditions rather than one big 'if' statement for readability.
4953 //
4954 // If either register is a high reg, it's either one of the SP
4955 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004956 // check against T3. If the second register is the PC, this is an
4957 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004958 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4959 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004960 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004961 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4962 return false;
4963 // If both registers are low, we're in an IT block, and the immediate is
4964 // in range, we should use encoding T1 instead, which has a cc_out.
4965 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004966 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004967 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4968 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4969 return false;
4970
4971 // Otherwise, we use encoding T4, which does not have a cc_out
4972 // operand.
4973 return true;
4974 }
4975
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004976 // The thumb2 multiply instruction doesn't have a CCOut register, so
4977 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4978 // use the 16-bit encoding or not.
4979 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4980 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4981 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4982 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4983 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4984 // If the registers aren't low regs, the destination reg isn't the
4985 // same as one of the source regs, or the cc_out operand is zero
4986 // outside of an IT block, we have to use the 32-bit encoding, so
4987 // remove the cc_out operand.
4988 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4989 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004990 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004991 !inITBlock() ||
4992 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4993 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4994 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4995 static_cast<ARMOperand*>(Operands[4])->getReg())))
4996 return true;
4997
Jim Grosbachefa7e952011-11-15 19:55:16 +00004998 // Also check the 'mul' syntax variant that doesn't specify an explicit
4999 // destination register.
5000 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5001 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5002 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5003 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5004 // If the registers aren't low regs or the cc_out operand is zero
5005 // outside of an IT block, we have to use the 32-bit encoding, so
5006 // remove the cc_out operand.
5007 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5008 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5009 !inITBlock()))
5010 return true;
5011
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005012
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005013
Jim Grosbach4b701af2011-08-24 21:42:27 +00005014 // Register-register 'add/sub' for thumb does not have a cc_out operand
5015 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5016 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5017 // right, this will result in better diagnostics (which operand is off)
5018 // anyway.
5019 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5020 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005021 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5022 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005023 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5024 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5025 (Operands.size() == 6 &&
5026 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005027 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005028
Jim Grosbach7283da92011-08-16 21:12:37 +00005029 return false;
5030}
5031
Jim Grosbach12952fe2011-11-11 23:08:10 +00005032static bool isDataTypeToken(StringRef Tok) {
5033 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5034 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5035 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5036 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5037 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5038 Tok == ".f" || Tok == ".d";
5039}
5040
5041// FIXME: This bit should probably be handled via an explicit match class
5042// in the .td files that matches the suffix instead of having it be
5043// a literal string token the way it is now.
5044static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5045 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5046}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005047static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5048 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005049/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005050bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5051 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005052 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005053 // Apply mnemonic aliases before doing anything else, as the destination
5054 // mnemnonic may include suffices and we want to handle them normally.
5055 // The generic tblgen'erated code does this later, at the start of
5056 // MatchInstructionImpl(), but that's too late for aliases that include
5057 // any sort of suffix.
5058 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005059 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5060 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005061
Jim Grosbachab5830e2011-12-14 02:16:11 +00005062 // First check for the ARM-specific .req directive.
5063 if (Parser.getTok().is(AsmToken::Identifier) &&
5064 Parser.getTok().getIdentifier() == ".req") {
5065 parseDirectiveReq(Name, NameLoc);
5066 // We always return 'error' for this, as we're done with this
5067 // statement and don't need to match the 'instruction."
5068 return true;
5069 }
5070
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005071 // Create the leading tokens for the mnemonic, split by '.' characters.
5072 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005073 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005074
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005075 // Split out the predication code and carry setting flag from the mnemonic.
5076 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005077 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005078 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005079 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005080 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005081 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005082
Jim Grosbach1c171b12011-08-25 17:23:55 +00005083 // In Thumb1, only the branch (B) instruction can be predicated.
5084 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005085 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005086 return Error(NameLoc, "conditional execution not supported in Thumb1");
5087 }
5088
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005089 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5090
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005091 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5092 // is the mask as it will be for the IT encoding if the conditional
5093 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5094 // where the conditional bit0 is zero, the instruction post-processing
5095 // will adjust the mask accordingly.
5096 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005097 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5098 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005099 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005100 return Error(Loc, "too many conditions on IT instruction");
5101 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005102 unsigned Mask = 8;
5103 for (unsigned i = ITMask.size(); i != 0; --i) {
5104 char pos = ITMask[i - 1];
5105 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005106 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005107 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005108 }
5109 Mask >>= 1;
5110 if (ITMask[i - 1] == 't')
5111 Mask |= 8;
5112 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005113 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005114 }
5115
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005116 // FIXME: This is all a pretty gross hack. We should automatically handle
5117 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005118
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005119 // Next, add the CCOut and ConditionCode operands, if needed.
5120 //
5121 // For mnemonics which can ever incorporate a carry setting bit or predication
5122 // code, our matching model involves us always generating CCOut and
5123 // ConditionCode operands to match the mnemonic "as written" and then we let
5124 // the matcher deal with finding the right instruction or generating an
5125 // appropriate error.
5126 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005127 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005128
Jim Grosbach03a8a162011-07-14 22:04:21 +00005129 // If we had a carry-set on an instruction that can't do that, issue an
5130 // error.
5131 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005132 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005133 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005134 "' can not set flags, but 's' suffix specified");
5135 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005136 // If we had a predication code on an instruction that can't do that, issue an
5137 // error.
5138 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005139 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005140 return Error(NameLoc, "instruction '" + Mnemonic +
5141 "' is not predicable, but condition code specified");
5142 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005143
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005144 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005145 if (CanAcceptCarrySet) {
5146 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005147 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005148 Loc));
5149 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005150
5151 // Add the predication code operand, if necessary.
5152 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005153 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5154 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005155 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005156 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005157 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005158
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005159 // Add the processor imod operand, if necessary.
5160 if (ProcessorIMod) {
5161 Operands.push_back(ARMOperand::CreateImm(
5162 MCConstantExpr::Create(ProcessorIMod, getContext()),
5163 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005164 }
5165
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005166 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005167 while (Next != StringRef::npos) {
5168 Start = Next;
5169 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005170 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005171
Jim Grosbach12952fe2011-11-11 23:08:10 +00005172 // Some NEON instructions have an optional datatype suffix that is
5173 // completely ignored. Check for that.
5174 if (isDataTypeToken(ExtraToken) &&
5175 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5176 continue;
5177
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005178 if (ExtraToken != ".n") {
5179 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5180 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5181 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005182 }
5183
5184 // Read the remaining operands.
5185 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005186 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005187 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005188 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005189 return true;
5190 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005191
5192 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005193 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005194
5195 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005196 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005197 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005198 return true;
5199 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005200 }
5201 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005202
Chris Lattnera2a9d162010-09-11 16:18:25 +00005203 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005204 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005205 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005206 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005207 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005208
Chris Lattner91689c12010-09-08 05:10:46 +00005209 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005210
Jim Grosbach7283da92011-08-16 21:12:37 +00005211 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5212 // do and don't have a cc_out optional-def operand. With some spot-checks
5213 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005214 // parse and adjust accordingly before actually matching. We shouldn't ever
5215 // try to remove a cc_out operand that was explicitly set on the the
5216 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5217 // table driven matcher doesn't fit well with the ARM instruction set.
5218 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005219 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5220 Operands.erase(Operands.begin() + 1);
5221 delete Op;
5222 }
5223
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005224 // ARM mode 'blx' need special handling, as the register operand version
5225 // is predicable, but the label operand version is not. So, we can't rely
5226 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005227 // a k_CondCode operand in the list. If we're trying to match the label
5228 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005229 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5230 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5231 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5232 Operands.erase(Operands.begin() + 1);
5233 delete Op;
5234 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005235
Weiming Zhao8f56f882012-11-16 21:55:34 +00005236 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5237 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5238 // a single GPRPair reg operand is used in the .td file to replace the two
5239 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5240 // expressed as a GPRPair, so we have to manually merge them.
5241 // FIXME: We would really like to be able to tablegen'erate this.
5242 if (!isThumb() && Operands.size() > 4 &&
5243 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5244 bool isLoad = (Mnemonic == "ldrexd");
5245 unsigned Idx = isLoad ? 2 : 3;
5246 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5247 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5248
5249 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5250 // Adjust only if Op1 and Op2 are GPRs.
5251 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5252 MRC.contains(Op2->getReg())) {
5253 unsigned Reg1 = Op1->getReg();
5254 unsigned Reg2 = Op2->getReg();
5255 unsigned Rt = MRI->getEncodingValue(Reg1);
5256 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5257
5258 // Rt2 must be Rt + 1 and Rt must be even.
5259 if (Rt + 1 != Rt2 || (Rt & 1)) {
5260 Error(Op2->getStartLoc(), isLoad ?
5261 "destination operands must be sequential" :
5262 "source operands must be sequential");
5263 return true;
5264 }
5265 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5266 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5267 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5268 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5269 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5270 delete Op1;
5271 delete Op2;
5272 }
5273 }
5274
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005275 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005276}
5277
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005278// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005279
5280// return 'true' if register list contains non-low GPR registers,
5281// 'false' otherwise. If Reg is in the register list or is HiReg, set
5282// 'containsReg' to true.
5283static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5284 unsigned HiReg, bool &containsReg) {
5285 containsReg = false;
5286 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5287 unsigned OpReg = Inst.getOperand(i).getReg();
5288 if (OpReg == Reg)
5289 containsReg = true;
5290 // Anything other than a low register isn't legal here.
5291 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5292 return true;
5293 }
5294 return false;
5295}
5296
Jim Grosbacha31f2232011-09-07 18:05:34 +00005297// Check if the specified regisgter is in the register list of the inst,
5298// starting at the indicated operand number.
5299static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5300 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5301 unsigned OpReg = Inst.getOperand(i).getReg();
5302 if (OpReg == Reg)
5303 return true;
5304 }
5305 return false;
5306}
5307
Jim Grosbached16ec42011-08-29 22:24:09 +00005308// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5309// the ARMInsts array) instead. Getting that here requires awkward
5310// API changes, though. Better way?
5311namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005312extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005313}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005314static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005315 return ARMInsts[Opcode];
5316}
5317
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005318// FIXME: We would really like to be able to tablegen'erate this.
5319bool ARMAsmParser::
5320validateInstruction(MCInst &Inst,
5321 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005322 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005323 SMLoc Loc = Operands[0]->getStartLoc();
5324 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005325 // NOTE: BKPT instruction has the interesting property of being
5326 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005327 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005328 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5329 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005330 unsigned bit = 1;
5331 if (ITState.FirstCond)
5332 ITState.FirstCond = false;
5333 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005334 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005335 // The instruction must be predicable.
5336 if (!MCID.isPredicable())
5337 return Error(Loc, "instructions in IT block must be predicable");
5338 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5339 unsigned ITCond = bit ? ITState.Cond :
5340 ARMCC::getOppositeCondition(ITState.Cond);
5341 if (Cond != ITCond) {
5342 // Find the condition code Operand to get its SMLoc information.
5343 SMLoc CondLoc;
5344 for (unsigned i = 1; i < Operands.size(); ++i)
5345 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5346 CondLoc = Operands[i]->getStartLoc();
5347 return Error(CondLoc, "incorrect condition in IT block; got '" +
5348 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5349 "', but expected '" +
5350 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5351 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005352 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005353 } else if (isThumbTwo() && MCID.isPredicable() &&
5354 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005355 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5356 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005357 return Error(Loc, "predicated instructions must be in IT block");
5358
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005359 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005360 case ARM::LDRD:
5361 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005362 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005363 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005364 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5365 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005366 if (Rt2 != Rt + 1)
5367 return Error(Operands[3]->getStartLoc(),
5368 "destination operands must be sequential");
5369 return false;
5370 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005371 case ARM::STRD: {
5372 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005373 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5374 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005375 if (Rt2 != Rt + 1)
5376 return Error(Operands[3]->getStartLoc(),
5377 "source operands must be sequential");
5378 return false;
5379 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005380 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005381 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005382 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005383 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5384 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005385 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005386 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005387 "source operands must be sequential");
5388 return false;
5389 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005390 case ARM::SBFX:
5391 case ARM::UBFX: {
5392 // width must be in range [1, 32-lsb]
5393 unsigned lsb = Inst.getOperand(2).getImm();
5394 unsigned widthm1 = Inst.getOperand(3).getImm();
5395 if (widthm1 >= 32 - lsb)
5396 return Error(Operands[5]->getStartLoc(),
5397 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005398 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005399 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005400 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005401 // If we're parsing Thumb2, the .w variant is available and handles
5402 // most cases that are normally illegal for a Thumb1 LDM
5403 // instruction. We'll make the transformation in processInstruction()
5404 // if necessary.
5405 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005406 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005407 // in the register list.
5408 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005409 bool hasWritebackToken =
5410 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5411 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005412 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005413 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005414 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5415 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005416 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005417 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005418 return Error(Operands[2]->getStartLoc(),
5419 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005420 // If we should not have writeback, there must not be a '!'. This is
5421 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005422 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005423 return Error(Operands[3]->getStartLoc(),
5424 "writeback operator '!' not allowed when base register "
5425 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005426
5427 break;
5428 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005429 case ARM::t2LDMIA_UPD: {
5430 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5431 return Error(Operands[4]->getStartLoc(),
5432 "writeback operator '!' not allowed when base register "
5433 "in register list");
5434 break;
5435 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005436 case ARM::tMUL: {
5437 // The second source operand must be the same register as the destination
5438 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005439 //
5440 // In this case, we must directly check the parsed operands because the
5441 // cvtThumbMultiply() function is written in such a way that it guarantees
5442 // this first statement is always true for the new Inst. Essentially, the
5443 // destination is unconditionally copied into the second source operand
5444 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005445 if (Operands.size() == 6 &&
5446 (((ARMOperand*)Operands[3])->getReg() !=
5447 ((ARMOperand*)Operands[5])->getReg()) &&
5448 (((ARMOperand*)Operands[3])->getReg() !=
5449 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005450 return Error(Operands[3]->getStartLoc(),
5451 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005452 }
5453 break;
5454 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005455 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5456 // so only issue a diagnostic for thumb1. The instructions will be
5457 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005458 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005459 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005460 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5461 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005462 return Error(Operands[2]->getStartLoc(),
5463 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005464 break;
5465 }
5466 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005467 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005468 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5469 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005470 return Error(Operands[2]->getStartLoc(),
5471 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005472 break;
5473 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005474 case ARM::tSTMIA_UPD: {
5475 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005476 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005477 return Error(Operands[4]->getStartLoc(),
5478 "registers must be in range r0-r7");
5479 break;
5480 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005481 case ARM::tADDrSP: {
5482 // If the non-SP source operand and the destination operand are not the
5483 // same, we need thumb2 (for the wide encoding), or we have an error.
5484 if (!isThumbTwo() &&
5485 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5486 return Error(Operands[4]->getStartLoc(),
5487 "source register must be the same as destination");
5488 }
5489 break;
5490 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005491 }
5492
5493 return false;
5494}
5495
Jim Grosbach1a747242012-01-23 23:45:44 +00005496static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005497 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005498 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005499 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005500 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5501 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5502 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5503 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5504 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5505 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5506 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5507 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5508 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005509
5510 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005511 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5512 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5513 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5514 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5515 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005516
Jim Grosbach1e946a42012-01-24 00:43:12 +00005517 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5518 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5519 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5520 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5521 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005522
Jim Grosbach1e946a42012-01-24 00:43:12 +00005523 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5524 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5525 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5526 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5527 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005528
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005529 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005530 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5531 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5532 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5533 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5534 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5535 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5536 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5537 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5538 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5539 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5540 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5541 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5542 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5543 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5544 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005545
Jim Grosbach1a747242012-01-23 23:45:44 +00005546 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005547 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5548 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5549 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5550 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5551 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5552 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5553 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5554 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5555 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5556 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5557 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5558 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5559 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5560 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5561 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5562 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5563 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5564 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005565
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005566 // VST4LN
5567 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5568 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5569 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5570 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5571 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5572 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5573 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5574 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5575 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5576 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5577 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5578 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5579 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5580 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5581 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5582
Jim Grosbachda70eac2012-01-24 00:58:13 +00005583 // VST4
5584 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5585 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5586 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5587 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5588 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5589 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5590 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5591 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5592 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5593 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5594 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5595 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5596 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5597 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5598 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5599 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5600 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5601 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005602 }
5603}
5604
Jim Grosbach1a747242012-01-23 23:45:44 +00005605static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005606 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005607 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005608 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005609 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5610 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5611 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5612 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5613 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5614 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5615 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5616 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5617 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005618
5619 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005620 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5621 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5622 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5623 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5624 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5625 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5626 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5627 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5628 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5629 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5630 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5631 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5632 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5633 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5634 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005635
Jim Grosbachb78403c2012-01-24 23:47:04 +00005636 // VLD3DUP
5637 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5638 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5639 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5640 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5641 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5642 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5643 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5644 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5645 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5646 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5647 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5648 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5649 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5650 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5651 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5652 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5653 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5654 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5655
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005656 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005657 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5658 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5659 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5660 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5661 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5662 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5663 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5664 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5665 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5666 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5667 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5668 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5669 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5670 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5671 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005672
5673 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005674 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5675 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5676 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5677 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5678 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5679 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5680 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5681 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5682 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5683 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5684 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5685 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5686 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5687 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5688 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5689 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5690 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5691 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005692
Jim Grosbach14952a02012-01-24 18:37:25 +00005693 // VLD4LN
5694 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5695 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5696 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5697 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5698 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5699 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5700 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5701 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5702 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5703 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5704 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5705 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5706 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5707 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5708 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5709
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005710 // VLD4DUP
5711 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5712 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5713 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5714 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5715 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5716 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5717 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5718 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5719 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5720 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5721 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5722 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5723 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5724 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5725 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5726 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5727 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5728 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5729
Jim Grosbached561fc2012-01-24 00:43:17 +00005730 // VLD4
5731 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5732 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5733 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5734 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5735 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5736 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5737 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5738 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5739 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5740 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5741 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5742 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5743 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5744 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5745 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5746 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5747 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5748 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005749 }
5750}
5751
Jim Grosbachafad0532011-11-10 23:42:14 +00005752bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005753processInstruction(MCInst &Inst,
5754 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5755 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005756 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5757 case ARM::ADDri: {
5758 if (Inst.getOperand(1).getReg() != ARM::PC ||
5759 Inst.getOperand(5).getReg() != 0)
5760 return false;
5761 MCInst TmpInst;
5762 TmpInst.setOpcode(ARM::ADR);
5763 TmpInst.addOperand(Inst.getOperand(0));
5764 TmpInst.addOperand(Inst.getOperand(2));
5765 TmpInst.addOperand(Inst.getOperand(3));
5766 TmpInst.addOperand(Inst.getOperand(4));
5767 Inst = TmpInst;
5768 return true;
5769 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005770 // Aliases for alternate PC+imm syntax of LDR instructions.
5771 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005772 // Select the narrow version if the immediate will fit.
5773 if (Inst.getOperand(1).getImm() > 0 &&
5774 Inst.getOperand(1).getImm() <= 0xff)
5775 Inst.setOpcode(ARM::tLDRpci);
5776 else
5777 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005778 return true;
5779 case ARM::t2LDRBpcrel:
5780 Inst.setOpcode(ARM::t2LDRBpci);
5781 return true;
5782 case ARM::t2LDRHpcrel:
5783 Inst.setOpcode(ARM::t2LDRHpci);
5784 return true;
5785 case ARM::t2LDRSBpcrel:
5786 Inst.setOpcode(ARM::t2LDRSBpci);
5787 return true;
5788 case ARM::t2LDRSHpcrel:
5789 Inst.setOpcode(ARM::t2LDRSHpci);
5790 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005791 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005792 case ARM::VST1LNdWB_register_Asm_8:
5793 case ARM::VST1LNdWB_register_Asm_16:
5794 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005795 MCInst TmpInst;
5796 // Shuffle the operands around so the lane index operand is in the
5797 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005798 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005799 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005800 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(Inst.getOperand(1)); // lane
5806 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5807 TmpInst.addOperand(Inst.getOperand(6));
5808 Inst = TmpInst;
5809 return true;
5810 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005811
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005812 case ARM::VST2LNdWB_register_Asm_8:
5813 case ARM::VST2LNdWB_register_Asm_16:
5814 case ARM::VST2LNdWB_register_Asm_32:
5815 case ARM::VST2LNqWB_register_Asm_16:
5816 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005817 MCInst TmpInst;
5818 // Shuffle the operands around so the lane index operand is in the
5819 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005820 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005821 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005822 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5823 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5824 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5825 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5826 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005827 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5828 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005829 TmpInst.addOperand(Inst.getOperand(1)); // lane
5830 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5831 TmpInst.addOperand(Inst.getOperand(6));
5832 Inst = TmpInst;
5833 return true;
5834 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005835
5836 case ARM::VST3LNdWB_register_Asm_8:
5837 case ARM::VST3LNdWB_register_Asm_16:
5838 case ARM::VST3LNdWB_register_Asm_32:
5839 case ARM::VST3LNqWB_register_Asm_16:
5840 case ARM::VST3LNqWB_register_Asm_32: {
5841 MCInst TmpInst;
5842 // Shuffle the operands around so the lane index operand is in the
5843 // right place.
5844 unsigned Spacing;
5845 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5846 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5847 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5848 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5849 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5850 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5852 Spacing));
5853 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5854 Spacing * 2));
5855 TmpInst.addOperand(Inst.getOperand(1)); // lane
5856 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5857 TmpInst.addOperand(Inst.getOperand(6));
5858 Inst = TmpInst;
5859 return true;
5860 }
5861
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005862 case ARM::VST4LNdWB_register_Asm_8:
5863 case ARM::VST4LNdWB_register_Asm_16:
5864 case ARM::VST4LNdWB_register_Asm_32:
5865 case ARM::VST4LNqWB_register_Asm_16:
5866 case ARM::VST4LNqWB_register_Asm_32: {
5867 MCInst TmpInst;
5868 // Shuffle the operands around so the lane index operand is in the
5869 // right place.
5870 unsigned Spacing;
5871 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5872 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5873 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5874 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5875 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5876 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5877 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5878 Spacing));
5879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5880 Spacing * 2));
5881 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5882 Spacing * 3));
5883 TmpInst.addOperand(Inst.getOperand(1)); // lane
5884 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5885 TmpInst.addOperand(Inst.getOperand(6));
5886 Inst = TmpInst;
5887 return true;
5888 }
5889
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005890 case ARM::VST1LNdWB_fixed_Asm_8:
5891 case ARM::VST1LNdWB_fixed_Asm_16:
5892 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005893 MCInst TmpInst;
5894 // Shuffle the operands around so the lane index operand is in the
5895 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005896 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005897 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005898 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(Inst.getOperand(1)); // lane
5904 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5905 TmpInst.addOperand(Inst.getOperand(5));
5906 Inst = TmpInst;
5907 return true;
5908 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005909
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005910 case ARM::VST2LNdWB_fixed_Asm_8:
5911 case ARM::VST2LNdWB_fixed_Asm_16:
5912 case ARM::VST2LNdWB_fixed_Asm_32:
5913 case ARM::VST2LNqWB_fixed_Asm_16:
5914 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005915 MCInst TmpInst;
5916 // Shuffle the operands around so the lane index operand is in the
5917 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005918 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005919 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005920 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5921 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5922 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5923 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5924 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005925 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5926 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005927 TmpInst.addOperand(Inst.getOperand(1)); // lane
5928 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5929 TmpInst.addOperand(Inst.getOperand(5));
5930 Inst = TmpInst;
5931 return true;
5932 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005933
5934 case ARM::VST3LNdWB_fixed_Asm_8:
5935 case ARM::VST3LNdWB_fixed_Asm_16:
5936 case ARM::VST3LNdWB_fixed_Asm_32:
5937 case ARM::VST3LNqWB_fixed_Asm_16:
5938 case ARM::VST3LNqWB_fixed_Asm_32: {
5939 MCInst TmpInst;
5940 // Shuffle the operands around so the lane index operand is in the
5941 // right place.
5942 unsigned Spacing;
5943 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5944 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5945 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5946 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5947 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5948 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5949 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5950 Spacing));
5951 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5952 Spacing * 2));
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 }
5959
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005960 case ARM::VST4LNdWB_fixed_Asm_8:
5961 case ARM::VST4LNdWB_fixed_Asm_16:
5962 case ARM::VST4LNdWB_fixed_Asm_32:
5963 case ARM::VST4LNqWB_fixed_Asm_16:
5964 case ARM::VST4LNqWB_fixed_Asm_32: {
5965 MCInst TmpInst;
5966 // Shuffle the operands around so the lane index operand is in the
5967 // right place.
5968 unsigned Spacing;
5969 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5970 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5971 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5972 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5973 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5974 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5975 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5976 Spacing));
5977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5978 Spacing * 2));
5979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5980 Spacing * 3));
5981 TmpInst.addOperand(Inst.getOperand(1)); // lane
5982 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5983 TmpInst.addOperand(Inst.getOperand(5));
5984 Inst = TmpInst;
5985 return true;
5986 }
5987
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005988 case ARM::VST1LNdAsm_8:
5989 case ARM::VST1LNdAsm_16:
5990 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005991 MCInst TmpInst;
5992 // Shuffle the operands around so the lane index operand is in the
5993 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005994 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005995 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005996 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5997 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5998 TmpInst.addOperand(Inst.getOperand(0)); // Vd
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 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006005
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006006 case ARM::VST2LNdAsm_8:
6007 case ARM::VST2LNdAsm_16:
6008 case ARM::VST2LNdAsm_32:
6009 case ARM::VST2LNqAsm_16:
6010 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006011 MCInst TmpInst;
6012 // Shuffle the operands around so the lane index operand is in the
6013 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006014 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006015 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006016 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6017 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6018 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006019 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6020 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006021 TmpInst.addOperand(Inst.getOperand(1)); // lane
6022 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6023 TmpInst.addOperand(Inst.getOperand(5));
6024 Inst = TmpInst;
6025 return true;
6026 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006027
6028 case ARM::VST3LNdAsm_8:
6029 case ARM::VST3LNdAsm_16:
6030 case ARM::VST3LNdAsm_32:
6031 case ARM::VST3LNqAsm_16:
6032 case ARM::VST3LNqAsm_32: {
6033 MCInst TmpInst;
6034 // Shuffle the operands around so the lane index operand is in the
6035 // right place.
6036 unsigned Spacing;
6037 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6038 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6039 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6040 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6041 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6042 Spacing));
6043 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6044 Spacing * 2));
6045 TmpInst.addOperand(Inst.getOperand(1)); // lane
6046 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6047 TmpInst.addOperand(Inst.getOperand(5));
6048 Inst = TmpInst;
6049 return true;
6050 }
6051
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006052 case ARM::VST4LNdAsm_8:
6053 case ARM::VST4LNdAsm_16:
6054 case ARM::VST4LNdAsm_32:
6055 case ARM::VST4LNqAsm_16:
6056 case ARM::VST4LNqAsm_32: {
6057 MCInst TmpInst;
6058 // Shuffle the operands around so the lane index operand is in the
6059 // right place.
6060 unsigned Spacing;
6061 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6062 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6063 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6064 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6065 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6066 Spacing));
6067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6068 Spacing * 2));
6069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6070 Spacing * 3));
6071 TmpInst.addOperand(Inst.getOperand(1)); // lane
6072 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6073 TmpInst.addOperand(Inst.getOperand(5));
6074 Inst = TmpInst;
6075 return true;
6076 }
6077
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006078 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006079 case ARM::VLD1LNdWB_register_Asm_8:
6080 case ARM::VLD1LNdWB_register_Asm_16:
6081 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006082 MCInst TmpInst;
6083 // Shuffle the operands around so the lane index operand is in the
6084 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006085 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006086 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006087 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6088 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6089 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6090 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6091 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6092 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6093 TmpInst.addOperand(Inst.getOperand(1)); // lane
6094 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6095 TmpInst.addOperand(Inst.getOperand(6));
6096 Inst = TmpInst;
6097 return true;
6098 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006099
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006100 case ARM::VLD2LNdWB_register_Asm_8:
6101 case ARM::VLD2LNdWB_register_Asm_16:
6102 case ARM::VLD2LNdWB_register_Asm_32:
6103 case ARM::VLD2LNqWB_register_Asm_16:
6104 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006105 MCInst TmpInst;
6106 // Shuffle the operands around so the lane index operand is in the
6107 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006108 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006109 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006110 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006111 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6112 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006113 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6114 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6115 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6116 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6117 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006118 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6119 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006120 TmpInst.addOperand(Inst.getOperand(1)); // lane
6121 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6122 TmpInst.addOperand(Inst.getOperand(6));
6123 Inst = TmpInst;
6124 return true;
6125 }
6126
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006127 case ARM::VLD3LNdWB_register_Asm_8:
6128 case ARM::VLD3LNdWB_register_Asm_16:
6129 case ARM::VLD3LNdWB_register_Asm_32:
6130 case ARM::VLD3LNqWB_register_Asm_16:
6131 case ARM::VLD3LNqWB_register_Asm_32: {
6132 MCInst TmpInst;
6133 // Shuffle the operands around so the lane index operand is in the
6134 // right place.
6135 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006136 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006137 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6138 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6139 Spacing));
6140 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006141 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006142 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6143 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6144 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6145 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6146 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6147 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6148 Spacing));
6149 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006150 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006151 TmpInst.addOperand(Inst.getOperand(1)); // lane
6152 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6153 TmpInst.addOperand(Inst.getOperand(6));
6154 Inst = TmpInst;
6155 return true;
6156 }
6157
Jim Grosbach14952a02012-01-24 18:37:25 +00006158 case ARM::VLD4LNdWB_register_Asm_8:
6159 case ARM::VLD4LNdWB_register_Asm_16:
6160 case ARM::VLD4LNdWB_register_Asm_32:
6161 case ARM::VLD4LNqWB_register_Asm_16:
6162 case ARM::VLD4LNqWB_register_Asm_32: {
6163 MCInst TmpInst;
6164 // Shuffle the operands around so the lane index operand is in the
6165 // right place.
6166 unsigned Spacing;
6167 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6168 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6169 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6170 Spacing));
6171 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6172 Spacing * 2));
6173 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6174 Spacing * 3));
6175 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6176 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6177 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6178 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6179 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6180 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6181 Spacing));
6182 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6183 Spacing * 2));
6184 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6185 Spacing * 3));
6186 TmpInst.addOperand(Inst.getOperand(1)); // lane
6187 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6188 TmpInst.addOperand(Inst.getOperand(6));
6189 Inst = TmpInst;
6190 return true;
6191 }
6192
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006193 case ARM::VLD1LNdWB_fixed_Asm_8:
6194 case ARM::VLD1LNdWB_fixed_Asm_16:
6195 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006196 MCInst TmpInst;
6197 // Shuffle the operands around so the lane index operand is in the
6198 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006199 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006200 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006201 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6202 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6203 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6204 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6205 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6206 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6207 TmpInst.addOperand(Inst.getOperand(1)); // lane
6208 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6209 TmpInst.addOperand(Inst.getOperand(5));
6210 Inst = TmpInst;
6211 return true;
6212 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006213
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006214 case ARM::VLD2LNdWB_fixed_Asm_8:
6215 case ARM::VLD2LNdWB_fixed_Asm_16:
6216 case ARM::VLD2LNdWB_fixed_Asm_32:
6217 case ARM::VLD2LNqWB_fixed_Asm_16:
6218 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006219 MCInst TmpInst;
6220 // Shuffle the operands around so the lane index operand is in the
6221 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006222 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006223 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006224 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006225 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6226 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006227 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6228 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6229 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6230 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6231 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006232 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6233 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006234 TmpInst.addOperand(Inst.getOperand(1)); // lane
6235 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6236 TmpInst.addOperand(Inst.getOperand(5));
6237 Inst = TmpInst;
6238 return true;
6239 }
6240
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006241 case ARM::VLD3LNdWB_fixed_Asm_8:
6242 case ARM::VLD3LNdWB_fixed_Asm_16:
6243 case ARM::VLD3LNdWB_fixed_Asm_32:
6244 case ARM::VLD3LNqWB_fixed_Asm_16:
6245 case ARM::VLD3LNqWB_fixed_Asm_32: {
6246 MCInst TmpInst;
6247 // Shuffle the operands around so the lane index operand is in the
6248 // right place.
6249 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006250 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006251 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6252 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 Spacing));
6254 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006255 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006256 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6257 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6258 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6259 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6260 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6261 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6262 Spacing));
6263 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006264 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006265 TmpInst.addOperand(Inst.getOperand(1)); // lane
6266 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6267 TmpInst.addOperand(Inst.getOperand(5));
6268 Inst = TmpInst;
6269 return true;
6270 }
6271
Jim Grosbach14952a02012-01-24 18:37:25 +00006272 case ARM::VLD4LNdWB_fixed_Asm_8:
6273 case ARM::VLD4LNdWB_fixed_Asm_16:
6274 case ARM::VLD4LNdWB_fixed_Asm_32:
6275 case ARM::VLD4LNqWB_fixed_Asm_16:
6276 case ARM::VLD4LNqWB_fixed_Asm_32: {
6277 MCInst TmpInst;
6278 // Shuffle the operands around so the lane index operand is in the
6279 // right place.
6280 unsigned Spacing;
6281 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6282 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6283 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6284 Spacing));
6285 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6286 Spacing * 2));
6287 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6288 Spacing * 3));
6289 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6290 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6291 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6292 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6293 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6295 Spacing));
6296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6297 Spacing * 2));
6298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6299 Spacing * 3));
6300 TmpInst.addOperand(Inst.getOperand(1)); // lane
6301 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6302 TmpInst.addOperand(Inst.getOperand(5));
6303 Inst = TmpInst;
6304 return true;
6305 }
6306
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006307 case ARM::VLD1LNdAsm_8:
6308 case ARM::VLD1LNdAsm_16:
6309 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006310 MCInst TmpInst;
6311 // Shuffle the operands around so the lane index operand is in the
6312 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006313 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006314 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006315 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6316 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6317 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6318 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6319 TmpInst.addOperand(Inst.getOperand(1)); // lane
6320 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6321 TmpInst.addOperand(Inst.getOperand(5));
6322 Inst = TmpInst;
6323 return true;
6324 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006325
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006326 case ARM::VLD2LNdAsm_8:
6327 case ARM::VLD2LNdAsm_16:
6328 case ARM::VLD2LNdAsm_32:
6329 case ARM::VLD2LNqAsm_16:
6330 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006331 MCInst TmpInst;
6332 // Shuffle the operands around so the lane index operand is in the
6333 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006334 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006335 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006336 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006337 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6338 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006339 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6340 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6341 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006342 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6343 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006344 TmpInst.addOperand(Inst.getOperand(1)); // lane
6345 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6346 TmpInst.addOperand(Inst.getOperand(5));
6347 Inst = TmpInst;
6348 return true;
6349 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006350
6351 case ARM::VLD3LNdAsm_8:
6352 case ARM::VLD3LNdAsm_16:
6353 case ARM::VLD3LNdAsm_32:
6354 case ARM::VLD3LNqAsm_16:
6355 case ARM::VLD3LNqAsm_32: {
6356 MCInst TmpInst;
6357 // Shuffle the operands around so the lane index operand is in the
6358 // right place.
6359 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006360 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006361 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6363 Spacing));
6364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006365 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006366 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6367 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6368 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6369 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6370 Spacing));
6371 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006372 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006373 TmpInst.addOperand(Inst.getOperand(1)); // lane
6374 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6375 TmpInst.addOperand(Inst.getOperand(5));
6376 Inst = TmpInst;
6377 return true;
6378 }
6379
Jim Grosbach14952a02012-01-24 18:37:25 +00006380 case ARM::VLD4LNdAsm_8:
6381 case ARM::VLD4LNdAsm_16:
6382 case ARM::VLD4LNdAsm_32:
6383 case ARM::VLD4LNqAsm_16:
6384 case ARM::VLD4LNqAsm_32: {
6385 MCInst TmpInst;
6386 // Shuffle the operands around so the lane index operand is in the
6387 // right place.
6388 unsigned Spacing;
6389 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6390 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6391 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6392 Spacing));
6393 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6394 Spacing * 2));
6395 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6396 Spacing * 3));
6397 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6398 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6399 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6401 Spacing));
6402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6403 Spacing * 2));
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6405 Spacing * 3));
6406 TmpInst.addOperand(Inst.getOperand(1)); // lane
6407 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6408 TmpInst.addOperand(Inst.getOperand(5));
6409 Inst = TmpInst;
6410 return true;
6411 }
6412
Jim Grosbachb78403c2012-01-24 23:47:04 +00006413 // VLD3DUP single 3-element structure to all lanes instructions.
6414 case ARM::VLD3DUPdAsm_8:
6415 case ARM::VLD3DUPdAsm_16:
6416 case ARM::VLD3DUPdAsm_32:
6417 case ARM::VLD3DUPqAsm_8:
6418 case ARM::VLD3DUPqAsm_16:
6419 case ARM::VLD3DUPqAsm_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(2)); // alignment
6430 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6431 TmpInst.addOperand(Inst.getOperand(4));
6432 Inst = TmpInst;
6433 return true;
6434 }
6435
6436 case ARM::VLD3DUPdWB_fixed_Asm_8:
6437 case ARM::VLD3DUPdWB_fixed_Asm_16:
6438 case ARM::VLD3DUPdWB_fixed_Asm_32:
6439 case ARM::VLD3DUPqWB_fixed_Asm_8:
6440 case ARM::VLD3DUPqWB_fixed_Asm_16:
6441 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6442 MCInst TmpInst;
6443 unsigned Spacing;
6444 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6445 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6446 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6447 Spacing));
6448 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6449 Spacing * 2));
6450 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6451 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6452 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6453 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6454 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6455 TmpInst.addOperand(Inst.getOperand(4));
6456 Inst = TmpInst;
6457 return true;
6458 }
6459
6460 case ARM::VLD3DUPdWB_register_Asm_8:
6461 case ARM::VLD3DUPdWB_register_Asm_16:
6462 case ARM::VLD3DUPdWB_register_Asm_32:
6463 case ARM::VLD3DUPqWB_register_Asm_8:
6464 case ARM::VLD3DUPqWB_register_Asm_16:
6465 case ARM::VLD3DUPqWB_register_Asm_32: {
6466 MCInst TmpInst;
6467 unsigned Spacing;
6468 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6469 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6470 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6471 Spacing));
6472 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6473 Spacing * 2));
6474 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6475 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6476 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6477 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6478 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6479 TmpInst.addOperand(Inst.getOperand(5));
6480 Inst = TmpInst;
6481 return true;
6482 }
6483
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006484 // VLD3 multiple 3-element structure instructions.
6485 case ARM::VLD3dAsm_8:
6486 case ARM::VLD3dAsm_16:
6487 case ARM::VLD3dAsm_32:
6488 case ARM::VLD3qAsm_8:
6489 case ARM::VLD3qAsm_16:
6490 case ARM::VLD3qAsm_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(2)); // alignment
6501 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6502 TmpInst.addOperand(Inst.getOperand(4));
6503 Inst = TmpInst;
6504 return true;
6505 }
6506
6507 case ARM::VLD3dWB_fixed_Asm_8:
6508 case ARM::VLD3dWB_fixed_Asm_16:
6509 case ARM::VLD3dWB_fixed_Asm_32:
6510 case ARM::VLD3qWB_fixed_Asm_8:
6511 case ARM::VLD3qWB_fixed_Asm_16:
6512 case ARM::VLD3qWB_fixed_Asm_32: {
6513 MCInst TmpInst;
6514 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006515 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006516 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6517 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6518 Spacing));
6519 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6520 Spacing * 2));
6521 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6522 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6523 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6524 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6525 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6526 TmpInst.addOperand(Inst.getOperand(4));
6527 Inst = TmpInst;
6528 return true;
6529 }
6530
6531 case ARM::VLD3dWB_register_Asm_8:
6532 case ARM::VLD3dWB_register_Asm_16:
6533 case ARM::VLD3dWB_register_Asm_32:
6534 case ARM::VLD3qWB_register_Asm_8:
6535 case ARM::VLD3qWB_register_Asm_16:
6536 case ARM::VLD3qWB_register_Asm_32: {
6537 MCInst TmpInst;
6538 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006539 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006540 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6541 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6542 Spacing));
6543 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6544 Spacing * 2));
6545 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6546 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6547 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6548 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6549 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6550 TmpInst.addOperand(Inst.getOperand(5));
6551 Inst = TmpInst;
6552 return true;
6553 }
6554
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006555 // VLD4DUP single 3-element structure to all lanes instructions.
6556 case ARM::VLD4DUPdAsm_8:
6557 case ARM::VLD4DUPdAsm_16:
6558 case ARM::VLD4DUPdAsm_32:
6559 case ARM::VLD4DUPqAsm_8:
6560 case ARM::VLD4DUPqAsm_16:
6561 case ARM::VLD4DUPqAsm_32: {
6562 MCInst TmpInst;
6563 unsigned Spacing;
6564 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6565 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6566 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6567 Spacing));
6568 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6569 Spacing * 2));
6570 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6571 Spacing * 3));
6572 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6573 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6574 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6575 TmpInst.addOperand(Inst.getOperand(4));
6576 Inst = TmpInst;
6577 return true;
6578 }
6579
6580 case ARM::VLD4DUPdWB_fixed_Asm_8:
6581 case ARM::VLD4DUPdWB_fixed_Asm_16:
6582 case ARM::VLD4DUPdWB_fixed_Asm_32:
6583 case ARM::VLD4DUPqWB_fixed_Asm_8:
6584 case ARM::VLD4DUPqWB_fixed_Asm_16:
6585 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6586 MCInst TmpInst;
6587 unsigned Spacing;
6588 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6589 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6590 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6591 Spacing));
6592 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6593 Spacing * 2));
6594 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6595 Spacing * 3));
6596 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6597 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6598 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6599 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6600 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6601 TmpInst.addOperand(Inst.getOperand(4));
6602 Inst = TmpInst;
6603 return true;
6604 }
6605
6606 case ARM::VLD4DUPdWB_register_Asm_8:
6607 case ARM::VLD4DUPdWB_register_Asm_16:
6608 case ARM::VLD4DUPdWB_register_Asm_32:
6609 case ARM::VLD4DUPqWB_register_Asm_8:
6610 case ARM::VLD4DUPqWB_register_Asm_16:
6611 case ARM::VLD4DUPqWB_register_Asm_32: {
6612 MCInst TmpInst;
6613 unsigned Spacing;
6614 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6615 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6616 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6617 Spacing));
6618 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6619 Spacing * 2));
6620 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6621 Spacing * 3));
6622 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6623 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6624 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6625 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6626 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6627 TmpInst.addOperand(Inst.getOperand(5));
6628 Inst = TmpInst;
6629 return true;
6630 }
6631
6632 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006633 case ARM::VLD4dAsm_8:
6634 case ARM::VLD4dAsm_16:
6635 case ARM::VLD4dAsm_32:
6636 case ARM::VLD4qAsm_8:
6637 case ARM::VLD4qAsm_16:
6638 case ARM::VLD4qAsm_32: {
6639 MCInst TmpInst;
6640 unsigned Spacing;
6641 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6642 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6643 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6644 Spacing));
6645 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6646 Spacing * 2));
6647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6648 Spacing * 3));
6649 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6650 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6651 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6652 TmpInst.addOperand(Inst.getOperand(4));
6653 Inst = TmpInst;
6654 return true;
6655 }
6656
6657 case ARM::VLD4dWB_fixed_Asm_8:
6658 case ARM::VLD4dWB_fixed_Asm_16:
6659 case ARM::VLD4dWB_fixed_Asm_32:
6660 case ARM::VLD4qWB_fixed_Asm_8:
6661 case ARM::VLD4qWB_fixed_Asm_16:
6662 case ARM::VLD4qWB_fixed_Asm_32: {
6663 MCInst TmpInst;
6664 unsigned Spacing;
6665 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6666 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6667 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6668 Spacing));
6669 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6670 Spacing * 2));
6671 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6672 Spacing * 3));
6673 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6674 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6675 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6676 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6677 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6678 TmpInst.addOperand(Inst.getOperand(4));
6679 Inst = TmpInst;
6680 return true;
6681 }
6682
6683 case ARM::VLD4dWB_register_Asm_8:
6684 case ARM::VLD4dWB_register_Asm_16:
6685 case ARM::VLD4dWB_register_Asm_32:
6686 case ARM::VLD4qWB_register_Asm_8:
6687 case ARM::VLD4qWB_register_Asm_16:
6688 case ARM::VLD4qWB_register_Asm_32: {
6689 MCInst TmpInst;
6690 unsigned Spacing;
6691 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6692 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6693 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6694 Spacing));
6695 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6696 Spacing * 2));
6697 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6698 Spacing * 3));
6699 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6700 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6701 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6702 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6703 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6704 TmpInst.addOperand(Inst.getOperand(5));
6705 Inst = TmpInst;
6706 return true;
6707 }
6708
Jim Grosbach1a747242012-01-23 23:45:44 +00006709 // VST3 multiple 3-element structure instructions.
6710 case ARM::VST3dAsm_8:
6711 case ARM::VST3dAsm_16:
6712 case ARM::VST3dAsm_32:
6713 case ARM::VST3qAsm_8:
6714 case ARM::VST3qAsm_16:
6715 case ARM::VST3qAsm_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(2)); // alignment
6721 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6722 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6723 Spacing));
6724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 Spacing * 2));
6726 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6727 TmpInst.addOperand(Inst.getOperand(4));
6728 Inst = TmpInst;
6729 return true;
6730 }
6731
6732 case ARM::VST3dWB_fixed_Asm_8:
6733 case ARM::VST3dWB_fixed_Asm_16:
6734 case ARM::VST3dWB_fixed_Asm_32:
6735 case ARM::VST3qWB_fixed_Asm_8:
6736 case ARM::VST3qWB_fixed_Asm_16:
6737 case ARM::VST3qWB_fixed_Asm_32: {
6738 MCInst TmpInst;
6739 unsigned Spacing;
6740 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6741 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6742 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6743 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6744 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6745 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6746 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6747 Spacing));
6748 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6749 Spacing * 2));
6750 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6751 TmpInst.addOperand(Inst.getOperand(4));
6752 Inst = TmpInst;
6753 return true;
6754 }
6755
6756 case ARM::VST3dWB_register_Asm_8:
6757 case ARM::VST3dWB_register_Asm_16:
6758 case ARM::VST3dWB_register_Asm_32:
6759 case ARM::VST3qWB_register_Asm_8:
6760 case ARM::VST3qWB_register_Asm_16:
6761 case ARM::VST3qWB_register_Asm_32: {
6762 MCInst TmpInst;
6763 unsigned Spacing;
6764 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6765 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6766 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6767 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6768 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6769 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6770 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6771 Spacing));
6772 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6773 Spacing * 2));
6774 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6775 TmpInst.addOperand(Inst.getOperand(5));
6776 Inst = TmpInst;
6777 return true;
6778 }
6779
Jim Grosbachda70eac2012-01-24 00:58:13 +00006780 // VST4 multiple 3-element structure instructions.
6781 case ARM::VST4dAsm_8:
6782 case ARM::VST4dAsm_16:
6783 case ARM::VST4dAsm_32:
6784 case ARM::VST4qAsm_8:
6785 case ARM::VST4qAsm_16:
6786 case ARM::VST4qAsm_32: {
6787 MCInst TmpInst;
6788 unsigned Spacing;
6789 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6790 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6791 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6792 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6793 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6794 Spacing));
6795 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6796 Spacing * 2));
6797 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6798 Spacing * 3));
6799 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6800 TmpInst.addOperand(Inst.getOperand(4));
6801 Inst = TmpInst;
6802 return true;
6803 }
6804
6805 case ARM::VST4dWB_fixed_Asm_8:
6806 case ARM::VST4dWB_fixed_Asm_16:
6807 case ARM::VST4dWB_fixed_Asm_32:
6808 case ARM::VST4qWB_fixed_Asm_8:
6809 case ARM::VST4qWB_fixed_Asm_16:
6810 case ARM::VST4qWB_fixed_Asm_32: {
6811 MCInst TmpInst;
6812 unsigned Spacing;
6813 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6814 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6815 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6816 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6817 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6818 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6819 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6820 Spacing));
6821 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6822 Spacing * 2));
6823 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6824 Spacing * 3));
6825 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6826 TmpInst.addOperand(Inst.getOperand(4));
6827 Inst = TmpInst;
6828 return true;
6829 }
6830
6831 case ARM::VST4dWB_register_Asm_8:
6832 case ARM::VST4dWB_register_Asm_16:
6833 case ARM::VST4dWB_register_Asm_32:
6834 case ARM::VST4qWB_register_Asm_8:
6835 case ARM::VST4qWB_register_Asm_16:
6836 case ARM::VST4qWB_register_Asm_32: {
6837 MCInst TmpInst;
6838 unsigned Spacing;
6839 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6840 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6841 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6842 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6843 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6844 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6845 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6846 Spacing));
6847 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6848 Spacing * 2));
6849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6850 Spacing * 3));
6851 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6852 TmpInst.addOperand(Inst.getOperand(5));
6853 Inst = TmpInst;
6854 return true;
6855 }
6856
Jim Grosbachad66de12012-04-11 00:15:16 +00006857 // Handle encoding choice for the shift-immediate instructions.
6858 case ARM::t2LSLri:
6859 case ARM::t2LSRri:
6860 case ARM::t2ASRri: {
6861 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6862 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6863 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6864 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6865 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6866 unsigned NewOpc;
6867 switch (Inst.getOpcode()) {
6868 default: llvm_unreachable("unexpected opcode");
6869 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6870 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6871 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6872 }
6873 // The Thumb1 operands aren't in the same order. Awesome, eh?
6874 MCInst TmpInst;
6875 TmpInst.setOpcode(NewOpc);
6876 TmpInst.addOperand(Inst.getOperand(0));
6877 TmpInst.addOperand(Inst.getOperand(5));
6878 TmpInst.addOperand(Inst.getOperand(1));
6879 TmpInst.addOperand(Inst.getOperand(2));
6880 TmpInst.addOperand(Inst.getOperand(3));
6881 TmpInst.addOperand(Inst.getOperand(4));
6882 Inst = TmpInst;
6883 return true;
6884 }
6885 return false;
6886 }
6887
Jim Grosbach485e5622011-12-13 22:45:11 +00006888 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006889 case ARM::t2MOVsr:
6890 case ARM::t2MOVSsr: {
6891 // Which instruction to expand to depends on the CCOut operand and
6892 // whether we're in an IT block if the register operands are low
6893 // registers.
6894 bool isNarrow = false;
6895 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6896 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6897 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6898 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6899 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6900 isNarrow = true;
6901 MCInst TmpInst;
6902 unsigned newOpc;
6903 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6904 default: llvm_unreachable("unexpected opcode!");
6905 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6906 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6907 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6908 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6909 }
6910 TmpInst.setOpcode(newOpc);
6911 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6912 if (isNarrow)
6913 TmpInst.addOperand(MCOperand::CreateReg(
6914 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6915 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6916 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6917 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6918 TmpInst.addOperand(Inst.getOperand(5));
6919 if (!isNarrow)
6920 TmpInst.addOperand(MCOperand::CreateReg(
6921 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6922 Inst = TmpInst;
6923 return true;
6924 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006925 case ARM::t2MOVsi:
6926 case ARM::t2MOVSsi: {
6927 // Which instruction to expand to depends on the CCOut operand and
6928 // whether we're in an IT block if the register operands are low
6929 // registers.
6930 bool isNarrow = false;
6931 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6932 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6933 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6934 isNarrow = true;
6935 MCInst TmpInst;
6936 unsigned newOpc;
6937 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6938 default: llvm_unreachable("unexpected opcode!");
6939 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6940 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6941 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6942 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006943 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006944 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006945 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6946 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006947 TmpInst.setOpcode(newOpc);
6948 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6949 if (isNarrow)
6950 TmpInst.addOperand(MCOperand::CreateReg(
6951 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6952 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006953 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006954 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006955 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6956 TmpInst.addOperand(Inst.getOperand(4));
6957 if (!isNarrow)
6958 TmpInst.addOperand(MCOperand::CreateReg(
6959 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6960 Inst = TmpInst;
6961 return true;
6962 }
6963 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006964 case ARM::ASRr:
6965 case ARM::LSRr:
6966 case ARM::LSLr:
6967 case ARM::RORr: {
6968 ARM_AM::ShiftOpc ShiftTy;
6969 switch(Inst.getOpcode()) {
6970 default: llvm_unreachable("unexpected opcode!");
6971 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6972 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6973 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6974 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6975 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006976 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6977 MCInst TmpInst;
6978 TmpInst.setOpcode(ARM::MOVsr);
6979 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6980 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6981 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6982 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6983 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6984 TmpInst.addOperand(Inst.getOperand(4));
6985 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6986 Inst = TmpInst;
6987 return true;
6988 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006989 case ARM::ASRi:
6990 case ARM::LSRi:
6991 case ARM::LSLi:
6992 case ARM::RORi: {
6993 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006994 switch(Inst.getOpcode()) {
6995 default: llvm_unreachable("unexpected opcode!");
6996 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6997 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6998 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6999 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7000 }
7001 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007002 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007003 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007004 // A shift by 32 should be encoded as 0 when permitted
7005 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7006 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007007 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007008 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007009 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007010 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7011 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007012 if (Opc == ARM::MOVsi)
7013 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007014 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7015 TmpInst.addOperand(Inst.getOperand(4));
7016 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7017 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007018 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007019 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007020 case ARM::RRXi: {
7021 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7022 MCInst TmpInst;
7023 TmpInst.setOpcode(ARM::MOVsi);
7024 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7025 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7026 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7027 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7028 TmpInst.addOperand(Inst.getOperand(3));
7029 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7030 Inst = TmpInst;
7031 return true;
7032 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007033 case ARM::t2LDMIA_UPD: {
7034 // If this is a load of a single register, then we should use
7035 // a post-indexed LDR instruction instead, per the ARM ARM.
7036 if (Inst.getNumOperands() != 5)
7037 return false;
7038 MCInst TmpInst;
7039 TmpInst.setOpcode(ARM::t2LDR_POST);
7040 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7041 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7042 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7043 TmpInst.addOperand(MCOperand::CreateImm(4));
7044 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7045 TmpInst.addOperand(Inst.getOperand(3));
7046 Inst = TmpInst;
7047 return true;
7048 }
7049 case ARM::t2STMDB_UPD: {
7050 // If this is a store of a single register, then we should use
7051 // a pre-indexed STR instruction instead, per the ARM ARM.
7052 if (Inst.getNumOperands() != 5)
7053 return false;
7054 MCInst TmpInst;
7055 TmpInst.setOpcode(ARM::t2STR_PRE);
7056 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7057 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7058 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7059 TmpInst.addOperand(MCOperand::CreateImm(-4));
7060 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7061 TmpInst.addOperand(Inst.getOperand(3));
7062 Inst = TmpInst;
7063 return true;
7064 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007065 case ARM::LDMIA_UPD:
7066 // If this is a load of a single register via a 'pop', then we should use
7067 // a post-indexed LDR instruction instead, per the ARM ARM.
7068 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7069 Inst.getNumOperands() == 5) {
7070 MCInst TmpInst;
7071 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7072 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7073 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7074 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7075 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7076 TmpInst.addOperand(MCOperand::CreateImm(4));
7077 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7078 TmpInst.addOperand(Inst.getOperand(3));
7079 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007080 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007081 }
7082 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007083 case ARM::STMDB_UPD:
7084 // If this is a store of a single register via a 'push', then we should use
7085 // a pre-indexed STR instruction instead, per the ARM ARM.
7086 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7087 Inst.getNumOperands() == 5) {
7088 MCInst TmpInst;
7089 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7090 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7091 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7092 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7093 TmpInst.addOperand(MCOperand::CreateImm(-4));
7094 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7095 TmpInst.addOperand(Inst.getOperand(3));
7096 Inst = TmpInst;
7097 }
7098 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007099 case ARM::t2ADDri12:
7100 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7101 // mnemonic was used (not "addw"), encoding T3 is preferred.
7102 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7103 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7104 break;
7105 Inst.setOpcode(ARM::t2ADDri);
7106 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7107 break;
7108 case ARM::t2SUBri12:
7109 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7110 // mnemonic was used (not "subw"), encoding T3 is preferred.
7111 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7112 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7113 break;
7114 Inst.setOpcode(ARM::t2SUBri);
7115 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7116 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007117 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007118 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007119 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7120 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7121 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007122 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007123 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007124 return true;
7125 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007126 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007127 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007128 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007129 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7130 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7131 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007132 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007133 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007134 return true;
7135 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007136 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007137 case ARM::t2ADDri:
7138 case ARM::t2SUBri: {
7139 // If the destination and first source operand are the same, and
7140 // the flags are compatible with the current IT status, use encoding T2
7141 // instead of T3. For compatibility with the system 'as'. Make sure the
7142 // wide encoding wasn't explicit.
7143 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007144 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007145 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7146 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7147 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7148 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7149 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7150 break;
7151 MCInst TmpInst;
7152 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7153 ARM::tADDi8 : ARM::tSUBi8);
7154 TmpInst.addOperand(Inst.getOperand(0));
7155 TmpInst.addOperand(Inst.getOperand(5));
7156 TmpInst.addOperand(Inst.getOperand(0));
7157 TmpInst.addOperand(Inst.getOperand(2));
7158 TmpInst.addOperand(Inst.getOperand(3));
7159 TmpInst.addOperand(Inst.getOperand(4));
7160 Inst = TmpInst;
7161 return true;
7162 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007163 case ARM::t2ADDrr: {
7164 // If the destination and first source operand are the same, and
7165 // there's no setting of the flags, use encoding T2 instead of T3.
7166 // Note that this is only for ADD, not SUB. This mirrors the system
7167 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7168 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7169 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007170 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7171 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007172 break;
7173 MCInst TmpInst;
7174 TmpInst.setOpcode(ARM::tADDhirr);
7175 TmpInst.addOperand(Inst.getOperand(0));
7176 TmpInst.addOperand(Inst.getOperand(0));
7177 TmpInst.addOperand(Inst.getOperand(2));
7178 TmpInst.addOperand(Inst.getOperand(3));
7179 TmpInst.addOperand(Inst.getOperand(4));
7180 Inst = TmpInst;
7181 return true;
7182 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007183 case ARM::tADDrSP: {
7184 // If the non-SP source operand and the destination operand are not the
7185 // same, we need to use the 32-bit encoding if it's available.
7186 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7187 Inst.setOpcode(ARM::t2ADDrr);
7188 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7189 return true;
7190 }
7191 break;
7192 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007193 case ARM::tB:
7194 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007195 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007196 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007197 return true;
7198 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007199 break;
7200 case ARM::t2B:
7201 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007202 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007203 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007204 return true;
7205 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007206 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007207 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007208 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007209 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007210 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007211 return true;
7212 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007213 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007214 case ARM::tBcc:
7215 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007216 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007217 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007218 return true;
7219 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007220 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007221 case ARM::tLDMIA: {
7222 // If the register list contains any high registers, or if the writeback
7223 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7224 // instead if we're in Thumb2. Otherwise, this should have generated
7225 // an error in validateInstruction().
7226 unsigned Rn = Inst.getOperand(0).getReg();
7227 bool hasWritebackToken =
7228 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7229 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7230 bool listContainsBase;
7231 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7232 (!listContainsBase && !hasWritebackToken) ||
7233 (listContainsBase && hasWritebackToken)) {
7234 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7235 assert (isThumbTwo());
7236 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7237 // If we're switching to the updating version, we need to insert
7238 // the writeback tied operand.
7239 if (hasWritebackToken)
7240 Inst.insert(Inst.begin(),
7241 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007242 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007243 }
7244 break;
7245 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007246 case ARM::tSTMIA_UPD: {
7247 // If the register list contains any high registers, we need to use
7248 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7249 // should have generated an error in validateInstruction().
7250 unsigned Rn = Inst.getOperand(0).getReg();
7251 bool listContainsBase;
7252 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7253 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7254 assert (isThumbTwo());
7255 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007256 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007257 }
7258 break;
7259 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007260 case ARM::tPOP: {
7261 bool listContainsBase;
7262 // If the register list contains any high registers, we need to use
7263 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7264 // should have generated an error in validateInstruction().
7265 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007266 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007267 assert (isThumbTwo());
7268 Inst.setOpcode(ARM::t2LDMIA_UPD);
7269 // Add the base register and writeback operands.
7270 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7271 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007272 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007273 }
7274 case ARM::tPUSH: {
7275 bool listContainsBase;
7276 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007277 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007278 assert (isThumbTwo());
7279 Inst.setOpcode(ARM::t2STMDB_UPD);
7280 // Add the base register and writeback operands.
7281 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7282 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007283 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007284 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007285 case ARM::t2MOVi: {
7286 // If we can use the 16-bit encoding and the user didn't explicitly
7287 // request the 32-bit variant, transform it here.
7288 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007289 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007290 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7291 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7292 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007293 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7294 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7295 // The operands aren't in the same order for tMOVi8...
7296 MCInst TmpInst;
7297 TmpInst.setOpcode(ARM::tMOVi8);
7298 TmpInst.addOperand(Inst.getOperand(0));
7299 TmpInst.addOperand(Inst.getOperand(4));
7300 TmpInst.addOperand(Inst.getOperand(1));
7301 TmpInst.addOperand(Inst.getOperand(2));
7302 TmpInst.addOperand(Inst.getOperand(3));
7303 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007304 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007305 }
7306 break;
7307 }
7308 case ARM::t2MOVr: {
7309 // If we can use the 16-bit encoding and the user didn't explicitly
7310 // request the 32-bit variant, transform it here.
7311 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7312 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7313 Inst.getOperand(2).getImm() == ARMCC::AL &&
7314 Inst.getOperand(4).getReg() == ARM::CPSR &&
7315 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7316 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7317 // The operands aren't the same for tMOV[S]r... (no cc_out)
7318 MCInst TmpInst;
7319 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7320 TmpInst.addOperand(Inst.getOperand(0));
7321 TmpInst.addOperand(Inst.getOperand(1));
7322 TmpInst.addOperand(Inst.getOperand(2));
7323 TmpInst.addOperand(Inst.getOperand(3));
7324 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007325 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007326 }
7327 break;
7328 }
Jim Grosbach82213192011-09-19 20:29:33 +00007329 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007330 case ARM::t2SXTB:
7331 case ARM::t2UXTH:
7332 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007333 // If we can use the 16-bit encoding and the user didn't explicitly
7334 // request the 32-bit variant, transform it here.
7335 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7336 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7337 Inst.getOperand(2).getImm() == 0 &&
7338 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7339 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007340 unsigned NewOpc;
7341 switch (Inst.getOpcode()) {
7342 default: llvm_unreachable("Illegal opcode!");
7343 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7344 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7345 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7346 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7347 }
Jim Grosbach82213192011-09-19 20:29:33 +00007348 // The operands aren't the same for thumb1 (no rotate operand).
7349 MCInst TmpInst;
7350 TmpInst.setOpcode(NewOpc);
7351 TmpInst.addOperand(Inst.getOperand(0));
7352 TmpInst.addOperand(Inst.getOperand(1));
7353 TmpInst.addOperand(Inst.getOperand(3));
7354 TmpInst.addOperand(Inst.getOperand(4));
7355 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007356 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007357 }
7358 break;
7359 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007360 case ARM::MOVsi: {
7361 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007362 // rrx shifts and asr/lsr of #32 is encoded as 0
7363 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7364 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007365 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7366 // Shifting by zero is accepted as a vanilla 'MOVr'
7367 MCInst TmpInst;
7368 TmpInst.setOpcode(ARM::MOVr);
7369 TmpInst.addOperand(Inst.getOperand(0));
7370 TmpInst.addOperand(Inst.getOperand(1));
7371 TmpInst.addOperand(Inst.getOperand(3));
7372 TmpInst.addOperand(Inst.getOperand(4));
7373 TmpInst.addOperand(Inst.getOperand(5));
7374 Inst = TmpInst;
7375 return true;
7376 }
7377 return false;
7378 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007379 case ARM::ANDrsi:
7380 case ARM::ORRrsi:
7381 case ARM::EORrsi:
7382 case ARM::BICrsi:
7383 case ARM::SUBrsi:
7384 case ARM::ADDrsi: {
7385 unsigned newOpc;
7386 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7387 if (SOpc == ARM_AM::rrx) return false;
7388 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007389 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007390 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7391 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7392 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7393 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7394 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7395 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7396 }
7397 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007398 // The exception is for right shifts, where 0 == 32
7399 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7400 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007401 MCInst TmpInst;
7402 TmpInst.setOpcode(newOpc);
7403 TmpInst.addOperand(Inst.getOperand(0));
7404 TmpInst.addOperand(Inst.getOperand(1));
7405 TmpInst.addOperand(Inst.getOperand(2));
7406 TmpInst.addOperand(Inst.getOperand(4));
7407 TmpInst.addOperand(Inst.getOperand(5));
7408 TmpInst.addOperand(Inst.getOperand(6));
7409 Inst = TmpInst;
7410 return true;
7411 }
7412 return false;
7413 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007414 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007415 case ARM::t2IT: {
7416 // The mask bits for all but the first condition are represented as
7417 // the low bit of the condition code value implies 't'. We currently
7418 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007419 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007420 MCOperand &MO = Inst.getOperand(1);
7421 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007422 unsigned OrigMask = Mask;
7423 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007424 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007425 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7426 for (unsigned i = 3; i != TZ; --i)
7427 Mask ^= 1 << i;
Richard Bartonf435b092012-04-27 08:42:59 +00007428 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007429 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007430
7431 // Set up the IT block state according to the IT instruction we just
7432 // matched.
7433 assert(!inITBlock() && "nested IT blocks?!");
7434 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7435 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7436 ITState.CurPosition = 0;
7437 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007438 break;
7439 }
Richard Bartona39625e2012-07-09 16:12:24 +00007440 case ARM::t2LSLrr:
7441 case ARM::t2LSRrr:
7442 case ARM::t2ASRrr:
7443 case ARM::t2SBCrr:
7444 case ARM::t2RORrr:
7445 case ARM::t2BICrr:
7446 {
Richard Bartond5660372012-07-09 16:14:28 +00007447 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007448 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7449 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7450 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007451 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7452 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007453 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7454 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7455 unsigned NewOpc;
7456 switch (Inst.getOpcode()) {
7457 default: llvm_unreachable("unexpected opcode");
7458 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7459 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7460 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7461 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7462 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7463 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7464 }
7465 MCInst TmpInst;
7466 TmpInst.setOpcode(NewOpc);
7467 TmpInst.addOperand(Inst.getOperand(0));
7468 TmpInst.addOperand(Inst.getOperand(5));
7469 TmpInst.addOperand(Inst.getOperand(1));
7470 TmpInst.addOperand(Inst.getOperand(2));
7471 TmpInst.addOperand(Inst.getOperand(3));
7472 TmpInst.addOperand(Inst.getOperand(4));
7473 Inst = TmpInst;
7474 return true;
7475 }
7476 return false;
7477 }
7478 case ARM::t2ANDrr:
7479 case ARM::t2EORrr:
7480 case ARM::t2ADCrr:
7481 case ARM::t2ORRrr:
7482 {
Richard Bartond5660372012-07-09 16:14:28 +00007483 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007484 // These instructions are special in that they are commutable, so shorter encodings
7485 // are available more often.
7486 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7487 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7488 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7489 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007490 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7491 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007492 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7493 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7494 unsigned NewOpc;
7495 switch (Inst.getOpcode()) {
7496 default: llvm_unreachable("unexpected opcode");
7497 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7498 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7499 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7500 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7501 }
7502 MCInst TmpInst;
7503 TmpInst.setOpcode(NewOpc);
7504 TmpInst.addOperand(Inst.getOperand(0));
7505 TmpInst.addOperand(Inst.getOperand(5));
7506 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7507 TmpInst.addOperand(Inst.getOperand(1));
7508 TmpInst.addOperand(Inst.getOperand(2));
7509 } else {
7510 TmpInst.addOperand(Inst.getOperand(2));
7511 TmpInst.addOperand(Inst.getOperand(1));
7512 }
7513 TmpInst.addOperand(Inst.getOperand(3));
7514 TmpInst.addOperand(Inst.getOperand(4));
7515 Inst = TmpInst;
7516 return true;
7517 }
7518 return false;
7519 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007520 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007521 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007522}
7523
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007524unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7525 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7526 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007527 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007528 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007529 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7530 assert(MCID.hasOptionalDef() &&
7531 "optionally flag setting instruction missing optional def operand");
7532 assert(MCID.NumOperands == Inst.getNumOperands() &&
7533 "operand count mismatch!");
7534 // Find the optional-def operand (cc_out).
7535 unsigned OpNo;
7536 for (OpNo = 0;
7537 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7538 ++OpNo)
7539 ;
7540 // If we're parsing Thumb1, reject it completely.
7541 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7542 return Match_MnemonicFail;
7543 // If we're parsing Thumb2, which form is legal depends on whether we're
7544 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007545 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7546 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007547 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007548 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7549 inITBlock())
7550 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007551 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007552 // Some high-register supporting Thumb1 encodings only allow both registers
7553 // to be from r0-r7 when in Thumb2.
7554 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7555 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7556 isARMLowRegister(Inst.getOperand(2).getReg()))
7557 return Match_RequiresThumb2;
7558 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007559 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007560 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7561 isARMLowRegister(Inst.getOperand(1).getReg()))
7562 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007563 return Match_Success;
7564}
7565
Jim Grosbach5117ef72012-04-24 22:40:08 +00007566static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007567bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007568MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007569 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007570 MCStreamer &Out, unsigned &ErrorInfo,
7571 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007572 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007573 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007574
Chad Rosier2f480a82012-10-12 22:53:36 +00007575 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007576 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007577 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007578 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007579 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007580 // Context sensitive operand constraints aren't handled by the matcher,
7581 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007582 if (validateInstruction(Inst, Operands)) {
7583 // Still progress the IT block, otherwise one wrong condition causes
7584 // nasty cascading errors.
7585 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007586 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007587 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007588
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007589 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007590 // encoding is selected. Loop on it while changes happen so the
7591 // individual transformations can chain off each other. E.g.,
7592 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7593 while (processInstruction(Inst, Operands))
7594 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007595
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007596 // Only move forward at the very end so that everything in validate
7597 // and process gets a consistent answer about whether we're in an IT
7598 // block.
7599 forwardITPosition();
7600
Jim Grosbach82f76d12012-01-25 19:52:01 +00007601 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7602 // doesn't actually encode.
7603 if (Inst.getOpcode() == ARM::ITasm)
7604 return false;
7605
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007606 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007607 Out.EmitInstruction(Inst);
7608 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007609 case Match_MissingFeature: {
7610 assert(ErrorInfo && "Unknown missing feature!");
7611 // Special case the error message for the very common case where only
7612 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7613 std::string Msg = "instruction requires:";
7614 unsigned Mask = 1;
7615 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7616 if (ErrorInfo & Mask) {
7617 Msg += " ";
7618 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7619 }
7620 Mask <<= 1;
7621 }
7622 return Error(IDLoc, Msg);
7623 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007624 case Match_InvalidOperand: {
7625 SMLoc ErrorLoc = IDLoc;
7626 if (ErrorInfo != ~0U) {
7627 if (ErrorInfo >= Operands.size())
7628 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007629
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007630 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7631 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7632 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007633
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007634 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007635 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007636 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007637 return Error(IDLoc, "invalid instruction",
7638 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007639 case Match_RequiresNotITBlock:
7640 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007641 case Match_RequiresITBlock:
7642 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007643 case Match_RequiresV6:
7644 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7645 case Match_RequiresThumb2:
7646 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007647 case Match_ImmRange0_4: {
7648 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7649 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7650 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7651 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007652 case Match_ImmRange0_15: {
7653 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7654 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7655 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7656 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007657 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007658
Eric Christopher91d7b902010-10-29 09:26:59 +00007659 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007660}
7661
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007662/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007663bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7664 StringRef IDVal = DirectiveID.getIdentifier();
7665 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007666 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007667 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007668 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007669 else if (IDVal == ".arm")
7670 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007671 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007672 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007673 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007674 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007675 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007676 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007677 else if (IDVal == ".unreq")
7678 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007679 else if (IDVal == ".arch")
7680 return parseDirectiveArch(DirectiveID.getLoc());
7681 else if (IDVal == ".eabi_attribute")
7682 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007683 else if (IDVal == ".fnstart")
7684 return parseDirectiveFnStart(DirectiveID.getLoc());
7685 else if (IDVal == ".fnend")
7686 return parseDirectiveFnEnd(DirectiveID.getLoc());
7687 else if (IDVal == ".cantunwind")
7688 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7689 else if (IDVal == ".personality")
7690 return parseDirectivePersonality(DirectiveID.getLoc());
7691 else if (IDVal == ".handlerdata")
7692 return parseDirectiveHandlerData(DirectiveID.getLoc());
7693 else if (IDVal == ".setfp")
7694 return parseDirectiveSetFP(DirectiveID.getLoc());
7695 else if (IDVal == ".pad")
7696 return parseDirectivePad(DirectiveID.getLoc());
7697 else if (IDVal == ".save")
7698 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7699 else if (IDVal == ".vsave")
7700 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007701 return true;
7702}
7703
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007704/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007705/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007706bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007707 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7708 for (;;) {
7709 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007710 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007711 return true;
7712
Eric Christopherbf7bc492013-01-09 03:52:05 +00007713 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007714
7715 if (getLexer().is(AsmToken::EndOfStatement))
7716 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007717
Kevin Enderbyccab3172009-09-15 00:27:25 +00007718 // FIXME: Improve diagnostic.
7719 if (getLexer().isNot(AsmToken::Comma))
7720 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007721 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007722 }
7723 }
7724
Sean Callanana83fd7d2010-01-19 20:27:46 +00007725 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007726 return false;
7727}
7728
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007729/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007730/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007731bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007732 if (getLexer().isNot(AsmToken::EndOfStatement))
7733 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007734 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007735
Jim Grosbach7f882392011-12-07 18:04:19 +00007736 if (!isThumb())
7737 SwitchMode();
7738 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7739 return false;
7740}
7741
7742/// parseDirectiveARM
7743/// ::= .arm
7744bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7745 if (getLexer().isNot(AsmToken::EndOfStatement))
7746 return Error(L, "unexpected token in directive");
7747 Parser.Lex();
7748
7749 if (isThumb())
7750 SwitchMode();
7751 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007752 return false;
7753}
7754
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007755/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007756/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007757bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007758 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7759 bool isMachO = MAI.hasSubsectionsViaSymbols();
7760 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007761 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007762
Jim Grosbach1152cc02011-12-21 22:30:16 +00007763 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007764 // ELF doesn't
7765 if (isMachO) {
7766 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007767 if (Tok.isNot(AsmToken::EndOfStatement)) {
7768 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7769 return Error(L, "unexpected token in .thumb_func directive");
7770 Name = Tok.getIdentifier();
7771 Parser.Lex(); // Consume the identifier token.
7772 needFuncName = false;
7773 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007774 }
7775
Jim Grosbach1152cc02011-12-21 22:30:16 +00007776 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007777 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007778
7779 // Eat the end of statement and any blank lines that follow.
7780 while (getLexer().is(AsmToken::EndOfStatement))
7781 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007782
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007783 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007784 // We really should be checking the next symbol definition even if there's
7785 // stuff in between.
7786 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007787 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007788 }
7789
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007790 // Mark symbol as a thumb symbol.
7791 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7792 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007793 return false;
7794}
7795
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007796/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007797/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007798bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007799 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007800 if (Tok.isNot(AsmToken::Identifier))
7801 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007802 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007803 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007804 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007805 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007806 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007807 else
7808 return Error(L, "unrecognized syntax mode in .syntax directive");
7809
7810 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007811 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007812 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007813
7814 // TODO tell the MC streamer the mode
7815 // getParser().getStreamer().Emit???();
7816 return false;
7817}
7818
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007819/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007820/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007821bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007822 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007823 if (Tok.isNot(AsmToken::Integer))
7824 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007825 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007826 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007827 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007828 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007829 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007830 else
7831 return Error(L, "invalid operand to .code directive");
7832
7833 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007834 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007835 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007836
Evan Cheng284b4672011-07-08 22:36:29 +00007837 if (Val == 16) {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007838 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007839 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007840 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007841 } else {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007842 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007843 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007844 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007845 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007846
Kevin Enderby146dcf22009-10-15 20:48:48 +00007847 return false;
7848}
7849
Jim Grosbachab5830e2011-12-14 02:16:11 +00007850/// parseDirectiveReq
7851/// ::= name .req registername
7852bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7853 Parser.Lex(); // Eat the '.req' token.
7854 unsigned Reg;
7855 SMLoc SRegLoc, ERegLoc;
7856 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007857 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007858 return Error(SRegLoc, "register name expected");
7859 }
7860
7861 // Shouldn't be anything else.
7862 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007863 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007864 return Error(Parser.getTok().getLoc(),
7865 "unexpected input in .req directive.");
7866 }
7867
7868 Parser.Lex(); // Consume the EndOfStatement
7869
7870 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7871 return Error(SRegLoc, "redefinition of '" + Name +
7872 "' does not match original.");
7873
7874 return false;
7875}
7876
7877/// parseDirectiveUneq
7878/// ::= .unreq registername
7879bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7880 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007881 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007882 return Error(L, "unexpected input in .unreq directive.");
7883 }
7884 RegisterReqs.erase(Parser.getTok().getIdentifier());
7885 Parser.Lex(); // Eat the identifier.
7886 return false;
7887}
7888
Jason W Kim135d2442011-12-20 17:38:12 +00007889/// parseDirectiveArch
7890/// ::= .arch token
7891bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7892 return true;
7893}
7894
7895/// parseDirectiveEabiAttr
7896/// ::= .eabi_attribute int, int
7897bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7898 return true;
7899}
7900
Logan Chien4ea23b52013-05-10 16:17:24 +00007901/// parseDirectiveFnStart
7902/// ::= .fnstart
7903bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7904 if (FnStartLoc.isValid()) {
7905 Error(L, ".fnstart starts before the end of previous one");
7906 Error(FnStartLoc, "previous .fnstart starts here");
7907 return true;
7908 }
7909
7910 FnStartLoc = L;
7911 getParser().getStreamer().EmitFnStart();
7912 return false;
7913}
7914
7915/// parseDirectiveFnEnd
7916/// ::= .fnend
7917bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7918 // Check the ordering of unwind directives
7919 if (!FnStartLoc.isValid())
7920 return Error(L, ".fnstart must precede .fnend directive");
7921
7922 // Reset the unwind directives parser state
7923 resetUnwindDirectiveParserState();
7924
7925 getParser().getStreamer().EmitFnEnd();
7926 return false;
7927}
7928
7929/// parseDirectiveCantUnwind
7930/// ::= .cantunwind
7931bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7932 // Check the ordering of unwind directives
7933 CantUnwindLoc = L;
7934 if (!FnStartLoc.isValid())
7935 return Error(L, ".fnstart must precede .cantunwind directive");
7936 if (HandlerDataLoc.isValid()) {
7937 Error(L, ".cantunwind can't be used with .handlerdata directive");
7938 Error(HandlerDataLoc, ".handlerdata was specified here");
7939 return true;
7940 }
7941 if (PersonalityLoc.isValid()) {
7942 Error(L, ".cantunwind can't be used with .personality directive");
7943 Error(PersonalityLoc, ".personality was specified here");
7944 return true;
7945 }
7946
7947 getParser().getStreamer().EmitCantUnwind();
7948 return false;
7949}
7950
7951/// parseDirectivePersonality
7952/// ::= .personality name
7953bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7954 // Check the ordering of unwind directives
7955 PersonalityLoc = L;
7956 if (!FnStartLoc.isValid())
7957 return Error(L, ".fnstart must precede .personality directive");
7958 if (CantUnwindLoc.isValid()) {
7959 Error(L, ".personality can't be used with .cantunwind directive");
7960 Error(CantUnwindLoc, ".cantunwind was specified here");
7961 return true;
7962 }
7963 if (HandlerDataLoc.isValid()) {
7964 Error(L, ".personality must precede .handlerdata directive");
7965 Error(HandlerDataLoc, ".handlerdata was specified here");
7966 return true;
7967 }
7968
7969 // Parse the name of the personality routine
7970 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7971 Parser.eatToEndOfStatement();
7972 return Error(L, "unexpected input in .personality directive.");
7973 }
7974 StringRef Name(Parser.getTok().getIdentifier());
7975 Parser.Lex();
7976
7977 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
7978 getParser().getStreamer().EmitPersonality(PR);
7979 return false;
7980}
7981
7982/// parseDirectiveHandlerData
7983/// ::= .handlerdata
7984bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
7985 // Check the ordering of unwind directives
7986 HandlerDataLoc = L;
7987 if (!FnStartLoc.isValid())
7988 return Error(L, ".fnstart must precede .personality directive");
7989 if (CantUnwindLoc.isValid()) {
7990 Error(L, ".handlerdata can't be used with .cantunwind directive");
7991 Error(CantUnwindLoc, ".cantunwind was specified here");
7992 return true;
7993 }
7994
7995 getParser().getStreamer().EmitHandlerData();
7996 return false;
7997}
7998
7999/// parseDirectiveSetFP
8000/// ::= .setfp fpreg, spreg [, offset]
8001bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8002 // Check the ordering of unwind directives
8003 if (!FnStartLoc.isValid())
8004 return Error(L, ".fnstart must precede .setfp directive");
8005 if (HandlerDataLoc.isValid())
8006 return Error(L, ".setfp must precede .handlerdata directive");
8007
8008 // Parse fpreg
8009 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8010 int NewFPReg = tryParseRegister();
8011 if (NewFPReg == -1)
8012 return Error(NewFPRegLoc, "frame pointer register expected");
8013
8014 // Consume comma
8015 if (!Parser.getTok().is(AsmToken::Comma))
8016 return Error(Parser.getTok().getLoc(), "comma expected");
8017 Parser.Lex(); // skip comma
8018
8019 // Parse spreg
8020 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8021 int NewSPReg = tryParseRegister();
8022 if (NewSPReg == -1)
8023 return Error(NewSPRegLoc, "stack pointer register expected");
8024
8025 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8026 return Error(NewSPRegLoc,
8027 "register should be either $sp or the latest fp register");
8028
8029 // Update the frame pointer register
8030 FPReg = NewFPReg;
8031
8032 // Parse offset
8033 int64_t Offset = 0;
8034 if (Parser.getTok().is(AsmToken::Comma)) {
8035 Parser.Lex(); // skip comma
8036
8037 if (Parser.getTok().isNot(AsmToken::Hash) &&
8038 Parser.getTok().isNot(AsmToken::Dollar)) {
8039 return Error(Parser.getTok().getLoc(), "'#' expected");
8040 }
8041 Parser.Lex(); // skip hash token.
8042
8043 const MCExpr *OffsetExpr;
8044 SMLoc ExLoc = Parser.getTok().getLoc();
8045 SMLoc EndLoc;
8046 if (getParser().parseExpression(OffsetExpr, EndLoc))
8047 return Error(ExLoc, "malformed setfp offset");
8048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8049 if (!CE)
8050 return Error(ExLoc, "setfp offset must be an immediate");
8051
8052 Offset = CE->getValue();
8053 }
8054
8055 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8056 static_cast<unsigned>(NewSPReg),
8057 Offset);
8058 return false;
8059}
8060
8061/// parseDirective
8062/// ::= .pad offset
8063bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8064 // Check the ordering of unwind directives
8065 if (!FnStartLoc.isValid())
8066 return Error(L, ".fnstart must precede .pad directive");
8067 if (HandlerDataLoc.isValid())
8068 return Error(L, ".pad must precede .handlerdata directive");
8069
8070 // Parse the offset
8071 if (Parser.getTok().isNot(AsmToken::Hash) &&
8072 Parser.getTok().isNot(AsmToken::Dollar)) {
8073 return Error(Parser.getTok().getLoc(), "'#' expected");
8074 }
8075 Parser.Lex(); // skip hash token.
8076
8077 const MCExpr *OffsetExpr;
8078 SMLoc ExLoc = Parser.getTok().getLoc();
8079 SMLoc EndLoc;
8080 if (getParser().parseExpression(OffsetExpr, EndLoc))
8081 return Error(ExLoc, "malformed pad offset");
8082 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8083 if (!CE)
8084 return Error(ExLoc, "pad offset must be an immediate");
8085
8086 getParser().getStreamer().EmitPad(CE->getValue());
8087 return false;
8088}
8089
8090/// parseDirectiveRegSave
8091/// ::= .save { registers }
8092/// ::= .vsave { registers }
8093bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8094 // Check the ordering of unwind directives
8095 if (!FnStartLoc.isValid())
8096 return Error(L, ".fnstart must precede .save or .vsave directives");
8097 if (HandlerDataLoc.isValid())
8098 return Error(L, ".save or .vsave must precede .handlerdata directive");
8099
8100 // Parse the register list
8101 SmallVector<MCParsedAsmOperand*, 1> Operands;
8102 if (parseRegisterList(Operands))
8103 return true;
8104 ARMOperand *Op = (ARMOperand*)Operands[0];
8105 if (!IsVector && !Op->isRegList())
8106 return Error(L, ".save expects GPR registers");
8107 if (IsVector && !Op->isDPRRegList())
8108 return Error(L, ".vsave expects DPR registers");
8109
8110 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8111 return false;
8112}
8113
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008114/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008115extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008116 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8117 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008118}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008119
Chris Lattner3e4582a2010-09-06 19:11:01 +00008120#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008121#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008122#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008123#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008124
8125// Define this matcher function after the auto-generated include so we
8126// have the match class enum definitions.
8127unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8128 unsigned Kind) {
8129 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8130 // If the kind is a token for a literal immediate, check if our asm
8131 // operand matches. This is for InstAliases which have a fixed-value
8132 // immediate in the syntax.
8133 if (Kind == MCK__35_0 && Op->isImm()) {
8134 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8135 if (!CE)
8136 return Match_InvalidOperand;
8137 if (CE->getValue() == 0)
8138 return Match_Success;
8139 }
8140 return Match_InvalidOperand;
8141}