blob: 209741aaaeec86de80aed6d45c248d000f66f9d0 [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
Logan Chien8cbb80d2013-10-28 17:51:12 +000010#include "ARMBuildAttrs.h"
11#include "ARMFPUName.h"
Amara Emerson52cfb6a2013-10-03 09:31:51 +000012#include "ARMFeatures.h"
Evan Cheng11424442011-07-26 00:24:13 +000013#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "MCTargetDesc/ARMAddressingModes.h"
Logan Chien439e8f92013-12-11 17:16:25 +000015#include "MCTargetDesc/ARMArchName.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "MCTargetDesc/ARMBaseInfo.h"
17#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000018#include "llvm/ADT/BitVector.h"
David Peixotto52303f62013-12-19 22:41:56 +000019#include "llvm/ADT/MapVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000020#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000021#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000022#include "llvm/ADT/SmallVector.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000023#include "llvm/ADT/StringExtras.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000024#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000025#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000026#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000027#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000028#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000029#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000030#include "llvm/MC/MCExpr.h"
31#include "llvm/MC/MCInst.h"
32#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000033#include "llvm/MC/MCInstrInfo.h"
Saleem Abdulrasoola5549682013-12-26 01:52:28 +000034#include "llvm/MC/MCSection.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000035#include "llvm/MC/MCParser/MCAsmLexer.h"
36#include "llvm/MC/MCParser/MCAsmParser.h"
37#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
38#include "llvm/MC/MCRegisterInfo.h"
39#include "llvm/MC/MCStreamer.h"
40#include "llvm/MC/MCSubtargetInfo.h"
David Peixottoe407d092013-12-19 18:12:36 +000041#include "llvm/MC/MCSymbol.h"
Jack Carter718da0b2013-01-30 02:24:33 +000042#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000043#include "llvm/Support/MathExtras.h"
44#include "llvm/Support/SourceMgr.h"
45#include "llvm/Support/TargetRegistry.h"
46#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000047
Kevin Enderbyccab3172009-09-15 00:27:25 +000048using namespace llvm;
49
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000050namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000051
52class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000053
Jim Grosbach04945c42011-12-02 00:35:16 +000054enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000055
David Peixottoe407d092013-12-19 18:12:36 +000056// A class to keep track of assembler-generated constant pools that are use to
57// implement the ldr-pseudo.
58class ConstantPool {
59 typedef SmallVector<std::pair<MCSymbol *, const MCExpr *>, 4> EntryVecTy;
60 EntryVecTy Entries;
61
62public:
63 // Initialize a new empty constant pool
64 ConstantPool() { }
65
66 // Add a new entry to the constant pool in the next slot.
67 // \param Value is the new entry to put in the constant pool.
68 //
69 // \returns a MCExpr that references the newly inserted value
70 const MCExpr *addEntry(const MCExpr *Value, MCContext &Context) {
71 MCSymbol *CPEntryLabel = Context.CreateTempSymbol();
72
73 Entries.push_back(std::make_pair(CPEntryLabel, Value));
74 return MCSymbolRefExpr::Create(CPEntryLabel, Context);
75 }
76
77 // Emit the contents of the constant pool using the provided streamer.
David Peixotto52303f62013-12-19 22:41:56 +000078 void emitEntries(MCStreamer &Streamer) {
79 if (Entries.empty())
80 return;
David Peixottoe407d092013-12-19 18:12:36 +000081 Streamer.EmitCodeAlignment(4); // align to 4-byte address
82 Streamer.EmitDataRegion(MCDR_DataRegion);
83 for (EntryVecTy::const_iterator I = Entries.begin(), E = Entries.end();
84 I != E; ++I) {
85 Streamer.EmitLabel(I->first);
86 Streamer.EmitValue(I->second, 4);
87 }
88 Streamer.EmitDataRegion(MCDR_DataRegionEnd);
David Peixotto52303f62013-12-19 22:41:56 +000089 Entries.clear();
90 }
91
92 // Return true if the constant pool is empty
93 bool empty() {
94 return Entries.empty();
David Peixottoe407d092013-12-19 18:12:36 +000095 }
96};
97
98// Map type used to keep track of per-Section constant pools used by the
99// ldr-pseudo opcode. The map associates a section to its constant pool. The
100// constant pool is a vector of (label, value) pairs. When the ldr
101// pseudo is parsed we insert a new (label, value) pair into the constant pool
102// for the current section and add MCSymbolRefExpr to the new label as
103// an opcode to the ldr. After we have parsed all the user input we
104// output the (label, value) pairs in each constant pool at the end of the
105// section.
David Peixotto52303f62013-12-19 22:41:56 +0000106//
107// We use the MapVector for the map type to ensure stable iteration of
108// the sections at the end of the parse. We need to iterate over the
109// sections in a stable order to ensure that we have print the
110// constant pools in a deterministic order when printing an assembly
111// file.
112typedef MapVector<const MCSection *, ConstantPool> ConstantPoolMapTy;
David Peixottoe407d092013-12-19 18:12:36 +0000113
Evan Cheng11424442011-07-26 00:24:13 +0000114class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +0000115 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000116 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +0000117 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000118 const MCRegisterInfo *MRI;
David Peixottoe407d092013-12-19 18:12:36 +0000119 ConstantPoolMapTy ConstantPools;
120
121 // Assembler created constant pools for ldr pseudo
122 ConstantPool *getConstantPool(const MCSection *Section) {
123 ConstantPoolMapTy::iterator CP = ConstantPools.find(Section);
124 if (CP == ConstantPools.end())
125 return 0;
126
127 return &CP->second;
128 }
129
130 ConstantPool &getOrCreateConstantPool(const MCSection *Section) {
131 return ConstantPools[Section];
132 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000133
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000134 ARMTargetStreamer &getTargetStreamer() {
135 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
136 return static_cast<ARMTargetStreamer &>(TS);
137 }
138
Logan Chien4ea23b52013-05-10 16:17:24 +0000139 // Unwind directives state
140 SMLoc FnStartLoc;
141 SMLoc CantUnwindLoc;
142 SMLoc PersonalityLoc;
143 SMLoc HandlerDataLoc;
144 int FPReg;
145 void resetUnwindDirectiveParserState() {
146 FnStartLoc = SMLoc();
147 CantUnwindLoc = SMLoc();
148 PersonalityLoc = SMLoc();
149 HandlerDataLoc = SMLoc();
150 FPReg = -1;
151 }
152
Jim Grosbachab5830e2011-12-14 02:16:11 +0000153 // Map of register aliases registers via the .req directive.
154 StringMap<unsigned> RegisterReqs;
155
Tim Northover1744d0a2013-10-25 12:49:50 +0000156 bool NextSymbolIsThumb;
157
Jim Grosbached16ec42011-08-29 22:24:09 +0000158 struct {
159 ARMCC::CondCodes Cond; // Condition for IT block.
160 unsigned Mask:4; // Condition mask for instructions.
161 // Starting at first 1 (from lsb).
162 // '1' condition as indicated in IT.
163 // '0' inverse of condition (else).
164 // Count of instructions in IT block is
165 // 4 - trailingzeroes(mask)
166
167 bool FirstCond; // Explicit flag for when we're parsing the
168 // First instruction in the IT block. It's
169 // implied in the mask, so needs special
170 // handling.
171
172 unsigned CurPosition; // Current position in parsing of IT
173 // block. In range [0,3]. Initialized
174 // according to count of instructions in block.
175 // ~0U if no active IT block.
176 } ITState;
177 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000178 void forwardITPosition() {
179 if (!inITBlock()) return;
180 // Move to the next instruction in the IT block, if there is one. If not,
181 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000182 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000183 if (++ITState.CurPosition == 5 - TZ)
184 ITState.CurPosition = ~0U; // Done with the IT block after this.
185 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000186
187
Kevin Enderbyccab3172009-09-15 00:27:25 +0000188 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000189 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
190
Benjamin Kramer673824b2012-04-15 17:04:27 +0000191 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000192 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000193 return Parser.Warning(L, Msg, Ranges);
194 }
195 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000196 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000197 return Parser.Error(L, Msg, Ranges);
198 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000199
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000200 int tryParseRegister();
201 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000202 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000203 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000204 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000205 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
206 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000207 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
208 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000209 bool parseDirectiveWord(unsigned Size, SMLoc L);
210 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000211 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000212 bool parseDirectiveThumbFunc(SMLoc L);
213 bool parseDirectiveCode(SMLoc L);
214 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000215 bool parseDirectiveReq(StringRef Name, SMLoc L);
216 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000217 bool parseDirectiveArch(SMLoc L);
218 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000219 bool parseDirectiveCPU(SMLoc L);
220 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000221 bool parseDirectiveFnStart(SMLoc L);
222 bool parseDirectiveFnEnd(SMLoc L);
223 bool parseDirectiveCantUnwind(SMLoc L);
224 bool parseDirectivePersonality(SMLoc L);
225 bool parseDirectiveHandlerData(SMLoc L);
226 bool parseDirectiveSetFP(SMLoc L);
227 bool parseDirectivePad(SMLoc L);
228 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000229 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
David Peixotto80c083a2013-12-19 18:26:07 +0000230 bool parseDirectiveLtorg(SMLoc L);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +0000231 bool parseDirectiveEven(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000232
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000233 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000234 bool &CarrySetting, unsigned &ProcessorIMod,
235 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000236 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
237 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000238 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000239
Evan Cheng4d1ca962011-07-08 01:53:10 +0000240 bool isThumb() const {
241 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000242 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000243 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000244 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000245 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000246 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000247 bool isThumbTwo() const {
248 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
249 }
Tim Northovera2292d02013-06-10 23:20:58 +0000250 bool hasThumb() const {
251 return STI.getFeatureBits() & ARM::HasV4TOps;
252 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000253 bool hasV6Ops() const {
254 return STI.getFeatureBits() & ARM::HasV6Ops;
255 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000256 bool hasV6MOps() const {
257 return STI.getFeatureBits() & ARM::HasV6MOps;
258 }
James Molloy21efa7d2011-09-28 14:21:38 +0000259 bool hasV7Ops() const {
260 return STI.getFeatureBits() & ARM::HasV7Ops;
261 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000262 bool hasV8Ops() const {
263 return STI.getFeatureBits() & ARM::HasV8Ops;
264 }
Tim Northovera2292d02013-06-10 23:20:58 +0000265 bool hasARM() const {
266 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
267 }
268
Evan Cheng284b4672011-07-08 22:36:29 +0000269 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000270 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
271 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000272 }
James Molloy21efa7d2011-09-28 14:21:38 +0000273 bool isMClass() const {
274 return STI.getFeatureBits() & ARM::FeatureMClass;
275 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000276
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000277 /// @name Auto-generated Match Functions
278 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000279
Chris Lattner3e4582a2010-09-06 19:11:01 +0000280#define GET_ASSEMBLER_HEADER
281#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000282
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000283 /// }
284
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000285 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000286 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000287 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000288 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000289 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000290 OperandMatchResultTy parseCoprocOptionOperand(
291 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000292 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000293 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000294 OperandMatchResultTy parseInstSyncBarrierOptOperand(
295 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000296 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000297 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000298 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000299 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000300 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
301 StringRef Op, int Low, int High);
302 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
303 return parsePKHImm(O, "lsl", 0, 31);
304 }
305 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
306 return parsePKHImm(O, "asr", 1, 32);
307 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000308 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000309 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000310 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000311 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000312 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000313 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000314 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000315 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000316 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
317 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000318
319 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000320 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000321 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000322 void cvtThumbBranches(MCInst &Inst,
323 const SmallVectorImpl<MCParsedAsmOperand*> &);
324
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000325 bool validateInstruction(MCInst &Inst,
326 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000327 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000328 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000329 bool shouldOmitCCOutOperand(StringRef Mnemonic,
330 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000331 bool shouldOmitPredicateOperand(StringRef Mnemonic,
332 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000333public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000334 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000335 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000336 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000337 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000338 Match_RequiresThumb2,
339#define GET_OPERAND_DIAGNOSTIC_TYPES
340#include "ARMGenAsmMatcher.inc"
341
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000342 };
343
Joey Gouly0e76fa72013-09-12 10:28:05 +0000344 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
345 const MCInstrInfo &MII)
346 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000347 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000348
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000349 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000350 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000351
Evan Cheng4d1ca962011-07-08 01:53:10 +0000352 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000353 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000354
355 // Not in an ITBlock to start with.
356 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000357
358 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000359 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000360
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000361 // Implementation of the MCTargetAsmParser interface:
362 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000363 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
364 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000365 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000366 bool ParseDirective(AsmToken DirectiveID);
367
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000368 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000369 unsigned checkTargetMatchPredicate(MCInst &Inst);
370
Chad Rosier49963552012-10-13 00:26:04 +0000371 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000372 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000373 MCStreamer &Out, unsigned &ErrorInfo,
374 bool MatchingInlineAsm);
Tim Northover1744d0a2013-10-25 12:49:50 +0000375 void onLabelParsed(MCSymbol *Symbol);
David Peixottoe407d092013-12-19 18:12:36 +0000376 void finishParse();
Kevin Enderbyccab3172009-09-15 00:27:25 +0000377};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000378} // end anonymous namespace
379
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000380namespace {
381
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000382/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000383/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000384class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000385 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000386 k_CondCode,
387 k_CCOut,
388 k_ITCondMask,
389 k_CoprocNum,
390 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000391 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000392 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000393 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000394 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000395 k_Memory,
396 k_PostIndexRegister,
397 k_MSRMask,
398 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000399 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000400 k_Register,
401 k_RegisterList,
402 k_DPRRegisterList,
403 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000404 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000405 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000406 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000407 k_ShiftedRegister,
408 k_ShiftedImmediate,
409 k_ShifterImmediate,
410 k_RotateImmediate,
411 k_BitfieldDescriptor,
412 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000413 } Kind;
414
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000415 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000416 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000417
Eric Christopher8996c5d2013-03-15 00:42:55 +0000418 struct CCOp {
419 ARMCC::CondCodes Val;
420 };
421
422 struct CopOp {
423 unsigned Val;
424 };
425
426 struct CoprocOptionOp {
427 unsigned Val;
428 };
429
430 struct ITMaskOp {
431 unsigned Mask:4;
432 };
433
434 struct MBOptOp {
435 ARM_MB::MemBOpt Val;
436 };
437
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000438 struct ISBOptOp {
439 ARM_ISB::InstSyncBOpt Val;
440 };
441
Eric Christopher8996c5d2013-03-15 00:42:55 +0000442 struct IFlagsOp {
443 ARM_PROC::IFlags Val;
444 };
445
446 struct MMaskOp {
447 unsigned Val;
448 };
449
450 struct TokOp {
451 const char *Data;
452 unsigned Length;
453 };
454
455 struct RegOp {
456 unsigned RegNum;
457 };
458
459 // A vector register list is a sequential list of 1 to 4 registers.
460 struct VectorListOp {
461 unsigned RegNum;
462 unsigned Count;
463 unsigned LaneIndex;
464 bool isDoubleSpaced;
465 };
466
467 struct VectorIndexOp {
468 unsigned Val;
469 };
470
471 struct ImmOp {
472 const MCExpr *Val;
473 };
474
475 /// Combined record for all forms of ARM address expressions.
476 struct MemoryOp {
477 unsigned BaseRegNum;
478 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
479 // was specified.
480 const MCConstantExpr *OffsetImm; // Offset immediate value
481 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
482 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
483 unsigned ShiftImm; // shift for OffsetReg.
484 unsigned Alignment; // 0 = no alignment specified
485 // n = alignment in bytes (2, 4, 8, 16, or 32)
486 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
487 };
488
489 struct PostIdxRegOp {
490 unsigned RegNum;
491 bool isAdd;
492 ARM_AM::ShiftOpc ShiftTy;
493 unsigned ShiftImm;
494 };
495
496 struct ShifterImmOp {
497 bool isASR;
498 unsigned Imm;
499 };
500
501 struct RegShiftedRegOp {
502 ARM_AM::ShiftOpc ShiftTy;
503 unsigned SrcReg;
504 unsigned ShiftReg;
505 unsigned ShiftImm;
506 };
507
508 struct RegShiftedImmOp {
509 ARM_AM::ShiftOpc ShiftTy;
510 unsigned SrcReg;
511 unsigned ShiftImm;
512 };
513
514 struct RotImmOp {
515 unsigned Imm;
516 };
517
518 struct BitfieldOp {
519 unsigned LSB;
520 unsigned Width;
521 };
522
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000523 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000524 struct CCOp CC;
525 struct CopOp Cop;
526 struct CoprocOptionOp CoprocOption;
527 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000528 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000529 struct ITMaskOp ITMask;
530 struct IFlagsOp IFlags;
531 struct MMaskOp MMask;
532 struct TokOp Tok;
533 struct RegOp Reg;
534 struct VectorListOp VectorList;
535 struct VectorIndexOp VectorIndex;
536 struct ImmOp Imm;
537 struct MemoryOp Memory;
538 struct PostIdxRegOp PostIdxReg;
539 struct ShifterImmOp ShifterImm;
540 struct RegShiftedRegOp RegShiftedReg;
541 struct RegShiftedImmOp RegShiftedImm;
542 struct RotImmOp RotImm;
543 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000544 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000545
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000546 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
547public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000548 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
549 Kind = o.Kind;
550 StartLoc = o.StartLoc;
551 EndLoc = o.EndLoc;
552 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000553 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000554 CC = o.CC;
555 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000556 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000557 ITMask = o.ITMask;
558 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000559 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000560 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000561 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000562 case k_CCOut:
563 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000564 Reg = o.Reg;
565 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000566 case k_RegisterList:
567 case k_DPRRegisterList:
568 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000569 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000570 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000571 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000572 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000573 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000574 VectorList = o.VectorList;
575 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000576 case k_CoprocNum:
577 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000578 Cop = o.Cop;
579 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000580 case k_CoprocOption:
581 CoprocOption = o.CoprocOption;
582 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000583 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000584 Imm = o.Imm;
585 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000586 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000587 MBOpt = o.MBOpt;
588 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000589 case k_InstSyncBarrierOpt:
590 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000591 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000592 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000593 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000594 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000595 PostIdxReg = o.PostIdxReg;
596 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000597 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000598 MMask = o.MMask;
599 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000600 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000601 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000602 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000603 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000604 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000605 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000606 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000607 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000608 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000609 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000610 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000611 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000612 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000613 RotImm = o.RotImm;
614 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000615 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000616 Bitfield = o.Bitfield;
617 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000618 case k_VectorIndex:
619 VectorIndex = o.VectorIndex;
620 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000621 }
622 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000623
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000624 /// getStartLoc - Get the location of the first token of this operand.
625 SMLoc getStartLoc() const { return StartLoc; }
626 /// getEndLoc - Get the location of the last token of this operand.
627 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000628 /// getLocRange - Get the range between the first and last token of this
629 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000630 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
631
Daniel Dunbard8042b72010-08-11 06:36:53 +0000632 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000633 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000634 return CC.Val;
635 }
636
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000637 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000638 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000639 return Cop.Val;
640 }
641
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000642 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000643 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000644 return StringRef(Tok.Data, Tok.Length);
645 }
646
647 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000648 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000649 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000650 }
651
Bill Wendlingbed94652010-11-09 23:28:44 +0000652 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000653 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
654 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000655 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000656 }
657
Kevin Enderbyf5079942009-10-13 22:19:02 +0000658 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000659 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000660 return Imm.Val;
661 }
662
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000663 unsigned getVectorIndex() const {
664 assert(Kind == k_VectorIndex && "Invalid access!");
665 return VectorIndex.Val;
666 }
667
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000668 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000669 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000670 return MBOpt.Val;
671 }
672
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000673 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
674 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
675 return ISBOpt.Val;
676 }
677
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000678 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000679 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000680 return IFlags.Val;
681 }
682
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000683 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000684 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000685 return MMask.Val;
686 }
687
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000688 bool isCoprocNum() const { return Kind == k_CoprocNum; }
689 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000690 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000691 bool isCondCode() const { return Kind == k_CondCode; }
692 bool isCCOut() const { return Kind == k_CCOut; }
693 bool isITMask() const { return Kind == k_ITCondMask; }
694 bool isITCondCode() const { return Kind == k_CondCode; }
695 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000696 // checks whether this operand is an unsigned offset which fits is a field
697 // of specified width and scaled by a specific number of bits
698 template<unsigned width, unsigned scale>
699 bool isUnsignedOffset() const {
700 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000701 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000702 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
703 int64_t Val = CE->getValue();
704 int64_t Align = 1LL << scale;
705 int64_t Max = Align * ((1LL << width) - 1);
706 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
707 }
708 return false;
709 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000710 // checks whether this operand is an signed offset which fits is a field
711 // of specified width and scaled by a specific number of bits
712 template<unsigned width, unsigned scale>
713 bool isSignedOffset() const {
714 if (!isImm()) return false;
715 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
716 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
717 int64_t Val = CE->getValue();
718 int64_t Align = 1LL << scale;
719 int64_t Max = Align * ((1LL << (width-1)) - 1);
720 int64_t Min = -Align * (1LL << (width-1));
721 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
722 }
723 return false;
724 }
725
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000726 // checks whether this operand is a memory operand computed as an offset
727 // applied to PC. the offset may have 8 bits of magnitude and is represented
728 // with two bits of shift. textually it may be either [pc, #imm], #imm or
729 // relocable expression...
730 bool isThumbMemPC() const {
731 int64_t Val = 0;
732 if (isImm()) {
733 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
735 if (!CE) return false;
736 Val = CE->getValue();
737 }
738 else if (isMem()) {
739 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
740 if(Memory.BaseRegNum != ARM::PC) return false;
741 Val = Memory.OffsetImm->getValue();
742 }
743 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000744 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000745 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000746 bool isFPImm() const {
747 if (!isImm()) return false;
748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
749 if (!CE) return false;
750 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
751 return Val != -1;
752 }
Jim Grosbachea231912011-12-22 22:19:05 +0000753 bool isFBits16() const {
754 if (!isImm()) return false;
755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
756 if (!CE) return false;
757 int64_t Value = CE->getValue();
758 return Value >= 0 && Value <= 16;
759 }
760 bool isFBits32() const {
761 if (!isImm()) return false;
762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
763 if (!CE) return false;
764 int64_t Value = CE->getValue();
765 return Value >= 1 && Value <= 32;
766 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000767 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000768 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
770 if (!CE) return false;
771 int64_t Value = CE->getValue();
772 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
773 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000774 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000775 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
777 if (!CE) return false;
778 int64_t Value = CE->getValue();
779 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
780 }
781 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000782 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
784 if (!CE) return false;
785 int64_t Value = CE->getValue();
786 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
787 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000788 bool isImm0_508s4Neg() const {
789 if (!isImm()) return false;
790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
791 if (!CE) return false;
792 int64_t Value = -CE->getValue();
793 // explicitly exclude zero. we want that to use the normal 0_508 version.
794 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
795 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000796 bool isImm0_239() const {
797 if (!isImm()) return false;
798 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
799 if (!CE) return false;
800 int64_t Value = CE->getValue();
801 return Value >= 0 && Value < 240;
802 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000803 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000804 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000805 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
806 if (!CE) return false;
807 int64_t Value = CE->getValue();
808 return Value >= 0 && Value < 256;
809 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000810 bool isImm0_4095() const {
811 if (!isImm()) return false;
812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
813 if (!CE) return false;
814 int64_t Value = CE->getValue();
815 return Value >= 0 && Value < 4096;
816 }
817 bool isImm0_4095Neg() const {
818 if (!isImm()) return false;
819 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
820 if (!CE) return false;
821 int64_t Value = -CE->getValue();
822 return Value > 0 && Value < 4096;
823 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000824 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000825 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000826 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
827 if (!CE) return false;
828 int64_t Value = CE->getValue();
829 return Value >= 0 && Value < 2;
830 }
831 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000832 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
834 if (!CE) return false;
835 int64_t Value = CE->getValue();
836 return Value >= 0 && Value < 4;
837 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000838 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000839 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000840 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
841 if (!CE) return false;
842 int64_t Value = CE->getValue();
843 return Value >= 0 && Value < 8;
844 }
845 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000846 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000847 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
848 if (!CE) return false;
849 int64_t Value = CE->getValue();
850 return Value >= 0 && Value < 16;
851 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000852 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000853 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000854 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
855 if (!CE) return false;
856 int64_t Value = CE->getValue();
857 return Value >= 0 && Value < 32;
858 }
Jim Grosbach00326402011-12-08 01:30:04 +0000859 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000860 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000861 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
862 if (!CE) return false;
863 int64_t Value = CE->getValue();
864 return Value >= 0 && Value < 64;
865 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000866 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000867 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000868 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
869 if (!CE) return false;
870 int64_t Value = CE->getValue();
871 return Value == 8;
872 }
873 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000874 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
876 if (!CE) return false;
877 int64_t Value = CE->getValue();
878 return Value == 16;
879 }
880 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000881 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
883 if (!CE) return false;
884 int64_t Value = CE->getValue();
885 return Value == 32;
886 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000887 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000888 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
890 if (!CE) return false;
891 int64_t Value = CE->getValue();
892 return Value > 0 && Value <= 8;
893 }
894 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000895 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000896 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
897 if (!CE) return false;
898 int64_t Value = CE->getValue();
899 return Value > 0 && Value <= 16;
900 }
901 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000902 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000903 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
904 if (!CE) return false;
905 int64_t Value = CE->getValue();
906 return Value > 0 && Value <= 32;
907 }
908 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000909 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000910 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
911 if (!CE) return false;
912 int64_t Value = CE->getValue();
913 return Value > 0 && Value <= 64;
914 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000915 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000916 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
918 if (!CE) return false;
919 int64_t Value = CE->getValue();
920 return Value > 0 && Value < 8;
921 }
922 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000923 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000924 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
925 if (!CE) return false;
926 int64_t Value = CE->getValue();
927 return Value > 0 && Value < 16;
928 }
929 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000930 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000931 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
932 if (!CE) return false;
933 int64_t Value = CE->getValue();
934 return Value > 0 && Value < 32;
935 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000936 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000937 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000938 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
939 if (!CE) return false;
940 int64_t Value = CE->getValue();
941 return Value > 0 && Value < 17;
942 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000943 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000944 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000945 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
946 if (!CE) return false;
947 int64_t Value = CE->getValue();
948 return Value > 0 && Value < 33;
949 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000950 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000951 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000952 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
953 if (!CE) return false;
954 int64_t Value = CE->getValue();
955 return Value >= 0 && Value < 33;
956 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000957 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000958 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000959 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
960 if (!CE) return false;
961 int64_t Value = CE->getValue();
962 return Value >= 0 && Value < 65536;
963 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000964 bool isImm256_65535Expr() const {
965 if (!isImm()) return false;
966 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
967 // If it's not a constant expression, it'll generate a fixup and be
968 // handled later.
969 if (!CE) return true;
970 int64_t Value = CE->getValue();
971 return Value >= 256 && Value < 65536;
972 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000973 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000974 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000975 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
976 // If it's not a constant expression, it'll generate a fixup and be
977 // handled later.
978 if (!CE) return true;
979 int64_t Value = CE->getValue();
980 return Value >= 0 && Value < 65536;
981 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000982 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000983 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000984 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
985 if (!CE) return false;
986 int64_t Value = CE->getValue();
987 return Value >= 0 && Value <= 0xffffff;
988 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000989 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000990 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000991 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
992 if (!CE) return false;
993 int64_t Value = CE->getValue();
994 return Value > 0 && Value < 33;
995 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000996 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000997 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
999 if (!CE) return false;
1000 int64_t Value = CE->getValue();
1001 return Value >= 0 && Value < 32;
1002 }
1003 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001004 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001005 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1006 if (!CE) return false;
1007 int64_t Value = CE->getValue();
1008 return Value > 0 && Value <= 32;
1009 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001010 bool isAdrLabel() const {
1011 // If we have an immediate that's not a constant, treat it as a label
1012 // reference needing a fixup. If it is a constant, but it can't fit
1013 // into shift immediate encoding, we reject it.
1014 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1015 else return (isARMSOImm() || isARMSOImmNeg());
1016 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001017 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001018 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001019 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1020 if (!CE) return false;
1021 int64_t Value = CE->getValue();
1022 return ARM_AM::getSOImmVal(Value) != -1;
1023 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001024 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001025 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001026 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1027 if (!CE) return false;
1028 int64_t Value = CE->getValue();
1029 return ARM_AM::getSOImmVal(~Value) != -1;
1030 }
Jim Grosbach30506252011-12-08 00:31:07 +00001031 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001032 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001033 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1034 if (!CE) return false;
1035 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001036 // Only use this when not representable as a plain so_imm.
1037 return ARM_AM::getSOImmVal(Value) == -1 &&
1038 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001039 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001040 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001041 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001042 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1043 if (!CE) return false;
1044 int64_t Value = CE->getValue();
1045 return ARM_AM::getT2SOImmVal(Value) != -1;
1046 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001047 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001048 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001049 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1050 if (!CE) return false;
1051 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001052 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1053 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001054 }
Jim Grosbach30506252011-12-08 00:31:07 +00001055 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001056 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001057 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1058 if (!CE) return false;
1059 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001060 // Only use this when not representable as a plain so_imm.
1061 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1062 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001063 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001064 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001065 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001066 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1067 if (!CE) return false;
1068 int64_t Value = CE->getValue();
1069 return Value == 1 || Value == 0;
1070 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001071 bool isReg() const { return Kind == k_Register; }
1072 bool isRegList() const { return Kind == k_RegisterList; }
1073 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1074 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1075 bool isToken() const { return Kind == k_Token; }
1076 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001077 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +00001078 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001079 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1080 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1081 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1082 bool isRotImm() const { return Kind == k_RotateImmediate; }
1083 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1084 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001085 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001086 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001087 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001088 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +00001089 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001090 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001091 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +00001092 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1093 (alignOK || Memory.Alignment == 0);
1094 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001095 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001096 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001097 return false;
1098 // Base register must be PC.
1099 if (Memory.BaseRegNum != ARM::PC)
1100 return false;
1101 // Immediate offset in range [-4095, 4095].
1102 if (!Memory.OffsetImm) return true;
1103 int64_t Val = Memory.OffsetImm->getValue();
1104 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1105 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001106 bool isAlignedMemory() const {
1107 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001108 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001109 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001110 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001111 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001112 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001113 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001114 if (!Memory.OffsetImm) return true;
1115 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001116 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001117 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001118 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001119 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001120 // Immediate offset in range [-4095, 4095].
1121 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1122 if (!CE) return false;
1123 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001124 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001125 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001126 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001127 // If we have an immediate that's not a constant, treat it as a label
1128 // reference needing a fixup. If it is a constant, it's something else
1129 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001130 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001131 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001132 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001133 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001134 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001135 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001136 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001137 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001138 if (!Memory.OffsetImm) return true;
1139 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001140 // The #-0 offset is encoded as INT32_MIN, and we have to check
1141 // for this too.
1142 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001143 }
1144 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001145 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001146 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001147 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001148 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1149 // Immediate offset in range [-255, 255].
1150 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1151 if (!CE) return false;
1152 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001153 // Special case, #-0 is INT32_MIN.
1154 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001155 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001156 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001157 // If we have an immediate that's not a constant, treat it as a label
1158 // reference needing a fixup. If it is a constant, it's something else
1159 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001160 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001161 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001162 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001163 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001164 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001165 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001166 if (!Memory.OffsetImm) return true;
1167 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001168 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001169 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001170 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001171 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001172 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001173 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001174 return false;
1175 return true;
1176 }
1177 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001178 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001179 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1180 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001181 return false;
1182 return true;
1183 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001184 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001185 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001186 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001187 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001188 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001189 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001190 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001191 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001192 return false;
1193 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001194 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001195 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001196 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001197 return false;
1198 return true;
1199 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001200 bool isMemThumbRR() const {
1201 // Thumb reg+reg addressing is simple. Just two registers, a base and
1202 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001203 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001204 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001205 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001206 return isARMLowRegister(Memory.BaseRegNum) &&
1207 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001208 }
1209 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001210 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001211 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001212 return false;
1213 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001214 if (!Memory.OffsetImm) return true;
1215 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001216 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1217 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001218 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001219 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001220 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001221 return false;
1222 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001223 if (!Memory.OffsetImm) return true;
1224 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001225 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1226 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001227 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001228 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001229 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001230 return false;
1231 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001232 if (!Memory.OffsetImm) return true;
1233 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001234 return Val >= 0 && Val <= 31;
1235 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001236 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001237 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001238 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001239 return false;
1240 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001241 if (!Memory.OffsetImm) return true;
1242 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001243 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001244 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001245 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001246 // If we have an immediate that's not a constant, treat it as a label
1247 // reference needing a fixup. If it is a constant, it's something else
1248 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001249 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001250 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001251 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001252 return false;
1253 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001254 if (!Memory.OffsetImm) return true;
1255 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001256 // Special case, #-0 is INT32_MIN.
1257 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001258 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001259 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001260 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001261 return false;
1262 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001263 if (!Memory.OffsetImm) return true;
1264 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001265 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1266 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001267 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001268 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001269 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001270 // Base reg of PC isn't allowed for these encodings.
1271 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001272 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001273 if (!Memory.OffsetImm) return true;
1274 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001275 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001276 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001277 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001278 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001279 return false;
1280 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001281 if (!Memory.OffsetImm) return true;
1282 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001283 return Val >= 0 && Val < 256;
1284 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001285 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001286 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001287 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001288 // Base reg of PC isn't allowed for these encodings.
1289 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001290 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001291 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001292 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001293 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001294 }
1295 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001296 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001297 return false;
1298 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001299 if (!Memory.OffsetImm) return true;
1300 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001301 return (Val >= 0 && Val < 4096);
1302 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001303 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001304 // If we have an immediate that's not a constant, treat it as a label
1305 // reference needing a fixup. If it is a constant, it's something else
1306 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001307 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001308 return true;
1309
Chad Rosier41099832012-09-11 23:02:35 +00001310 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001311 return false;
1312 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001313 if (!Memory.OffsetImm) return true;
1314 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001315 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001316 }
1317 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001318 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001319 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1320 if (!CE) return false;
1321 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001322 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001323 }
Jim Grosbach93981412011-10-11 21:55:36 +00001324 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001325 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001326 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1327 if (!CE) return false;
1328 int64_t Val = CE->getValue();
1329 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1330 (Val == INT32_MIN);
1331 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001332
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001333 bool isMSRMask() const { return Kind == k_MSRMask; }
1334 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001335
Jim Grosbach741cd732011-10-17 22:26:03 +00001336 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001337 bool isSingleSpacedVectorList() const {
1338 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1339 }
1340 bool isDoubleSpacedVectorList() const {
1341 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1342 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001343 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001344 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001345 return VectorList.Count == 1;
1346 }
1347
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001348 bool isVecListDPair() const {
1349 if (!isSingleSpacedVectorList()) return false;
1350 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1351 .contains(VectorList.RegNum));
1352 }
1353
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001354 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001355 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001356 return VectorList.Count == 3;
1357 }
1358
Jim Grosbach846bcff2011-10-21 20:35:01 +00001359 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001360 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001361 return VectorList.Count == 4;
1362 }
1363
Jim Grosbache5307f92012-03-05 21:43:40 +00001364 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001365 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001366 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1367 .contains(VectorList.RegNum));
1368 }
1369
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001370 bool isVecListThreeQ() const {
1371 if (!isDoubleSpacedVectorList()) return false;
1372 return VectorList.Count == 3;
1373 }
1374
Jim Grosbach1e946a42012-01-24 00:43:12 +00001375 bool isVecListFourQ() const {
1376 if (!isDoubleSpacedVectorList()) return false;
1377 return VectorList.Count == 4;
1378 }
1379
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001380 bool isSingleSpacedVectorAllLanes() const {
1381 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1382 }
1383 bool isDoubleSpacedVectorAllLanes() const {
1384 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1385 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001386 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001387 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001388 return VectorList.Count == 1;
1389 }
1390
Jim Grosbach13a292c2012-03-06 22:01:44 +00001391 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001392 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001393 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1394 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001395 }
1396
Jim Grosbached428bc2012-03-06 23:10:38 +00001397 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001398 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001399 return VectorList.Count == 2;
1400 }
1401
Jim Grosbachb78403c2012-01-24 23:47:04 +00001402 bool isVecListThreeDAllLanes() const {
1403 if (!isSingleSpacedVectorAllLanes()) return false;
1404 return VectorList.Count == 3;
1405 }
1406
1407 bool isVecListThreeQAllLanes() const {
1408 if (!isDoubleSpacedVectorAllLanes()) return false;
1409 return VectorList.Count == 3;
1410 }
1411
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001412 bool isVecListFourDAllLanes() const {
1413 if (!isSingleSpacedVectorAllLanes()) return false;
1414 return VectorList.Count == 4;
1415 }
1416
1417 bool isVecListFourQAllLanes() const {
1418 if (!isDoubleSpacedVectorAllLanes()) return false;
1419 return VectorList.Count == 4;
1420 }
1421
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001422 bool isSingleSpacedVectorIndexed() const {
1423 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1424 }
1425 bool isDoubleSpacedVectorIndexed() const {
1426 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1427 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001428 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001429 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001430 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1431 }
1432
Jim Grosbachda511042011-12-14 23:35:06 +00001433 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001434 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001435 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1436 }
1437
1438 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001439 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001440 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1441 }
1442
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001443 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001444 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001445 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1446 }
1447
Jim Grosbachda511042011-12-14 23:35:06 +00001448 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001449 if (!isSingleSpacedVectorIndexed()) return false;
1450 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1451 }
1452
1453 bool isVecListTwoQWordIndexed() const {
1454 if (!isDoubleSpacedVectorIndexed()) return false;
1455 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1456 }
1457
1458 bool isVecListTwoQHWordIndexed() const {
1459 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001460 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1461 }
1462
1463 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001464 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001465 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1466 }
1467
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001468 bool isVecListThreeDByteIndexed() const {
1469 if (!isSingleSpacedVectorIndexed()) return false;
1470 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1471 }
1472
1473 bool isVecListThreeDHWordIndexed() const {
1474 if (!isSingleSpacedVectorIndexed()) return false;
1475 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1476 }
1477
1478 bool isVecListThreeQWordIndexed() const {
1479 if (!isDoubleSpacedVectorIndexed()) return false;
1480 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1481 }
1482
1483 bool isVecListThreeQHWordIndexed() const {
1484 if (!isDoubleSpacedVectorIndexed()) return false;
1485 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1486 }
1487
1488 bool isVecListThreeDWordIndexed() const {
1489 if (!isSingleSpacedVectorIndexed()) return false;
1490 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1491 }
1492
Jim Grosbach14952a02012-01-24 18:37:25 +00001493 bool isVecListFourDByteIndexed() const {
1494 if (!isSingleSpacedVectorIndexed()) return false;
1495 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1496 }
1497
1498 bool isVecListFourDHWordIndexed() const {
1499 if (!isSingleSpacedVectorIndexed()) return false;
1500 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1501 }
1502
1503 bool isVecListFourQWordIndexed() const {
1504 if (!isDoubleSpacedVectorIndexed()) return false;
1505 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1506 }
1507
1508 bool isVecListFourQHWordIndexed() const {
1509 if (!isDoubleSpacedVectorIndexed()) return false;
1510 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1511 }
1512
1513 bool isVecListFourDWordIndexed() const {
1514 if (!isSingleSpacedVectorIndexed()) return false;
1515 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1516 }
1517
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001518 bool isVectorIndex8() const {
1519 if (Kind != k_VectorIndex) return false;
1520 return VectorIndex.Val < 8;
1521 }
1522 bool isVectorIndex16() const {
1523 if (Kind != k_VectorIndex) return false;
1524 return VectorIndex.Val < 4;
1525 }
1526 bool isVectorIndex32() const {
1527 if (Kind != k_VectorIndex) return false;
1528 return VectorIndex.Val < 2;
1529 }
1530
Jim Grosbach741cd732011-10-17 22:26:03 +00001531 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001532 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001533 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1534 // Must be a constant.
1535 if (!CE) return false;
1536 int64_t Value = CE->getValue();
1537 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1538 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001539 return Value >= 0 && Value < 256;
1540 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001541
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001542 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001543 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001544 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1545 // Must be a constant.
1546 if (!CE) return false;
1547 int64_t Value = CE->getValue();
1548 // i16 value in the range [0,255] or [0x0100, 0xff00]
1549 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1550 }
1551
Jim Grosbach8211c052011-10-18 00:22:00 +00001552 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001553 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001554 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1555 // Must be a constant.
1556 if (!CE) return false;
1557 int64_t Value = CE->getValue();
1558 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1559 return (Value >= 0 && Value < 256) ||
1560 (Value >= 0x0100 && Value <= 0xff00) ||
1561 (Value >= 0x010000 && Value <= 0xff0000) ||
1562 (Value >= 0x01000000 && Value <= 0xff000000);
1563 }
1564
1565 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001566 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001567 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1568 // Must be a constant.
1569 if (!CE) return false;
1570 int64_t Value = CE->getValue();
1571 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1572 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1573 return (Value >= 0 && Value < 256) ||
1574 (Value >= 0x0100 && Value <= 0xff00) ||
1575 (Value >= 0x010000 && Value <= 0xff0000) ||
1576 (Value >= 0x01000000 && Value <= 0xff000000) ||
1577 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1578 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1579 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001580 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001581 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001582 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1583 // Must be a constant.
1584 if (!CE) return false;
1585 int64_t Value = ~CE->getValue();
1586 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1587 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1588 return (Value >= 0 && Value < 256) ||
1589 (Value >= 0x0100 && Value <= 0xff00) ||
1590 (Value >= 0x010000 && Value <= 0xff0000) ||
1591 (Value >= 0x01000000 && Value <= 0xff000000) ||
1592 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1593 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1594 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001595
Jim Grosbache4454e02011-10-18 16:18:11 +00001596 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001597 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1599 // Must be a constant.
1600 if (!CE) return false;
1601 uint64_t Value = CE->getValue();
1602 // i64 value with each byte being either 0 or 0xff.
1603 for (unsigned i = 0; i < 8; ++i)
1604 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1605 return true;
1606 }
1607
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001608 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001609 // Add as immediates when possible. Null MCExpr = 0.
1610 if (Expr == 0)
1611 Inst.addOperand(MCOperand::CreateImm(0));
1612 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001613 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1614 else
1615 Inst.addOperand(MCOperand::CreateExpr(Expr));
1616 }
1617
Daniel Dunbard8042b72010-08-11 06:36:53 +00001618 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001619 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001620 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001621 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1622 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001623 }
1624
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001625 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1626 assert(N == 1 && "Invalid number of operands!");
1627 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1628 }
1629
Jim Grosbach48399582011-10-12 17:34:41 +00001630 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1631 assert(N == 1 && "Invalid number of operands!");
1632 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1633 }
1634
1635 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
1637 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1638 }
1639
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001640 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1641 assert(N == 1 && "Invalid number of operands!");
1642 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1643 }
1644
1645 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
1647 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1648 }
1649
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001650 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 Inst.addOperand(MCOperand::CreateReg(getReg()));
1653 }
1654
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001655 void addRegOperands(MCInst &Inst, unsigned N) const {
1656 assert(N == 1 && "Invalid number of operands!");
1657 Inst.addOperand(MCOperand::CreateReg(getReg()));
1658 }
1659
Jim Grosbachac798e12011-07-25 20:49:51 +00001660 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001661 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001662 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001663 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001664 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1665 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001666 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001667 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001668 }
1669
Jim Grosbachac798e12011-07-25 20:49:51 +00001670 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001671 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001672 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001673 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001674 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001675 // Shift of #32 is encoded as 0 where permitted
1676 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001677 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001678 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001679 }
1680
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001681 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001682 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001683 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1684 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001685 }
1686
Bill Wendling8d2aa032010-11-08 23:49:57 +00001687 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001688 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001689 const SmallVectorImpl<unsigned> &RegList = getRegList();
1690 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001691 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1692 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001693 }
1694
Bill Wendling9898ac92010-11-17 04:32:08 +00001695 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1696 addRegListOperands(Inst, N);
1697 }
1698
1699 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1700 addRegListOperands(Inst, N);
1701 }
1702
Jim Grosbach833b9d32011-07-27 20:15:40 +00001703 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1704 assert(N == 1 && "Invalid number of operands!");
1705 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1706 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1707 }
1708
Jim Grosbach864b6092011-07-28 21:34:26 +00001709 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1710 assert(N == 1 && "Invalid number of operands!");
1711 // Munge the lsb/width into a bitfield mask.
1712 unsigned lsb = Bitfield.LSB;
1713 unsigned width = Bitfield.Width;
1714 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1715 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1716 (32 - (lsb + width)));
1717 Inst.addOperand(MCOperand::CreateImm(Mask));
1718 }
1719
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001720 void addImmOperands(MCInst &Inst, unsigned N) const {
1721 assert(N == 1 && "Invalid number of operands!");
1722 addExpr(Inst, getImm());
1723 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001724
Jim Grosbachea231912011-12-22 22:19:05 +00001725 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1726 assert(N == 1 && "Invalid number of operands!");
1727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1728 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1729 }
1730
1731 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1732 assert(N == 1 && "Invalid number of operands!");
1733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1734 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1735 }
1736
Jim Grosbache7fbce72011-10-03 23:38:36 +00001737 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1738 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1740 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1741 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001742 }
1743
Jim Grosbach7db8d692011-09-08 22:07:06 +00001744 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1745 assert(N == 1 && "Invalid number of operands!");
1746 // FIXME: We really want to scale the value here, but the LDRD/STRD
1747 // instruction don't encode operands that way yet.
1748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1749 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1750 }
1751
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001752 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1753 assert(N == 1 && "Invalid number of operands!");
1754 // The immediate is scaled by four in the encoding and is stored
1755 // in the MCInst as such. Lop off the low two bits here.
1756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1757 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1758 }
1759
Jim Grosbach930f2f62012-04-05 20:57:13 +00001760 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1761 assert(N == 1 && "Invalid number of operands!");
1762 // The immediate is scaled by four in the encoding and is stored
1763 // in the MCInst as such. Lop off the low two bits here.
1764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1765 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1766 }
1767
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001768 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1769 assert(N == 1 && "Invalid number of operands!");
1770 // The immediate is scaled by four in the encoding and is stored
1771 // in the MCInst as such. Lop off the low two bits here.
1772 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1773 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1774 }
1775
Jim Grosbach475c6db2011-07-25 23:09:14 +00001776 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1777 assert(N == 1 && "Invalid number of operands!");
1778 // The constant encodes as the immediate-1, and we store in the instruction
1779 // the bits as encoded, so subtract off one here.
1780 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1781 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1782 }
1783
Jim Grosbach801e0a32011-07-22 23:16:18 +00001784 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1785 assert(N == 1 && "Invalid number of operands!");
1786 // The constant encodes as the immediate-1, and we store in the instruction
1787 // the bits as encoded, so subtract off one here.
1788 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1789 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1790 }
1791
Jim Grosbach46dd4132011-08-17 21:51:27 +00001792 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1793 assert(N == 1 && "Invalid number of operands!");
1794 // The constant encodes as the immediate, except for 32, which encodes as
1795 // zero.
1796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1797 unsigned Imm = CE->getValue();
1798 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1799 }
1800
Jim Grosbach27c1e252011-07-21 17:23:04 +00001801 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1802 assert(N == 1 && "Invalid number of operands!");
1803 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1804 // the instruction as well.
1805 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1806 int Val = CE->getValue();
1807 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1808 }
1809
Jim Grosbachb009a872011-10-28 22:36:30 +00001810 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1811 assert(N == 1 && "Invalid number of operands!");
1812 // The operand is actually a t2_so_imm, but we have its bitwise
1813 // negation in the assembly source, so twiddle it here.
1814 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1815 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1816 }
1817
Jim Grosbach30506252011-12-08 00:31:07 +00001818 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1819 assert(N == 1 && "Invalid number of operands!");
1820 // The operand is actually a t2_so_imm, but we have its
1821 // negation in the assembly source, so twiddle it here.
1822 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1823 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1824 }
1825
Jim Grosbach930f2f62012-04-05 20:57:13 +00001826 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1827 assert(N == 1 && "Invalid number of operands!");
1828 // The operand is actually an imm0_4095, but we have its
1829 // negation in the assembly source, so twiddle it here.
1830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1831 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1832 }
1833
Mihai Popad36cbaa2013-07-03 09:21:44 +00001834 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1835 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1836 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1837 return;
1838 }
1839
1840 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1841 assert(SR && "Unknown value type!");
1842 Inst.addOperand(MCOperand::CreateExpr(SR));
1843 }
1844
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001845 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1846 assert(N == 1 && "Invalid number of operands!");
1847 if (isImm()) {
1848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1849 if (CE) {
1850 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1851 return;
1852 }
1853
1854 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1855 assert(SR && "Unknown value type!");
1856 Inst.addOperand(MCOperand::CreateExpr(SR));
1857 return;
1858 }
1859
1860 assert(isMem() && "Unknown value type!");
1861 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1862 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1863 }
1864
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001865 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1866 assert(N == 1 && "Invalid number of operands!");
1867 // The operand is actually a so_imm, but we have its bitwise
1868 // negation in the assembly source, so twiddle it here.
1869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1870 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1871 }
1872
Jim Grosbach30506252011-12-08 00:31:07 +00001873 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1874 assert(N == 1 && "Invalid number of operands!");
1875 // The operand is actually a so_imm, but we have its
1876 // negation in the assembly source, so twiddle it here.
1877 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1878 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1879 }
1880
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001881 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1882 assert(N == 1 && "Invalid number of operands!");
1883 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1884 }
1885
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001886 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1887 assert(N == 1 && "Invalid number of operands!");
1888 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1889 }
1890
Jim Grosbachd3595712011-08-03 23:50:40 +00001891 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1892 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001893 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001894 }
1895
Jim Grosbach94298a92012-01-18 22:46:46 +00001896 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1897 assert(N == 1 && "Invalid number of operands!");
1898 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001899 Inst.addOperand(MCOperand::CreateImm(Imm));
1900 }
1901
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001902 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1903 assert(N == 1 && "Invalid number of operands!");
1904 assert(isImm() && "Not an immediate!");
1905
1906 // If we have an immediate that's not a constant, treat it as a label
1907 // reference needing a fixup.
1908 if (!isa<MCConstantExpr>(getImm())) {
1909 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1910 return;
1911 }
1912
1913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1914 int Val = CE->getValue();
1915 Inst.addOperand(MCOperand::CreateImm(Val));
1916 }
1917
Jim Grosbacha95ec992011-10-11 17:29:55 +00001918 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1919 assert(N == 2 && "Invalid number of operands!");
1920 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1921 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1922 }
1923
Jim Grosbachd3595712011-08-03 23:50:40 +00001924 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1925 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001926 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1927 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001928 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1929 // Special case for #-0
1930 if (Val == INT32_MIN) Val = 0;
1931 if (Val < 0) Val = -Val;
1932 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1933 } else {
1934 // For register offset, we encode the shift type and negation flag
1935 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001936 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1937 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001938 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001939 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1940 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001941 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001942 }
1943
Jim Grosbachcd17c122011-08-04 23:01:30 +00001944 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1945 assert(N == 2 && "Invalid number of operands!");
1946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1947 assert(CE && "non-constant AM2OffsetImm operand!");
1948 int32_t Val = CE->getValue();
1949 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1950 // Special case for #-0
1951 if (Val == INT32_MIN) Val = 0;
1952 if (Val < 0) Val = -Val;
1953 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1954 Inst.addOperand(MCOperand::CreateReg(0));
1955 Inst.addOperand(MCOperand::CreateImm(Val));
1956 }
1957
Jim Grosbach5b96b802011-08-10 20:29:19 +00001958 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1959 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001960 // If we have an immediate that's not a constant, treat it as a label
1961 // reference needing a fixup. If it is a constant, it's something else
1962 // and we reject it.
1963 if (isImm()) {
1964 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1965 Inst.addOperand(MCOperand::CreateReg(0));
1966 Inst.addOperand(MCOperand::CreateImm(0));
1967 return;
1968 }
1969
Jim Grosbach871dff72011-10-11 15:59:20 +00001970 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1971 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001972 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1973 // Special case for #-0
1974 if (Val == INT32_MIN) Val = 0;
1975 if (Val < 0) Val = -Val;
1976 Val = ARM_AM::getAM3Opc(AddSub, Val);
1977 } else {
1978 // For register offset, we encode the shift type and negation flag
1979 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001980 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001981 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001982 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1983 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001984 Inst.addOperand(MCOperand::CreateImm(Val));
1985 }
1986
1987 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1988 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001989 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001990 int32_t Val =
1991 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1992 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1993 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001994 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001995 }
1996
1997 // Constant offset.
1998 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1999 int32_t Val = CE->getValue();
2000 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2001 // Special case for #-0
2002 if (Val == INT32_MIN) Val = 0;
2003 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002004 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002005 Inst.addOperand(MCOperand::CreateReg(0));
2006 Inst.addOperand(MCOperand::CreateImm(Val));
2007 }
2008
Jim Grosbachd3595712011-08-03 23:50:40 +00002009 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2010 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002011 // If we have an immediate that's not a constant, treat it as a label
2012 // reference needing a fixup. If it is a constant, it's something else
2013 // and we reject it.
2014 if (isImm()) {
2015 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2016 Inst.addOperand(MCOperand::CreateImm(0));
2017 return;
2018 }
2019
Jim Grosbachd3595712011-08-03 23:50:40 +00002020 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002021 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002022 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2023 // Special case for #-0
2024 if (Val == INT32_MIN) Val = 0;
2025 if (Val < 0) Val = -Val;
2026 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002027 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002028 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002029 }
2030
Jim Grosbach7db8d692011-09-08 22:07:06 +00002031 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2032 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002033 // If we have an immediate that's not a constant, treat it as a label
2034 // reference needing a fixup. If it is a constant, it's something else
2035 // and we reject it.
2036 if (isImm()) {
2037 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2038 Inst.addOperand(MCOperand::CreateImm(0));
2039 return;
2040 }
2041
Jim Grosbach871dff72011-10-11 15:59:20 +00002042 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2043 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002044 Inst.addOperand(MCOperand::CreateImm(Val));
2045 }
2046
Jim Grosbacha05627e2011-09-09 18:37:27 +00002047 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2048 assert(N == 2 && "Invalid number of operands!");
2049 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002050 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2051 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002052 Inst.addOperand(MCOperand::CreateImm(Val));
2053 }
2054
Jim Grosbachd3595712011-08-03 23:50:40 +00002055 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2056 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002057 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2058 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002059 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002060 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002061
Jim Grosbach2392c532011-09-07 23:39:14 +00002062 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2063 addMemImm8OffsetOperands(Inst, N);
2064 }
2065
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002066 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002067 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002068 }
2069
2070 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2071 assert(N == 2 && "Invalid number of operands!");
2072 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002073 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002074 addExpr(Inst, getImm());
2075 Inst.addOperand(MCOperand::CreateImm(0));
2076 return;
2077 }
2078
2079 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002080 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2081 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002082 Inst.addOperand(MCOperand::CreateImm(Val));
2083 }
2084
Jim Grosbachd3595712011-08-03 23:50:40 +00002085 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2086 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002087 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002088 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002089 addExpr(Inst, getImm());
2090 Inst.addOperand(MCOperand::CreateImm(0));
2091 return;
2092 }
2093
2094 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002095 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2096 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002097 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002098 }
Bill Wendling811c9362010-11-30 07:44:32 +00002099
Jim Grosbach05541f42011-09-19 22:21:13 +00002100 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2101 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002102 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2103 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002104 }
2105
2106 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2107 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002108 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2109 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002110 }
2111
Jim Grosbachd3595712011-08-03 23:50:40 +00002112 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2113 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002114 unsigned Val =
2115 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2116 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002117 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2118 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002119 Inst.addOperand(MCOperand::CreateImm(Val));
2120 }
2121
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002122 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2123 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002124 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2125 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2126 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002127 }
2128
Jim Grosbachd3595712011-08-03 23:50:40 +00002129 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2130 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002131 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2132 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002133 }
2134
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002135 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2136 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002137 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2138 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002139 Inst.addOperand(MCOperand::CreateImm(Val));
2140 }
2141
Jim Grosbach26d35872011-08-19 18:55:51 +00002142 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2143 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002144 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2145 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002146 Inst.addOperand(MCOperand::CreateImm(Val));
2147 }
2148
Jim Grosbacha32c7532011-08-19 18:49:59 +00002149 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2150 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002151 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2152 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002153 Inst.addOperand(MCOperand::CreateImm(Val));
2154 }
2155
Jim Grosbach23983d62011-08-19 18:13:48 +00002156 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2157 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002158 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2159 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002160 Inst.addOperand(MCOperand::CreateImm(Val));
2161 }
2162
Jim Grosbachd3595712011-08-03 23:50:40 +00002163 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2164 assert(N == 1 && "Invalid number of operands!");
2165 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2166 assert(CE && "non-constant post-idx-imm8 operand!");
2167 int Imm = CE->getValue();
2168 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002169 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002170 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2171 Inst.addOperand(MCOperand::CreateImm(Imm));
2172 }
2173
Jim Grosbach93981412011-10-11 21:55:36 +00002174 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2175 assert(N == 1 && "Invalid number of operands!");
2176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2177 assert(CE && "non-constant post-idx-imm8s4 operand!");
2178 int Imm = CE->getValue();
2179 bool isAdd = Imm >= 0;
2180 if (Imm == INT32_MIN) Imm = 0;
2181 // Immediate is scaled by 4.
2182 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2183 Inst.addOperand(MCOperand::CreateImm(Imm));
2184 }
2185
Jim Grosbachd3595712011-08-03 23:50:40 +00002186 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2187 assert(N == 2 && "Invalid number of operands!");
2188 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002189 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2190 }
2191
2192 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2193 assert(N == 2 && "Invalid number of operands!");
2194 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2195 // The sign, shift type, and shift amount are encoded in a single operand
2196 // using the AM2 encoding helpers.
2197 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2198 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2199 PostIdxReg.ShiftTy);
2200 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002201 }
2202
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002203 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2204 assert(N == 1 && "Invalid number of operands!");
2205 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2206 }
2207
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002208 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2209 assert(N == 1 && "Invalid number of operands!");
2210 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2211 }
2212
Jim Grosbach182b6a02011-11-29 23:51:09 +00002213 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002214 assert(N == 1 && "Invalid number of operands!");
2215 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2216 }
2217
Jim Grosbach04945c42011-12-02 00:35:16 +00002218 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2219 assert(N == 2 && "Invalid number of operands!");
2220 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2221 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2222 }
2223
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002224 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2225 assert(N == 1 && "Invalid number of operands!");
2226 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2227 }
2228
2229 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2230 assert(N == 1 && "Invalid number of operands!");
2231 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2232 }
2233
2234 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2235 assert(N == 1 && "Invalid number of operands!");
2236 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2237 }
2238
Jim Grosbach741cd732011-10-17 22:26:03 +00002239 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2240 assert(N == 1 && "Invalid number of operands!");
2241 // The immediate encodes the type of constant as well as the value.
2242 // Mask in that this is an i8 splat.
2243 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2244 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2245 }
2246
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002247 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2248 assert(N == 1 && "Invalid number of operands!");
2249 // The immediate encodes the type of constant as well as the value.
2250 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2251 unsigned Value = CE->getValue();
2252 if (Value >= 256)
2253 Value = (Value >> 8) | 0xa00;
2254 else
2255 Value |= 0x800;
2256 Inst.addOperand(MCOperand::CreateImm(Value));
2257 }
2258
Jim Grosbach8211c052011-10-18 00:22:00 +00002259 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2260 assert(N == 1 && "Invalid number of operands!");
2261 // The immediate encodes the type of constant as well as the value.
2262 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2263 unsigned Value = CE->getValue();
2264 if (Value >= 256 && Value <= 0xff00)
2265 Value = (Value >> 8) | 0x200;
2266 else if (Value > 0xffff && Value <= 0xff0000)
2267 Value = (Value >> 16) | 0x400;
2268 else if (Value > 0xffffff)
2269 Value = (Value >> 24) | 0x600;
2270 Inst.addOperand(MCOperand::CreateImm(Value));
2271 }
2272
2273 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2274 assert(N == 1 && "Invalid number of operands!");
2275 // The immediate encodes the type of constant as well as the value.
2276 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2277 unsigned Value = CE->getValue();
2278 if (Value >= 256 && Value <= 0xffff)
2279 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2280 else if (Value > 0xffff && Value <= 0xffffff)
2281 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2282 else if (Value > 0xffffff)
2283 Value = (Value >> 24) | 0x600;
2284 Inst.addOperand(MCOperand::CreateImm(Value));
2285 }
2286
Jim Grosbach045b6c72011-12-19 23:51:07 +00002287 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2288 assert(N == 1 && "Invalid number of operands!");
2289 // The immediate encodes the type of constant as well as the value.
2290 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2291 unsigned Value = ~CE->getValue();
2292 if (Value >= 256 && Value <= 0xffff)
2293 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2294 else if (Value > 0xffff && Value <= 0xffffff)
2295 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2296 else if (Value > 0xffffff)
2297 Value = (Value >> 24) | 0x600;
2298 Inst.addOperand(MCOperand::CreateImm(Value));
2299 }
2300
Jim Grosbache4454e02011-10-18 16:18:11 +00002301 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2302 assert(N == 1 && "Invalid number of operands!");
2303 // The immediate encodes the type of constant as well as the value.
2304 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2305 uint64_t Value = CE->getValue();
2306 unsigned Imm = 0;
2307 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2308 Imm |= (Value & 1) << i;
2309 }
2310 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2311 }
2312
Jim Grosbach602aa902011-07-13 15:34:57 +00002313 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002314
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002315 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002316 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002317 Op->ITMask.Mask = Mask;
2318 Op->StartLoc = S;
2319 Op->EndLoc = S;
2320 return Op;
2321 }
2322
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002323 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002324 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002325 Op->CC.Val = CC;
2326 Op->StartLoc = S;
2327 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002328 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002329 }
2330
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002331 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002332 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002333 Op->Cop.Val = CopVal;
2334 Op->StartLoc = S;
2335 Op->EndLoc = S;
2336 return Op;
2337 }
2338
2339 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002340 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002341 Op->Cop.Val = CopVal;
2342 Op->StartLoc = S;
2343 Op->EndLoc = S;
2344 return Op;
2345 }
2346
Jim Grosbach48399582011-10-12 17:34:41 +00002347 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2348 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2349 Op->Cop.Val = Val;
2350 Op->StartLoc = S;
2351 Op->EndLoc = E;
2352 return Op;
2353 }
2354
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002355 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002356 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002357 Op->Reg.RegNum = RegNum;
2358 Op->StartLoc = S;
2359 Op->EndLoc = S;
2360 return Op;
2361 }
2362
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002363 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002364 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002365 Op->Tok.Data = Str.data();
2366 Op->Tok.Length = Str.size();
2367 Op->StartLoc = S;
2368 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002369 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002370 }
2371
Bill Wendling2063b842010-11-18 23:43:05 +00002372 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002373 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002374 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002375 Op->StartLoc = S;
2376 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002377 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002378 }
2379
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002380 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2381 unsigned SrcReg,
2382 unsigned ShiftReg,
2383 unsigned ShiftImm,
2384 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002385 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002386 Op->RegShiftedReg.ShiftTy = ShTy;
2387 Op->RegShiftedReg.SrcReg = SrcReg;
2388 Op->RegShiftedReg.ShiftReg = ShiftReg;
2389 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002390 Op->StartLoc = S;
2391 Op->EndLoc = E;
2392 return Op;
2393 }
2394
Owen Andersonb595ed02011-07-21 18:54:16 +00002395 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2396 unsigned SrcReg,
2397 unsigned ShiftImm,
2398 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002399 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002400 Op->RegShiftedImm.ShiftTy = ShTy;
2401 Op->RegShiftedImm.SrcReg = SrcReg;
2402 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002403 Op->StartLoc = S;
2404 Op->EndLoc = E;
2405 return Op;
2406 }
2407
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002408 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002409 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002410 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002411 Op->ShifterImm.isASR = isASR;
2412 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002413 Op->StartLoc = S;
2414 Op->EndLoc = E;
2415 return Op;
2416 }
2417
Jim Grosbach833b9d32011-07-27 20:15:40 +00002418 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002419 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002420 Op->RotImm.Imm = Imm;
2421 Op->StartLoc = S;
2422 Op->EndLoc = E;
2423 return Op;
2424 }
2425
Jim Grosbach864b6092011-07-28 21:34:26 +00002426 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2427 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002428 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002429 Op->Bitfield.LSB = LSB;
2430 Op->Bitfield.Width = Width;
2431 Op->StartLoc = S;
2432 Op->EndLoc = E;
2433 return Op;
2434 }
2435
Bill Wendling2cae3272010-11-09 22:44:22 +00002436 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002437 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002438 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002439 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002440 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002441
Chad Rosierfa705ee2013-07-01 20:49:23 +00002442 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002443 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002444 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002445 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002446 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002447
Chad Rosierfa705ee2013-07-01 20:49:23 +00002448 // Sort based on the register encoding values.
2449 array_pod_sort(Regs.begin(), Regs.end());
2450
Bill Wendling9898ac92010-11-17 04:32:08 +00002451 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002452 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002453 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002454 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002455 Op->StartLoc = StartLoc;
2456 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002457 return Op;
2458 }
2459
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002460 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002461 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002462 ARMOperand *Op = new ARMOperand(k_VectorList);
2463 Op->VectorList.RegNum = RegNum;
2464 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002465 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002466 Op->StartLoc = S;
2467 Op->EndLoc = E;
2468 return Op;
2469 }
2470
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002471 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002472 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002473 SMLoc S, SMLoc E) {
2474 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2475 Op->VectorList.RegNum = RegNum;
2476 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002477 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002478 Op->StartLoc = S;
2479 Op->EndLoc = E;
2480 return Op;
2481 }
2482
Jim Grosbach04945c42011-12-02 00:35:16 +00002483 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002484 unsigned Index,
2485 bool isDoubleSpaced,
2486 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002487 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2488 Op->VectorList.RegNum = RegNum;
2489 Op->VectorList.Count = Count;
2490 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002491 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002492 Op->StartLoc = S;
2493 Op->EndLoc = E;
2494 return Op;
2495 }
2496
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002497 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2498 MCContext &Ctx) {
2499 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2500 Op->VectorIndex.Val = Idx;
2501 Op->StartLoc = S;
2502 Op->EndLoc = E;
2503 return Op;
2504 }
2505
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002506 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002507 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002508 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002509 Op->StartLoc = S;
2510 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002511 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002512 }
2513
Jim Grosbachd3595712011-08-03 23:50:40 +00002514 static ARMOperand *CreateMem(unsigned BaseRegNum,
2515 const MCConstantExpr *OffsetImm,
2516 unsigned OffsetRegNum,
2517 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002518 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002519 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002520 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002521 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002522 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002523 Op->Memory.BaseRegNum = BaseRegNum;
2524 Op->Memory.OffsetImm = OffsetImm;
2525 Op->Memory.OffsetRegNum = OffsetRegNum;
2526 Op->Memory.ShiftType = ShiftType;
2527 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002528 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002529 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002530 Op->StartLoc = S;
2531 Op->EndLoc = E;
2532 return Op;
2533 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002534
Jim Grosbachc320c852011-08-05 21:28:30 +00002535 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2536 ARM_AM::ShiftOpc ShiftTy,
2537 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002538 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002539 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002540 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002541 Op->PostIdxReg.isAdd = isAdd;
2542 Op->PostIdxReg.ShiftTy = ShiftTy;
2543 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002544 Op->StartLoc = S;
2545 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002546 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002547 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002548
2549 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002550 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002551 Op->MBOpt.Val = Opt;
2552 Op->StartLoc = S;
2553 Op->EndLoc = S;
2554 return Op;
2555 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002556
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002557 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2558 SMLoc S) {
2559 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2560 Op->ISBOpt.Val = Opt;
2561 Op->StartLoc = S;
2562 Op->EndLoc = S;
2563 return Op;
2564 }
2565
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002566 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002567 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002568 Op->IFlags.Val = IFlags;
2569 Op->StartLoc = S;
2570 Op->EndLoc = S;
2571 return Op;
2572 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002573
2574 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002575 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002576 Op->MMask.Val = MMask;
2577 Op->StartLoc = S;
2578 Op->EndLoc = S;
2579 return Op;
2580 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002581};
2582
2583} // end anonymous namespace.
2584
Jim Grosbach602aa902011-07-13 15:34:57 +00002585void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002586 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002587 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002588 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002589 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002590 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002591 OS << "<ccout " << getReg() << ">";
2592 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002593 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002594 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002595 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2596 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2597 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002598 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2599 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2600 break;
2601 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002602 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002603 OS << "<coprocessor number: " << getCoproc() << ">";
2604 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002605 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002606 OS << "<coprocessor register: " << getCoproc() << ">";
2607 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002608 case k_CoprocOption:
2609 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2610 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002611 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002612 OS << "<mask: " << getMSRMask() << ">";
2613 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002614 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002615 getImm()->print(OS);
2616 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002617 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002618 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002619 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002620 case k_InstSyncBarrierOpt:
2621 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2622 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002623 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002624 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002625 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002626 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002627 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002628 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002629 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2630 << PostIdxReg.RegNum;
2631 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2632 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2633 << PostIdxReg.ShiftImm;
2634 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002635 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002636 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002637 OS << "<ARM_PROC::";
2638 unsigned IFlags = getProcIFlags();
2639 for (int i=2; i >= 0; --i)
2640 if (IFlags & (1 << i))
2641 OS << ARM_PROC::IFlagsToString(1 << i);
2642 OS << ">";
2643 break;
2644 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002645 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002646 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002647 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002648 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002649 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2650 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002651 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002652 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002653 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002654 << RegShiftedReg.SrcReg << " "
2655 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2656 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002657 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002658 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002659 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002660 << RegShiftedImm.SrcReg << " "
2661 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2662 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002663 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002664 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002665 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2666 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002667 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002668 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2669 << ", width: " << Bitfield.Width << ">";
2670 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002671 case k_RegisterList:
2672 case k_DPRRegisterList:
2673 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002674 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002675
Bill Wendlingbed94652010-11-09 23:28:44 +00002676 const SmallVectorImpl<unsigned> &RegList = getRegList();
2677 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002678 I = RegList.begin(), E = RegList.end(); I != E; ) {
2679 OS << *I;
2680 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002681 }
2682
2683 OS << ">";
2684 break;
2685 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002686 case k_VectorList:
2687 OS << "<vector_list " << VectorList.Count << " * "
2688 << VectorList.RegNum << ">";
2689 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002690 case k_VectorListAllLanes:
2691 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2692 << VectorList.RegNum << ">";
2693 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002694 case k_VectorListIndexed:
2695 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2696 << VectorList.Count << " * " << VectorList.RegNum << ">";
2697 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002698 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002699 OS << "'" << getToken() << "'";
2700 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002701 case k_VectorIndex:
2702 OS << "<vectorindex " << getVectorIndex() << ">";
2703 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002704 }
2705}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002706
2707/// @name Auto-generated Match Functions
2708/// {
2709
2710static unsigned MatchRegisterName(StringRef Name);
2711
2712/// }
2713
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002714bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2715 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002716 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002717 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002718 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002719
2720 return (RegNo == (unsigned)-1);
2721}
2722
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002723/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002724/// and if it is a register name the token is eaten and the register number is
2725/// returned. Otherwise return -1.
2726///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002727int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002728 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002729 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002730
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002731 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002732 unsigned RegNum = MatchRegisterName(lowerCase);
2733 if (!RegNum) {
2734 RegNum = StringSwitch<unsigned>(lowerCase)
2735 .Case("r13", ARM::SP)
2736 .Case("r14", ARM::LR)
2737 .Case("r15", ARM::PC)
2738 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002739 // Additional register name aliases for 'gas' compatibility.
2740 .Case("a1", ARM::R0)
2741 .Case("a2", ARM::R1)
2742 .Case("a3", ARM::R2)
2743 .Case("a4", ARM::R3)
2744 .Case("v1", ARM::R4)
2745 .Case("v2", ARM::R5)
2746 .Case("v3", ARM::R6)
2747 .Case("v4", ARM::R7)
2748 .Case("v5", ARM::R8)
2749 .Case("v6", ARM::R9)
2750 .Case("v7", ARM::R10)
2751 .Case("v8", ARM::R11)
2752 .Case("sb", ARM::R9)
2753 .Case("sl", ARM::R10)
2754 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002755 .Default(0);
2756 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002757 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002758 // Check for aliases registered via .req. Canonicalize to lower case.
2759 // That's more consistent since register names are case insensitive, and
2760 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2761 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002762 // If no match, return failure.
2763 if (Entry == RegisterReqs.end())
2764 return -1;
2765 Parser.Lex(); // Eat identifier token.
2766 return Entry->getValue();
2767 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002768
Chris Lattner44e5981c2010-10-30 04:09:10 +00002769 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002770
Chris Lattner44e5981c2010-10-30 04:09:10 +00002771 return RegNum;
2772}
Jim Grosbach99710a82010-11-01 16:44:21 +00002773
Jim Grosbachbb24c592011-07-13 18:49:30 +00002774// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2775// If a recoverable error occurs, return 1. If an irrecoverable error
2776// occurs, return -1. An irrecoverable error is one where tokens have been
2777// consumed in the process of trying to parse the shifter (i.e., when it is
2778// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002779int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002780 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2781 SMLoc S = Parser.getTok().getLoc();
2782 const AsmToken &Tok = Parser.getTok();
2783 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2784
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002785 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002786 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002787 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002788 .Case("lsl", ARM_AM::lsl)
2789 .Case("lsr", ARM_AM::lsr)
2790 .Case("asr", ARM_AM::asr)
2791 .Case("ror", ARM_AM::ror)
2792 .Case("rrx", ARM_AM::rrx)
2793 .Default(ARM_AM::no_shift);
2794
2795 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002796 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002797
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002798 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002799
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002800 // The source register for the shift has already been added to the
2801 // operand list, so we need to pop it off and combine it into the shifted
2802 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002803 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002804 if (!PrevOp->isReg())
2805 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2806 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002807
2808 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002809 int64_t Imm = 0;
2810 int ShiftReg = 0;
2811 if (ShiftTy == ARM_AM::rrx) {
2812 // RRX Doesn't have an explicit shift amount. The encoder expects
2813 // the shift register to be the same as the source register. Seems odd,
2814 // but OK.
2815 ShiftReg = SrcReg;
2816 } else {
2817 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002818 if (Parser.getTok().is(AsmToken::Hash) ||
2819 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002820 Parser.Lex(); // Eat hash.
2821 SMLoc ImmLoc = Parser.getTok().getLoc();
2822 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002823 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002824 Error(ImmLoc, "invalid immediate shift value");
2825 return -1;
2826 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002827 // The expression must be evaluatable as an immediate.
2828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002829 if (!CE) {
2830 Error(ImmLoc, "invalid immediate shift value");
2831 return -1;
2832 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002833 // Range check the immediate.
2834 // lsl, ror: 0 <= imm <= 31
2835 // lsr, asr: 0 <= imm <= 32
2836 Imm = CE->getValue();
2837 if (Imm < 0 ||
2838 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2839 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002840 Error(ImmLoc, "immediate shift value out of range");
2841 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002842 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002843 // shift by zero is a nop. Always send it through as lsl.
2844 // ('as' compatibility)
2845 if (Imm == 0)
2846 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002847 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002848 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002849 EndLoc = Parser.getTok().getEndLoc();
2850 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002851 if (ShiftReg == -1) {
2852 Error (L, "expected immediate or register in shift operand");
2853 return -1;
2854 }
2855 } else {
2856 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002857 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002858 return -1;
2859 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002860 }
2861
Owen Andersonb595ed02011-07-21 18:54:16 +00002862 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2863 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002864 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002865 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002866 else
2867 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002868 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002869
Jim Grosbachbb24c592011-07-13 18:49:30 +00002870 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002871}
2872
2873
Bill Wendling2063b842010-11-18 23:43:05 +00002874/// Try to parse a register name. The token must be an Identifier when called.
2875/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2876/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002877///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002878/// TODO this is likely to change to allow different register types and or to
2879/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002880bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002881tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002882 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002883 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002884 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002885 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002886
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002887 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2888 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002889
Chris Lattner44e5981c2010-10-30 04:09:10 +00002890 const AsmToken &ExclaimTok = Parser.getTok();
2891 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002892 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2893 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002894 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002895 return false;
2896 }
2897
2898 // Also check for an index operand. This is only legal for vector registers,
2899 // but that'll get caught OK in operand matching, so we don't need to
2900 // explicitly filter everything else out here.
2901 if (Parser.getTok().is(AsmToken::LBrac)) {
2902 SMLoc SIdx = Parser.getTok().getLoc();
2903 Parser.Lex(); // Eat left bracket token.
2904
2905 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002906 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002907 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002908 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002909 if (!MCE)
2910 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002911
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002912 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002913 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002914
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002915 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002916 Parser.Lex(); // Eat right bracket token.
2917
2918 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2919 SIdx, E,
2920 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002921 }
2922
Bill Wendling2063b842010-11-18 23:43:05 +00002923 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002924}
2925
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002926/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2927/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2928/// "c5", ...
2929static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002930 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2931 // but efficient.
2932 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002933 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002934 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002935 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002936 return -1;
2937 switch (Name[1]) {
2938 default: return -1;
2939 case '0': return 0;
2940 case '1': return 1;
2941 case '2': return 2;
2942 case '3': return 3;
2943 case '4': return 4;
2944 case '5': return 5;
2945 case '6': return 6;
2946 case '7': return 7;
2947 case '8': return 8;
2948 case '9': return 9;
2949 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002950 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002951 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002952 return -1;
2953 switch (Name[2]) {
2954 default: return -1;
Artyom Skrobov86534432013-11-08 09:16:31 +00002955 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2956 case '0': return CoprocOp == 'p'? -1: 10;
2957 case '1': return CoprocOp == 'p'? -1: 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002958 case '2': return 12;
2959 case '3': return 13;
2960 case '4': return 14;
2961 case '5': return 15;
2962 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002963 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002964}
2965
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002966/// parseITCondCode - Try to parse a condition code for an IT instruction.
2967ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2968parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2969 SMLoc S = Parser.getTok().getLoc();
2970 const AsmToken &Tok = Parser.getTok();
2971 if (!Tok.is(AsmToken::Identifier))
2972 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002973 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002974 .Case("eq", ARMCC::EQ)
2975 .Case("ne", ARMCC::NE)
2976 .Case("hs", ARMCC::HS)
2977 .Case("cs", ARMCC::HS)
2978 .Case("lo", ARMCC::LO)
2979 .Case("cc", ARMCC::LO)
2980 .Case("mi", ARMCC::MI)
2981 .Case("pl", ARMCC::PL)
2982 .Case("vs", ARMCC::VS)
2983 .Case("vc", ARMCC::VC)
2984 .Case("hi", ARMCC::HI)
2985 .Case("ls", ARMCC::LS)
2986 .Case("ge", ARMCC::GE)
2987 .Case("lt", ARMCC::LT)
2988 .Case("gt", ARMCC::GT)
2989 .Case("le", ARMCC::LE)
2990 .Case("al", ARMCC::AL)
2991 .Default(~0U);
2992 if (CC == ~0U)
2993 return MatchOperand_NoMatch;
2994 Parser.Lex(); // Eat the token.
2995
2996 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2997
2998 return MatchOperand_Success;
2999}
3000
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003001/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003002/// token must be an Identifier when called, and if it is a coprocessor
3003/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003004ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003005parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003006 SMLoc S = Parser.getTok().getLoc();
3007 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003008 if (Tok.isNot(AsmToken::Identifier))
3009 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003010
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003011 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003012 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003013 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003014
3015 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003016 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003017 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003018}
3019
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003020/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003021/// token must be an Identifier when called, and if it is a coprocessor
3022/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003023ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003024parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003025 SMLoc S = Parser.getTok().getLoc();
3026 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003027 if (Tok.isNot(AsmToken::Identifier))
3028 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003029
3030 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3031 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003032 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003033
3034 Parser.Lex(); // Eat identifier token.
3035 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003036 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003037}
3038
Jim Grosbach48399582011-10-12 17:34:41 +00003039/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3040/// coproc_option : '{' imm0_255 '}'
3041ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3042parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3043 SMLoc S = Parser.getTok().getLoc();
3044
3045 // If this isn't a '{', this isn't a coprocessor immediate operand.
3046 if (Parser.getTok().isNot(AsmToken::LCurly))
3047 return MatchOperand_NoMatch;
3048 Parser.Lex(); // Eat the '{'
3049
3050 const MCExpr *Expr;
3051 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003052 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003053 Error(Loc, "illegal expression");
3054 return MatchOperand_ParseFail;
3055 }
3056 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3057 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3058 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3059 return MatchOperand_ParseFail;
3060 }
3061 int Val = CE->getValue();
3062
3063 // Check for and consume the closing '}'
3064 if (Parser.getTok().isNot(AsmToken::RCurly))
3065 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003066 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003067 Parser.Lex(); // Eat the '}'
3068
3069 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3070 return MatchOperand_Success;
3071}
3072
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003073// For register list parsing, we need to map from raw GPR register numbering
3074// to the enumeration values. The enumeration values aren't sorted by
3075// register number due to our using "sp", "lr" and "pc" as canonical names.
3076static unsigned getNextRegister(unsigned Reg) {
3077 // If this is a GPR, we need to do it manually, otherwise we can rely
3078 // on the sort ordering of the enumeration since the other reg-classes
3079 // are sane.
3080 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3081 return Reg + 1;
3082 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003083 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003084 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3085 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3086 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3087 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3088 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3089 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3090 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3091 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3092 }
3093}
3094
Jim Grosbach85a23432011-11-11 21:27:40 +00003095// Return the low-subreg of a given Q register.
3096static unsigned getDRegFromQReg(unsigned QReg) {
3097 switch (QReg) {
3098 default: llvm_unreachable("expected a Q register!");
3099 case ARM::Q0: return ARM::D0;
3100 case ARM::Q1: return ARM::D2;
3101 case ARM::Q2: return ARM::D4;
3102 case ARM::Q3: return ARM::D6;
3103 case ARM::Q4: return ARM::D8;
3104 case ARM::Q5: return ARM::D10;
3105 case ARM::Q6: return ARM::D12;
3106 case ARM::Q7: return ARM::D14;
3107 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003108 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003109 case ARM::Q10: return ARM::D20;
3110 case ARM::Q11: return ARM::D22;
3111 case ARM::Q12: return ARM::D24;
3112 case ARM::Q13: return ARM::D26;
3113 case ARM::Q14: return ARM::D28;
3114 case ARM::Q15: return ARM::D30;
3115 }
3116}
3117
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003118/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003119bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003120parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003121 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003122 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003123 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003124 Parser.Lex(); // Eat '{' token.
3125 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003126
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003127 // Check the first register in the list to see what register class
3128 // this is a list of.
3129 int Reg = tryParseRegister();
3130 if (Reg == -1)
3131 return Error(RegLoc, "register expected");
3132
Jim Grosbach85a23432011-11-11 21:27:40 +00003133 // The reglist instructions have at most 16 registers, so reserve
3134 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003135 int EReg = 0;
3136 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003137
3138 // Allow Q regs and just interpret them as the two D sub-registers.
3139 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3140 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003141 EReg = MRI->getEncodingValue(Reg);
3142 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003143 ++Reg;
3144 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003145 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003146 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3147 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3148 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3149 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3150 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3151 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3152 else
3153 return Error(RegLoc, "invalid register in register list");
3154
Jim Grosbach85a23432011-11-11 21:27:40 +00003155 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003156 EReg = MRI->getEncodingValue(Reg);
3157 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003158
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003159 // This starts immediately after the first register token in the list,
3160 // so we can see either a comma or a minus (range separator) as a legal
3161 // next token.
3162 while (Parser.getTok().is(AsmToken::Comma) ||
3163 Parser.getTok().is(AsmToken::Minus)) {
3164 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003165 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003166 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003167 int EndReg = tryParseRegister();
3168 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003169 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003170 // Allow Q regs and just interpret them as the two D sub-registers.
3171 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3172 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003173 // If the register is the same as the start reg, there's nothing
3174 // more to do.
3175 if (Reg == EndReg)
3176 continue;
3177 // The register must be in the same register class as the first.
3178 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003179 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003180 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003181 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003182 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003183
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003184 // Add all the registers in the range to the register list.
3185 while (Reg != EndReg) {
3186 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003187 EReg = MRI->getEncodingValue(Reg);
3188 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003189 }
3190 continue;
3191 }
3192 Parser.Lex(); // Eat the comma.
3193 RegLoc = Parser.getTok().getLoc();
3194 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003195 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003196 Reg = tryParseRegister();
3197 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003198 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003199 // Allow Q regs and just interpret them as the two D sub-registers.
3200 bool isQReg = false;
3201 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3202 Reg = getDRegFromQReg(Reg);
3203 isQReg = true;
3204 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003205 // The register must be in the same register class as the first.
3206 if (!RC->contains(Reg))
3207 return Error(RegLoc, "invalid register in register list");
3208 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003209 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003210 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3211 Warning(RegLoc, "register list not in ascending order");
3212 else
3213 return Error(RegLoc, "register list not in ascending order");
3214 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003215 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003216 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3217 ") in register list");
3218 continue;
3219 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003220 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003221 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3222 Reg != OldReg + 1)
3223 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003224 EReg = MRI->getEncodingValue(Reg);
3225 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3226 if (isQReg) {
3227 EReg = MRI->getEncodingValue(++Reg);
3228 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3229 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003230 }
3231
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003232 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003233 return Error(Parser.getTok().getLoc(), "'}' expected");
3234 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003235 Parser.Lex(); // Eat '}' token.
3236
Jim Grosbach18bf3632011-12-13 21:48:29 +00003237 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003238 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003239
3240 // The ARM system instruction variants for LDM/STM have a '^' token here.
3241 if (Parser.getTok().is(AsmToken::Caret)) {
3242 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3243 Parser.Lex(); // Eat '^' token.
3244 }
3245
Bill Wendling2063b842010-11-18 23:43:05 +00003246 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003247}
3248
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003249// Helper function to parse the lane index for vector lists.
3250ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003251parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003252 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003253 if (Parser.getTok().is(AsmToken::LBrac)) {
3254 Parser.Lex(); // Eat the '['.
3255 if (Parser.getTok().is(AsmToken::RBrac)) {
3256 // "Dn[]" is the 'all lanes' syntax.
3257 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003258 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003259 Parser.Lex(); // Eat the ']'.
3260 return MatchOperand_Success;
3261 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003262
3263 // There's an optional '#' token here. Normally there wouldn't be, but
3264 // inline assemble puts one in, and it's friendly to accept that.
3265 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003266 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003267
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003268 const MCExpr *LaneIndex;
3269 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003270 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003271 Error(Loc, "illegal expression");
3272 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003273 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003274 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3275 if (!CE) {
3276 Error(Loc, "lane index must be empty or an integer");
3277 return MatchOperand_ParseFail;
3278 }
3279 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3280 Error(Parser.getTok().getLoc(), "']' expected");
3281 return MatchOperand_ParseFail;
3282 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003283 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003284 Parser.Lex(); // Eat the ']'.
3285 int64_t Val = CE->getValue();
3286
3287 // FIXME: Make this range check context sensitive for .8, .16, .32.
3288 if (Val < 0 || Val > 7) {
3289 Error(Parser.getTok().getLoc(), "lane index out of range");
3290 return MatchOperand_ParseFail;
3291 }
3292 Index = Val;
3293 LaneKind = IndexedLane;
3294 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003295 }
3296 LaneKind = NoLanes;
3297 return MatchOperand_Success;
3298}
3299
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003300// parse a vector register list
3301ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3302parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003303 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003304 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003305 SMLoc S = Parser.getTok().getLoc();
3306 // As an extension (to match gas), support a plain D register or Q register
3307 // (without encosing curly braces) as a single or double entry list,
3308 // respectively.
3309 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003310 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003311 int Reg = tryParseRegister();
3312 if (Reg == -1)
3313 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003314 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003315 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003316 if (Res != MatchOperand_Success)
3317 return Res;
3318 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003319 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003320 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003321 break;
3322 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003323 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3324 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003325 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003326 case IndexedLane:
3327 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003328 LaneIndex,
3329 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003330 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003331 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003332 return MatchOperand_Success;
3333 }
3334 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3335 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003336 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003337 if (Res != MatchOperand_Success)
3338 return Res;
3339 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003340 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003341 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003342 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003343 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003344 break;
3345 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003346 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3347 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003348 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3349 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003350 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003351 case IndexedLane:
3352 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003353 LaneIndex,
3354 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003355 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003356 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003357 return MatchOperand_Success;
3358 }
3359 Error(S, "vector register expected");
3360 return MatchOperand_ParseFail;
3361 }
3362
3363 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003364 return MatchOperand_NoMatch;
3365
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003366 Parser.Lex(); // Eat '{' token.
3367 SMLoc RegLoc = Parser.getTok().getLoc();
3368
3369 int Reg = tryParseRegister();
3370 if (Reg == -1) {
3371 Error(RegLoc, "register expected");
3372 return MatchOperand_ParseFail;
3373 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003374 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003375 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003376 unsigned FirstReg = Reg;
3377 // The list is of D registers, but we also allow Q regs and just interpret
3378 // them as the two D sub-registers.
3379 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3380 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003381 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3382 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003383 ++Reg;
3384 ++Count;
3385 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003386
3387 SMLoc E;
3388 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003389 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003390
Jim Grosbache891fe82011-11-15 23:19:15 +00003391 while (Parser.getTok().is(AsmToken::Comma) ||
3392 Parser.getTok().is(AsmToken::Minus)) {
3393 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003394 if (!Spacing)
3395 Spacing = 1; // Register range implies a single spaced list.
3396 else if (Spacing == 2) {
3397 Error(Parser.getTok().getLoc(),
3398 "sequential registers in double spaced list");
3399 return MatchOperand_ParseFail;
3400 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003401 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003402 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003403 int EndReg = tryParseRegister();
3404 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003405 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003406 return MatchOperand_ParseFail;
3407 }
3408 // Allow Q regs and just interpret them as the two D sub-registers.
3409 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3410 EndReg = getDRegFromQReg(EndReg) + 1;
3411 // If the register is the same as the start reg, there's nothing
3412 // more to do.
3413 if (Reg == EndReg)
3414 continue;
3415 // The register must be in the same register class as the first.
3416 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003417 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003418 return MatchOperand_ParseFail;
3419 }
3420 // Ranges must go from low to high.
3421 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003422 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003423 return MatchOperand_ParseFail;
3424 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003425 // Parse the lane specifier if present.
3426 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003427 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003428 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3429 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003430 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003431 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003432 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003433 return MatchOperand_ParseFail;
3434 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003435
3436 // Add all the registers in the range to the register list.
3437 Count += EndReg - Reg;
3438 Reg = EndReg;
3439 continue;
3440 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003441 Parser.Lex(); // Eat the comma.
3442 RegLoc = Parser.getTok().getLoc();
3443 int OldReg = Reg;
3444 Reg = tryParseRegister();
3445 if (Reg == -1) {
3446 Error(RegLoc, "register expected");
3447 return MatchOperand_ParseFail;
3448 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003449 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003450 // It's OK to use the enumeration values directly here rather, as the
3451 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003452 //
3453 // The list is of D registers, but we also allow Q regs and just interpret
3454 // them as the two D sub-registers.
3455 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003456 if (!Spacing)
3457 Spacing = 1; // Register range implies a single spaced list.
3458 else if (Spacing == 2) {
3459 Error(RegLoc,
3460 "invalid register in double-spaced list (must be 'D' register')");
3461 return MatchOperand_ParseFail;
3462 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003463 Reg = getDRegFromQReg(Reg);
3464 if (Reg != OldReg + 1) {
3465 Error(RegLoc, "non-contiguous register range");
3466 return MatchOperand_ParseFail;
3467 }
3468 ++Reg;
3469 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003470 // Parse the lane specifier if present.
3471 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003472 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003473 SMLoc LaneLoc = Parser.getTok().getLoc();
3474 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3475 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003476 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003477 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003478 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003479 return MatchOperand_ParseFail;
3480 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003481 continue;
3482 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003483 // Normal D register.
3484 // Figure out the register spacing (single or double) of the list if
3485 // we don't know it already.
3486 if (!Spacing)
3487 Spacing = 1 + (Reg == OldReg + 2);
3488
3489 // Just check that it's contiguous and keep going.
3490 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003491 Error(RegLoc, "non-contiguous register range");
3492 return MatchOperand_ParseFail;
3493 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003494 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003495 // Parse the lane specifier if present.
3496 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003497 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003498 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003499 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003500 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003501 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003502 Error(EndLoc, "mismatched lane index in register list");
3503 return MatchOperand_ParseFail;
3504 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003505 }
3506
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003507 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003508 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003509 return MatchOperand_ParseFail;
3510 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003511 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003512 Parser.Lex(); // Eat '}' token.
3513
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003514 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003515 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003516 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003517 // composite register classes.
3518 if (Count == 2) {
3519 const MCRegisterClass *RC = (Spacing == 1) ?
3520 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3521 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3522 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3523 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003524
Jim Grosbach2f50e922011-12-15 21:44:33 +00003525 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3526 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003527 break;
3528 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003529 // Two-register operands have been converted to the
3530 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003531 if (Count == 2) {
3532 const MCRegisterClass *RC = (Spacing == 1) ?
3533 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3534 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003535 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3536 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003537 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003538 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003539 S, E));
3540 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003541 case IndexedLane:
3542 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003543 LaneIndex,
3544 (Spacing == 2),
3545 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003546 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003547 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003548 return MatchOperand_Success;
3549}
3550
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003551/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003552ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003553parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003554 SMLoc S = Parser.getTok().getLoc();
3555 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003556 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003557
Jiangning Liu288e1af2012-08-02 08:21:27 +00003558 if (Tok.is(AsmToken::Identifier)) {
3559 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003560
Jiangning Liu288e1af2012-08-02 08:21:27 +00003561 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3562 .Case("sy", ARM_MB::SY)
3563 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003564 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003565 .Case("sh", ARM_MB::ISH)
3566 .Case("ish", ARM_MB::ISH)
3567 .Case("shst", ARM_MB::ISHST)
3568 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003569 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003570 .Case("nsh", ARM_MB::NSH)
3571 .Case("un", ARM_MB::NSH)
3572 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003573 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003574 .Case("unst", ARM_MB::NSHST)
3575 .Case("osh", ARM_MB::OSH)
3576 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003577 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003578 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003579
Joey Gouly926d3f52013-09-05 15:35:24 +00003580 // ishld, oshld, nshld and ld are only available from ARMv8.
3581 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3582 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3583 Opt = ~0U;
3584
Jiangning Liu288e1af2012-08-02 08:21:27 +00003585 if (Opt == ~0U)
3586 return MatchOperand_NoMatch;
3587
3588 Parser.Lex(); // Eat identifier token.
3589 } else if (Tok.is(AsmToken::Hash) ||
3590 Tok.is(AsmToken::Dollar) ||
3591 Tok.is(AsmToken::Integer)) {
3592 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003593 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003594 SMLoc Loc = Parser.getTok().getLoc();
3595
3596 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003597 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003598 Error(Loc, "illegal expression");
3599 return MatchOperand_ParseFail;
3600 }
3601
3602 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3603 if (!CE) {
3604 Error(Loc, "constant expression expected");
3605 return MatchOperand_ParseFail;
3606 }
3607
3608 int Val = CE->getValue();
3609 if (Val & ~0xf) {
3610 Error(Loc, "immediate value out of range");
3611 return MatchOperand_ParseFail;
3612 }
3613
3614 Opt = ARM_MB::RESERVED_0 + Val;
3615 } else
3616 return MatchOperand_ParseFail;
3617
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003618 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003619 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003620}
3621
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003622/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3623ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3624parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3625 SMLoc S = Parser.getTok().getLoc();
3626 const AsmToken &Tok = Parser.getTok();
3627 unsigned Opt;
3628
3629 if (Tok.is(AsmToken::Identifier)) {
3630 StringRef OptStr = Tok.getString();
3631
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003632 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003633 Opt = ARM_ISB::SY;
3634 else
3635 return MatchOperand_NoMatch;
3636
3637 Parser.Lex(); // Eat identifier token.
3638 } else if (Tok.is(AsmToken::Hash) ||
3639 Tok.is(AsmToken::Dollar) ||
3640 Tok.is(AsmToken::Integer)) {
3641 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003642 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003643 SMLoc Loc = Parser.getTok().getLoc();
3644
3645 const MCExpr *ISBarrierID;
3646 if (getParser().parseExpression(ISBarrierID)) {
3647 Error(Loc, "illegal expression");
3648 return MatchOperand_ParseFail;
3649 }
3650
3651 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3652 if (!CE) {
3653 Error(Loc, "constant expression expected");
3654 return MatchOperand_ParseFail;
3655 }
3656
3657 int Val = CE->getValue();
3658 if (Val & ~0xf) {
3659 Error(Loc, "immediate value out of range");
3660 return MatchOperand_ParseFail;
3661 }
3662
3663 Opt = ARM_ISB::RESERVED_0 + Val;
3664 } else
3665 return MatchOperand_ParseFail;
3666
3667 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3668 (ARM_ISB::InstSyncBOpt)Opt, S));
3669 return MatchOperand_Success;
3670}
3671
3672
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003673/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003674ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003675parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003676 SMLoc S = Parser.getTok().getLoc();
3677 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003678 if (!Tok.is(AsmToken::Identifier))
3679 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003680 StringRef IFlagsStr = Tok.getString();
3681
Owen Anderson10c5b122011-10-05 17:16:40 +00003682 // An iflags string of "none" is interpreted to mean that none of the AIF
3683 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003684 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003685 if (IFlagsStr != "none") {
3686 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3687 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3688 .Case("a", ARM_PROC::A)
3689 .Case("i", ARM_PROC::I)
3690 .Case("f", ARM_PROC::F)
3691 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003692
Owen Anderson10c5b122011-10-05 17:16:40 +00003693 // If some specific iflag is already set, it means that some letter is
3694 // present more than once, this is not acceptable.
3695 if (Flag == ~0U || (IFlags & Flag))
3696 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003697
Owen Anderson10c5b122011-10-05 17:16:40 +00003698 IFlags |= Flag;
3699 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003700 }
3701
3702 Parser.Lex(); // Eat identifier token.
3703 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3704 return MatchOperand_Success;
3705}
3706
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003707/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003708ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003709parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003710 SMLoc S = Parser.getTok().getLoc();
3711 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003712 if (!Tok.is(AsmToken::Identifier))
3713 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003714 StringRef Mask = Tok.getString();
3715
James Molloy21efa7d2011-09-28 14:21:38 +00003716 if (isMClass()) {
3717 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003718 std::string Name = Mask.lower();
3719 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003720 // Note: in the documentation:
3721 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3722 // for MSR APSR_nzcvq.
3723 // but we do make it an alias here. This is so to get the "mask encoding"
3724 // bits correct on MSR APSR writes.
3725 //
3726 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3727 // should really only be allowed when writing a special register. Note
3728 // they get dropped in the MRS instruction reading a special register as
3729 // the SYSm field is only 8 bits.
3730 //
3731 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3732 // includes the DSP extension but that is not checked.
3733 .Case("apsr", 0x800)
3734 .Case("apsr_nzcvq", 0x800)
3735 .Case("apsr_g", 0x400)
3736 .Case("apsr_nzcvqg", 0xc00)
3737 .Case("iapsr", 0x801)
3738 .Case("iapsr_nzcvq", 0x801)
3739 .Case("iapsr_g", 0x401)
3740 .Case("iapsr_nzcvqg", 0xc01)
3741 .Case("eapsr", 0x802)
3742 .Case("eapsr_nzcvq", 0x802)
3743 .Case("eapsr_g", 0x402)
3744 .Case("eapsr_nzcvqg", 0xc02)
3745 .Case("xpsr", 0x803)
3746 .Case("xpsr_nzcvq", 0x803)
3747 .Case("xpsr_g", 0x403)
3748 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003749 .Case("ipsr", 0x805)
3750 .Case("epsr", 0x806)
3751 .Case("iepsr", 0x807)
3752 .Case("msp", 0x808)
3753 .Case("psp", 0x809)
3754 .Case("primask", 0x810)
3755 .Case("basepri", 0x811)
3756 .Case("basepri_max", 0x812)
3757 .Case("faultmask", 0x813)
3758 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003759 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003760
James Molloy21efa7d2011-09-28 14:21:38 +00003761 if (FlagsVal == ~0U)
3762 return MatchOperand_NoMatch;
3763
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003764 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003765 // basepri, basepri_max and faultmask only valid for V7m.
3766 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003767
James Molloy21efa7d2011-09-28 14:21:38 +00003768 Parser.Lex(); // Eat identifier token.
3769 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3770 return MatchOperand_Success;
3771 }
3772
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003773 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3774 size_t Start = 0, Next = Mask.find('_');
3775 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003776 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003777 if (Next != StringRef::npos)
3778 Flags = Mask.slice(Next+1, Mask.size());
3779
3780 // FlagsVal contains the complete mask:
3781 // 3-0: Mask
3782 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3783 unsigned FlagsVal = 0;
3784
3785 if (SpecReg == "apsr") {
3786 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003787 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003788 .Case("g", 0x4) // same as CPSR_s
3789 .Case("nzcvqg", 0xc) // same as CPSR_fs
3790 .Default(~0U);
3791
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003792 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003793 if (!Flags.empty())
3794 return MatchOperand_NoMatch;
3795 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003796 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003797 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003798 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003799 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3800 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003801 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003802 for (int i = 0, e = Flags.size(); i != e; ++i) {
3803 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3804 .Case("c", 1)
3805 .Case("x", 2)
3806 .Case("s", 4)
3807 .Case("f", 8)
3808 .Default(~0U);
3809
3810 // If some specific flag is already set, it means that some letter is
3811 // present more than once, this is not acceptable.
3812 if (FlagsVal == ~0U || (FlagsVal & Flag))
3813 return MatchOperand_NoMatch;
3814 FlagsVal |= Flag;
3815 }
3816 } else // No match for special register.
3817 return MatchOperand_NoMatch;
3818
Owen Anderson03a173e2011-10-21 18:43:28 +00003819 // Special register without flags is NOT equivalent to "fc" flags.
3820 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3821 // two lines would enable gas compatibility at the expense of breaking
3822 // round-tripping.
3823 //
3824 // if (!FlagsVal)
3825 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003826
3827 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3828 if (SpecReg == "spsr")
3829 FlagsVal |= 16;
3830
3831 Parser.Lex(); // Eat identifier token.
3832 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3833 return MatchOperand_Success;
3834}
3835
Jim Grosbach27c1e252011-07-21 17:23:04 +00003836ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3837parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3838 int Low, int High) {
3839 const AsmToken &Tok = Parser.getTok();
3840 if (Tok.isNot(AsmToken::Identifier)) {
3841 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3842 return MatchOperand_ParseFail;
3843 }
3844 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003845 std::string LowerOp = Op.lower();
3846 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003847 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3848 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3849 return MatchOperand_ParseFail;
3850 }
3851 Parser.Lex(); // Eat shift type token.
3852
3853 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003854 if (Parser.getTok().isNot(AsmToken::Hash) &&
3855 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003856 Error(Parser.getTok().getLoc(), "'#' expected");
3857 return MatchOperand_ParseFail;
3858 }
3859 Parser.Lex(); // Eat hash token.
3860
3861 const MCExpr *ShiftAmount;
3862 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003863 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003864 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003865 Error(Loc, "illegal expression");
3866 return MatchOperand_ParseFail;
3867 }
3868 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3869 if (!CE) {
3870 Error(Loc, "constant expression expected");
3871 return MatchOperand_ParseFail;
3872 }
3873 int Val = CE->getValue();
3874 if (Val < Low || Val > High) {
3875 Error(Loc, "immediate value out of range");
3876 return MatchOperand_ParseFail;
3877 }
3878
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003879 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003880
3881 return MatchOperand_Success;
3882}
3883
Jim Grosbach0a547702011-07-22 17:44:50 +00003884ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3885parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3886 const AsmToken &Tok = Parser.getTok();
3887 SMLoc S = Tok.getLoc();
3888 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003889 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003890 return MatchOperand_ParseFail;
3891 }
Tim Northover4d141442013-05-31 15:58:45 +00003892 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003893 .Case("be", 1)
3894 .Case("le", 0)
3895 .Default(-1);
3896 Parser.Lex(); // Eat the token.
3897
3898 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003899 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003900 return MatchOperand_ParseFail;
3901 }
3902 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3903 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003904 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003905 return MatchOperand_Success;
3906}
3907
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003908/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3909/// instructions. Legal values are:
3910/// lsl #n 'n' in [0,31]
3911/// asr #n 'n' in [1,32]
3912/// n == 32 encoded as n == 0.
3913ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3914parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3915 const AsmToken &Tok = Parser.getTok();
3916 SMLoc S = Tok.getLoc();
3917 if (Tok.isNot(AsmToken::Identifier)) {
3918 Error(S, "shift operator 'asr' or 'lsl' expected");
3919 return MatchOperand_ParseFail;
3920 }
3921 StringRef ShiftName = Tok.getString();
3922 bool isASR;
3923 if (ShiftName == "lsl" || ShiftName == "LSL")
3924 isASR = false;
3925 else if (ShiftName == "asr" || ShiftName == "ASR")
3926 isASR = true;
3927 else {
3928 Error(S, "shift operator 'asr' or 'lsl' expected");
3929 return MatchOperand_ParseFail;
3930 }
3931 Parser.Lex(); // Eat the operator.
3932
3933 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003934 if (Parser.getTok().isNot(AsmToken::Hash) &&
3935 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003936 Error(Parser.getTok().getLoc(), "'#' expected");
3937 return MatchOperand_ParseFail;
3938 }
3939 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003940 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003941
3942 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003943 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003944 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003945 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003946 return MatchOperand_ParseFail;
3947 }
3948 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3949 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003950 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003951 return MatchOperand_ParseFail;
3952 }
3953
3954 int64_t Val = CE->getValue();
3955 if (isASR) {
3956 // Shift amount must be in [1,32]
3957 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003958 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003959 return MatchOperand_ParseFail;
3960 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003961 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3962 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003963 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003964 return MatchOperand_ParseFail;
3965 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003966 if (Val == 32) Val = 0;
3967 } else {
3968 // Shift amount must be in [1,32]
3969 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003970 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003971 return MatchOperand_ParseFail;
3972 }
3973 }
3974
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003975 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003976
3977 return MatchOperand_Success;
3978}
3979
Jim Grosbach833b9d32011-07-27 20:15:40 +00003980/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3981/// of instructions. Legal values are:
3982/// ror #n 'n' in {0, 8, 16, 24}
3983ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3984parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3985 const AsmToken &Tok = Parser.getTok();
3986 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003987 if (Tok.isNot(AsmToken::Identifier))
3988 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003989 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003990 if (ShiftName != "ror" && ShiftName != "ROR")
3991 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003992 Parser.Lex(); // Eat the operator.
3993
3994 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003995 if (Parser.getTok().isNot(AsmToken::Hash) &&
3996 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003997 Error(Parser.getTok().getLoc(), "'#' expected");
3998 return MatchOperand_ParseFail;
3999 }
4000 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004001 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004002
4003 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004004 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004005 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004006 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004007 return MatchOperand_ParseFail;
4008 }
4009 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4010 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004011 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004012 return MatchOperand_ParseFail;
4013 }
4014
4015 int64_t Val = CE->getValue();
4016 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4017 // normally, zero is represented in asm by omitting the rotate operand
4018 // entirely.
4019 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004020 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004021 return MatchOperand_ParseFail;
4022 }
4023
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004024 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004025
4026 return MatchOperand_Success;
4027}
4028
Jim Grosbach864b6092011-07-28 21:34:26 +00004029ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4030parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4031 SMLoc S = Parser.getTok().getLoc();
4032 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004033 if (Parser.getTok().isNot(AsmToken::Hash) &&
4034 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004035 Error(Parser.getTok().getLoc(), "'#' expected");
4036 return MatchOperand_ParseFail;
4037 }
4038 Parser.Lex(); // Eat hash token.
4039
4040 const MCExpr *LSBExpr;
4041 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004042 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004043 Error(E, "malformed immediate expression");
4044 return MatchOperand_ParseFail;
4045 }
4046 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4047 if (!CE) {
4048 Error(E, "'lsb' operand must be an immediate");
4049 return MatchOperand_ParseFail;
4050 }
4051
4052 int64_t LSB = CE->getValue();
4053 // The LSB must be in the range [0,31]
4054 if (LSB < 0 || LSB > 31) {
4055 Error(E, "'lsb' operand must be in the range [0,31]");
4056 return MatchOperand_ParseFail;
4057 }
4058 E = Parser.getTok().getLoc();
4059
4060 // Expect another immediate operand.
4061 if (Parser.getTok().isNot(AsmToken::Comma)) {
4062 Error(Parser.getTok().getLoc(), "too few operands");
4063 return MatchOperand_ParseFail;
4064 }
4065 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004066 if (Parser.getTok().isNot(AsmToken::Hash) &&
4067 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004068 Error(Parser.getTok().getLoc(), "'#' expected");
4069 return MatchOperand_ParseFail;
4070 }
4071 Parser.Lex(); // Eat hash token.
4072
4073 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004074 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004075 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004076 Error(E, "malformed immediate expression");
4077 return MatchOperand_ParseFail;
4078 }
4079 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4080 if (!CE) {
4081 Error(E, "'width' operand must be an immediate");
4082 return MatchOperand_ParseFail;
4083 }
4084
4085 int64_t Width = CE->getValue();
4086 // The LSB must be in the range [1,32-lsb]
4087 if (Width < 1 || Width > 32 - LSB) {
4088 Error(E, "'width' operand must be in the range [1,32-lsb]");
4089 return MatchOperand_ParseFail;
4090 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004091
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004092 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004093
4094 return MatchOperand_Success;
4095}
4096
Jim Grosbachd3595712011-08-03 23:50:40 +00004097ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4098parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4099 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004100 // postidx_reg := '+' register {, shift}
4101 // | '-' register {, shift}
4102 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004103
4104 // This method must return MatchOperand_NoMatch without consuming any tokens
4105 // in the case where there is no match, as other alternatives take other
4106 // parse methods.
4107 AsmToken Tok = Parser.getTok();
4108 SMLoc S = Tok.getLoc();
4109 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004110 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004111 if (Tok.is(AsmToken::Plus)) {
4112 Parser.Lex(); // Eat the '+' token.
4113 haveEaten = true;
4114 } else if (Tok.is(AsmToken::Minus)) {
4115 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004116 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004117 haveEaten = true;
4118 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004119
4120 SMLoc E = Parser.getTok().getEndLoc();
4121 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004122 if (Reg == -1) {
4123 if (!haveEaten)
4124 return MatchOperand_NoMatch;
4125 Error(Parser.getTok().getLoc(), "register expected");
4126 return MatchOperand_ParseFail;
4127 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004128
Jim Grosbachc320c852011-08-05 21:28:30 +00004129 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4130 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004131 if (Parser.getTok().is(AsmToken::Comma)) {
4132 Parser.Lex(); // Eat the ','.
4133 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4134 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004135
4136 // FIXME: Only approximates end...may include intervening whitespace.
4137 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004138 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004139
4140 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4141 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004142
4143 return MatchOperand_Success;
4144}
4145
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004146ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4147parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4148 // Check for a post-index addressing register operand. Specifically:
4149 // am3offset := '+' register
4150 // | '-' register
4151 // | register
4152 // | # imm
4153 // | # + imm
4154 // | # - imm
4155
4156 // This method must return MatchOperand_NoMatch without consuming any tokens
4157 // in the case where there is no match, as other alternatives take other
4158 // parse methods.
4159 AsmToken Tok = Parser.getTok();
4160 SMLoc S = Tok.getLoc();
4161
4162 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004163 if (Parser.getTok().is(AsmToken::Hash) ||
4164 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004165 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004166 // Explicitly look for a '-', as we need to encode negative zero
4167 // differently.
4168 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4169 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004170 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004171 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004172 return MatchOperand_ParseFail;
4173 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4174 if (!CE) {
4175 Error(S, "constant expression expected");
4176 return MatchOperand_ParseFail;
4177 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004178 // Negative zero is encoded as the flag value INT32_MIN.
4179 int32_t Val = CE->getValue();
4180 if (isNegative && Val == 0)
4181 Val = INT32_MIN;
4182
4183 Operands.push_back(
4184 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4185
4186 return MatchOperand_Success;
4187 }
4188
4189
4190 bool haveEaten = false;
4191 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004192 if (Tok.is(AsmToken::Plus)) {
4193 Parser.Lex(); // Eat the '+' token.
4194 haveEaten = true;
4195 } else if (Tok.is(AsmToken::Minus)) {
4196 Parser.Lex(); // Eat the '-' token.
4197 isAdd = false;
4198 haveEaten = true;
4199 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004200
4201 Tok = Parser.getTok();
4202 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004203 if (Reg == -1) {
4204 if (!haveEaten)
4205 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004206 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004207 return MatchOperand_ParseFail;
4208 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004209
4210 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004211 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004212
4213 return MatchOperand_Success;
4214}
4215
Tim Northovereb5e4d52013-07-22 09:06:12 +00004216/// Convert parsed operands to MCInst. Needed here because this instruction
4217/// only has two register operands, but multiplication is commutative so
4218/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004219void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004220cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004221 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004222 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4223 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004224 // If we have a three-operand form, make sure to set Rn to be the operand
4225 // that isn't the same as Rd.
4226 unsigned RegOp = 4;
4227 if (Operands.size() == 6 &&
4228 ((ARMOperand*)Operands[4])->getReg() ==
4229 ((ARMOperand*)Operands[3])->getReg())
4230 RegOp = 5;
4231 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4232 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004233 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004234}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004235
Mihai Popaad18d3c2013-08-09 10:38:32 +00004236void ARMAsmParser::
4237cvtThumbBranches(MCInst &Inst,
4238 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4239 int CondOp = -1, ImmOp = -1;
4240 switch(Inst.getOpcode()) {
4241 case ARM::tB:
4242 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4243
4244 case ARM::t2B:
4245 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4246
4247 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4248 }
4249 // first decide whether or not the branch should be conditional
4250 // by looking at it's location relative to an IT block
4251 if(inITBlock()) {
4252 // inside an IT block we cannot have any conditional branches. any
4253 // such instructions needs to be converted to unconditional form
4254 switch(Inst.getOpcode()) {
4255 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4256 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4257 }
4258 } else {
4259 // outside IT blocks we can only have unconditional branches with AL
4260 // condition code or conditional branches with non-AL condition code
4261 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4262 switch(Inst.getOpcode()) {
4263 case ARM::tB:
4264 case ARM::tBcc:
4265 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4266 break;
4267 case ARM::t2B:
4268 case ARM::t2Bcc:
4269 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4270 break;
4271 }
4272 }
4273
4274 // now decide on encoding size based on branch target range
4275 switch(Inst.getOpcode()) {
4276 // classify tB as either t2B or t1B based on range of immediate operand
4277 case ARM::tB: {
4278 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4279 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4280 Inst.setOpcode(ARM::t2B);
4281 break;
4282 }
4283 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4284 case ARM::tBcc: {
4285 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4286 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4287 Inst.setOpcode(ARM::t2Bcc);
4288 break;
4289 }
4290 }
4291 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4292 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4293}
4294
Bill Wendlinge18980a2010-11-06 22:36:58 +00004295/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004296/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004297bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004298parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004299 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004300 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004301 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004302 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004303 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004304
Sean Callanan936b0d32010-01-19 21:44:56 +00004305 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004306 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004307 if (BaseRegNum == -1)
4308 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004309
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004310 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004311 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004312 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4313 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004314 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004315
Jim Grosbachd3595712011-08-03 23:50:40 +00004316 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004317 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004318 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004319
Jim Grosbachd3595712011-08-03 23:50:40 +00004320 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004321 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004322
Jim Grosbach40700e02011-09-19 18:42:21 +00004323 // If there's a pre-indexing writeback marker, '!', just add it as a token
4324 // operand. It's rather odd, but syntactically valid.
4325 if (Parser.getTok().is(AsmToken::Exclaim)) {
4326 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4327 Parser.Lex(); // Eat the '!'.
4328 }
4329
Jim Grosbachd3595712011-08-03 23:50:40 +00004330 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004331 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004332
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004333 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4334 "Lost colon or comma in memory operand?!");
4335 if (Tok.is(AsmToken::Comma)) {
4336 Parser.Lex(); // Eat the comma.
4337 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004338
Jim Grosbacha95ec992011-10-11 17:29:55 +00004339 // If we have a ':', it's an alignment specifier.
4340 if (Parser.getTok().is(AsmToken::Colon)) {
4341 Parser.Lex(); // Eat the ':'.
4342 E = Parser.getTok().getLoc();
4343
4344 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004345 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004346 return true;
4347
4348 // The expression has to be a constant. Memory references with relocations
4349 // don't come through here, as they use the <label> forms of the relevant
4350 // instructions.
4351 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4352 if (!CE)
4353 return Error (E, "constant expression expected");
4354
4355 unsigned Align = 0;
4356 switch (CE->getValue()) {
4357 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004358 return Error(E,
4359 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4360 case 16: Align = 2; break;
4361 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004362 case 64: Align = 8; break;
4363 case 128: Align = 16; break;
4364 case 256: Align = 32; break;
4365 }
4366
4367 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004368 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004369 return Error(Parser.getTok().getLoc(), "']' expected");
4370 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004371 Parser.Lex(); // Eat right bracket token.
4372
4373 // Don't worry about range checking the value here. That's handled by
4374 // the is*() predicates.
4375 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4376 ARM_AM::no_shift, 0, Align,
4377 false, S, E));
4378
4379 // If there's a pre-indexing writeback marker, '!', just add it as a token
4380 // operand.
4381 if (Parser.getTok().is(AsmToken::Exclaim)) {
4382 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4383 Parser.Lex(); // Eat the '!'.
4384 }
4385
4386 return false;
4387 }
4388
4389 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004390 // offset. Be friendly and also accept a plain integer (without a leading
4391 // hash) for gas compatibility.
4392 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004393 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004394 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004395 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004396 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004397 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004398
Owen Anderson967674d2011-08-29 19:36:44 +00004399 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004400 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004401 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004402 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004403
4404 // The expression has to be a constant. Memory references with relocations
4405 // don't come through here, as they use the <label> forms of the relevant
4406 // instructions.
4407 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4408 if (!CE)
4409 return Error (E, "constant expression expected");
4410
Owen Anderson967674d2011-08-29 19:36:44 +00004411 // If the constant was #-0, represent it as INT32_MIN.
4412 int32_t Val = CE->getValue();
4413 if (isNegative && Val == 0)
4414 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4415
Jim Grosbachd3595712011-08-03 23:50:40 +00004416 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004417 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004418 return Error(Parser.getTok().getLoc(), "']' expected");
4419 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004420 Parser.Lex(); // Eat right bracket token.
4421
4422 // Don't worry about range checking the value here. That's handled by
4423 // the is*() predicates.
4424 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004425 ARM_AM::no_shift, 0, 0,
4426 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004427
4428 // If there's a pre-indexing writeback marker, '!', just add it as a token
4429 // operand.
4430 if (Parser.getTok().is(AsmToken::Exclaim)) {
4431 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4432 Parser.Lex(); // Eat the '!'.
4433 }
4434
4435 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004436 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004437
4438 // The register offset is optionally preceded by a '+' or '-'
4439 bool isNegative = false;
4440 if (Parser.getTok().is(AsmToken::Minus)) {
4441 isNegative = true;
4442 Parser.Lex(); // Eat the '-'.
4443 } else if (Parser.getTok().is(AsmToken::Plus)) {
4444 // Nothing to do.
4445 Parser.Lex(); // Eat the '+'.
4446 }
4447
4448 E = Parser.getTok().getLoc();
4449 int OffsetRegNum = tryParseRegister();
4450 if (OffsetRegNum == -1)
4451 return Error(E, "register expected");
4452
4453 // If there's a shift operator, handle it.
4454 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004455 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004456 if (Parser.getTok().is(AsmToken::Comma)) {
4457 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004458 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004459 return true;
4460 }
4461
4462 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004463 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004464 return Error(Parser.getTok().getLoc(), "']' expected");
4465 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004466 Parser.Lex(); // Eat right bracket token.
4467
4468 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004469 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004470 S, E));
4471
Jim Grosbachc320c852011-08-05 21:28:30 +00004472 // If there's a pre-indexing writeback marker, '!', just add it as a token
4473 // operand.
4474 if (Parser.getTok().is(AsmToken::Exclaim)) {
4475 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4476 Parser.Lex(); // Eat the '!'.
4477 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004478
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004479 return false;
4480}
4481
Jim Grosbachd3595712011-08-03 23:50:40 +00004482/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004483/// ( lsl | lsr | asr | ror ) , # shift_amount
4484/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004485/// return true if it parses a shift otherwise it returns false.
4486bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4487 unsigned &Amount) {
4488 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004489 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004490 if (Tok.isNot(AsmToken::Identifier))
4491 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004492 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004493 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4494 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004495 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004496 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004497 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004498 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004499 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004500 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004501 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004502 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004503 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004504 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004505 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004506 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004507
Jim Grosbachd3595712011-08-03 23:50:40 +00004508 // rrx stands alone.
4509 Amount = 0;
4510 if (St != ARM_AM::rrx) {
4511 Loc = Parser.getTok().getLoc();
4512 // A '#' and a shift amount.
4513 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004514 if (HashTok.isNot(AsmToken::Hash) &&
4515 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004516 return Error(HashTok.getLoc(), "'#' expected");
4517 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004518
Jim Grosbachd3595712011-08-03 23:50:40 +00004519 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004520 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004521 return true;
4522 // Range check the immediate.
4523 // lsl, ror: 0 <= imm <= 31
4524 // lsr, asr: 0 <= imm <= 32
4525 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4526 if (!CE)
4527 return Error(Loc, "shift amount must be an immediate");
4528 int64_t Imm = CE->getValue();
4529 if (Imm < 0 ||
4530 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4531 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4532 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004533 // If <ShiftTy> #0, turn it into a no_shift.
4534 if (Imm == 0)
4535 St = ARM_AM::lsl;
4536 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4537 if (Imm == 32)
4538 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004539 Amount = Imm;
4540 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004541
4542 return false;
4543}
4544
Jim Grosbache7fbce72011-10-03 23:38:36 +00004545/// parseFPImm - A floating point immediate expression operand.
4546ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4547parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004548 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004549 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004550 // integer only.
4551 //
4552 // This routine still creates a generic Immediate operand, containing
4553 // a bitcast of the 64-bit floating point value. The various operands
4554 // that accept floats can check whether the value is valid for them
4555 // via the standard is*() predicates.
4556
Jim Grosbache7fbce72011-10-03 23:38:36 +00004557 SMLoc S = Parser.getTok().getLoc();
4558
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004559 if (Parser.getTok().isNot(AsmToken::Hash) &&
4560 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004561 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004562
4563 // Disambiguate the VMOV forms that can accept an FP immediate.
4564 // vmov.f32 <sreg>, #imm
4565 // vmov.f64 <dreg>, #imm
4566 // vmov.f32 <dreg>, #imm @ vector f32x2
4567 // vmov.f32 <qreg>, #imm @ vector f32x4
4568 //
4569 // There are also the NEON VMOV instructions which expect an
4570 // integer constant. Make sure we don't try to parse an FPImm
4571 // for these:
4572 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4573 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4574 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4575 TyOp->getToken() != ".f64"))
4576 return MatchOperand_NoMatch;
4577
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004578 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004579
4580 // Handle negation, as that still comes through as a separate token.
4581 bool isNegative = false;
4582 if (Parser.getTok().is(AsmToken::Minus)) {
4583 isNegative = true;
4584 Parser.Lex();
4585 }
4586 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004587 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004588 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004589 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004590 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4591 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004592 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004593 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004594 Operands.push_back(ARMOperand::CreateImm(
4595 MCConstantExpr::Create(IntVal, getContext()),
4596 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004597 return MatchOperand_Success;
4598 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004599 // Also handle plain integers. Instructions which allow floating point
4600 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004601 if (Tok.is(AsmToken::Integer)) {
4602 int64_t Val = Tok.getIntVal();
4603 Parser.Lex(); // Eat the token.
4604 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004605 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004606 return MatchOperand_ParseFail;
4607 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004608 double RealVal = ARM_AM::getFPImmFloat(Val);
4609 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4610 Operands.push_back(ARMOperand::CreateImm(
4611 MCConstantExpr::Create(Val, getContext()), S,
4612 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004613 return MatchOperand_Success;
4614 }
4615
Jim Grosbach235c8d22012-01-19 02:47:30 +00004616 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004617 return MatchOperand_ParseFail;
4618}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004619
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004620/// Parse a arm instruction operand. For now this parses the operand regardless
4621/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004622bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004623 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004624 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004625
4626 // Check if the current operand has a custom associated parser, if so, try to
4627 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004628 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4629 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004630 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004631 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4632 // there was a match, but an error occurred, in which case, just return that
4633 // the operand parsing failed.
4634 if (ResTy == MatchOperand_ParseFail)
4635 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004636
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004637 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004638 default:
4639 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004640 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004641 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004642 // If we've seen a branch mnemonic, the next operand must be a label. This
4643 // is true even if the label is a register name. So "br r1" means branch to
4644 // label "r1".
4645 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4646 if (!ExpectLabel) {
4647 if (!tryParseRegisterWithWriteBack(Operands))
4648 return false;
4649 int Res = tryParseShiftRegister(Operands);
4650 if (Res == 0) // success
4651 return false;
4652 else if (Res == -1) // irrecoverable error
4653 return true;
4654 // If this is VMRS, check for the apsr_nzcv operand.
4655 if (Mnemonic == "vmrs" &&
4656 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4657 S = Parser.getTok().getLoc();
4658 Parser.Lex();
4659 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4660 return false;
4661 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004662 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004663
4664 // Fall though for the Identifier case that is not a register or a
4665 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004666 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004667 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004668 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004669 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004670 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004671 // This was not a register so parse other operands that start with an
4672 // identifier (like labels) as expressions and create them as immediates.
4673 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004674 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004675 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004676 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004677 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004678 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4679 return false;
4680 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004681 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004682 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004683 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004684 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004685 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004686 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004687 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004688 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004689 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004690
4691 if (Parser.getTok().isNot(AsmToken::Colon)) {
4692 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4693 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004694 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004695 return true;
4696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4697 if (CE) {
4698 int32_t Val = CE->getValue();
4699 if (isNegative && Val == 0)
4700 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4701 }
4702 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4703 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004704
4705 // There can be a trailing '!' on operands that we want as a separate
4706 // '!' Token operand. Handle that here. For example, the compatibilty
4707 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4708 if (Parser.getTok().is(AsmToken::Exclaim)) {
4709 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4710 Parser.getTok().getLoc()));
4711 Parser.Lex(); // Eat exclaim token
4712 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004713 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004714 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004715 // w/ a ':' after the '#', it's just like a plain ':'.
4716 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004717 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004718 case AsmToken::Colon: {
4719 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004720 // FIXME: Check it's an expression prefix,
4721 // e.g. (FOO - :lower16:BAR) isn't legal.
4722 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004723 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004724 return true;
4725
Evan Cheng965b3c72011-01-13 07:58:56 +00004726 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004727 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004728 return true;
4729
Evan Cheng965b3c72011-01-13 07:58:56 +00004730 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004731 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004732 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004733 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004734 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004735 }
David Peixottoe407d092013-12-19 18:12:36 +00004736 case AsmToken::Equal: {
4737 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4738 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4739
4740 const MCSection *Section =
4741 getParser().getStreamer().getCurrentSection().first;
4742 assert(Section);
4743 Parser.Lex(); // Eat '='
4744 const MCExpr *SubExprVal;
4745 if (getParser().parseExpression(SubExprVal))
4746 return true;
4747 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4748
4749 const MCExpr *CPLoc =
4750 getOrCreateConstantPool(Section).addEntry(SubExprVal, getContext());
4751 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4752 return false;
4753 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004754 }
4755}
4756
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004757// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004758// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004759bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004760 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004761
4762 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004763 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004764 Parser.Lex(); // Eat ':'
4765
4766 if (getLexer().isNot(AsmToken::Identifier)) {
4767 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4768 return true;
4769 }
4770
4771 StringRef IDVal = Parser.getTok().getIdentifier();
4772 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004773 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004774 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004775 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004776 } else {
4777 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4778 return true;
4779 }
4780 Parser.Lex();
4781
4782 if (getLexer().isNot(AsmToken::Colon)) {
4783 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4784 return true;
4785 }
4786 Parser.Lex(); // Eat the last ':'
4787 return false;
4788}
4789
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004790/// \brief Given a mnemonic, split out possible predication code and carry
4791/// setting letters to form a canonical mnemonic and flags.
4792//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004793// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004794// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004795StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004796 unsigned &PredicationCode,
4797 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004798 unsigned &ProcessorIMod,
4799 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004800 PredicationCode = ARMCC::AL;
4801 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004802 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004803
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004804 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004805 //
4806 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004807 if ((Mnemonic == "movs" && isThumb()) ||
4808 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4809 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4810 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4811 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004812 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004813 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4814 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004815 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004816 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004817 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4818 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4819 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004820 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004821
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004822 // First, split out any predication code. Ignore mnemonics we know aren't
4823 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004824 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004825 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004826 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004827 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004828 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4829 .Case("eq", ARMCC::EQ)
4830 .Case("ne", ARMCC::NE)
4831 .Case("hs", ARMCC::HS)
4832 .Case("cs", ARMCC::HS)
4833 .Case("lo", ARMCC::LO)
4834 .Case("cc", ARMCC::LO)
4835 .Case("mi", ARMCC::MI)
4836 .Case("pl", ARMCC::PL)
4837 .Case("vs", ARMCC::VS)
4838 .Case("vc", ARMCC::VC)
4839 .Case("hi", ARMCC::HI)
4840 .Case("ls", ARMCC::LS)
4841 .Case("ge", ARMCC::GE)
4842 .Case("lt", ARMCC::LT)
4843 .Case("gt", ARMCC::GT)
4844 .Case("le", ARMCC::LE)
4845 .Case("al", ARMCC::AL)
4846 .Default(~0U);
4847 if (CC != ~0U) {
4848 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4849 PredicationCode = CC;
4850 }
Bill Wendling193961b2010-10-29 23:50:21 +00004851 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004852
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004853 // Next, determine if we have a carry setting bit. We explicitly ignore all
4854 // the instructions we know end in 's'.
4855 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004856 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004857 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4858 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4859 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004860 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004861 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004862 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004863 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004864 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004865 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004866 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4867 CarrySetting = true;
4868 }
4869
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004870 // The "cps" instruction can have a interrupt mode operand which is glued into
4871 // the mnemonic. Check if this is the case, split it and parse the imod op
4872 if (Mnemonic.startswith("cps")) {
4873 // Split out any imod code.
4874 unsigned IMod =
4875 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4876 .Case("ie", ARM_PROC::IE)
4877 .Case("id", ARM_PROC::ID)
4878 .Default(~0U);
4879 if (IMod != ~0U) {
4880 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4881 ProcessorIMod = IMod;
4882 }
4883 }
4884
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004885 // The "it" instruction has the condition mask on the end of the mnemonic.
4886 if (Mnemonic.startswith("it")) {
4887 ITMask = Mnemonic.slice(2, Mnemonic.size());
4888 Mnemonic = Mnemonic.slice(0, 2);
4889 }
4890
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004891 return Mnemonic;
4892}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004893
4894/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4895/// inclusion of carry set or predication code operands.
4896//
4897// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004898void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00004899getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4900 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004901 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4902 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004903 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004904 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004905 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004906 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004907 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004908 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004909 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004910 Mnemonic == "mla" || Mnemonic == "smlal" ||
4911 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004912 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004913 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004914 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004915
Tim Northover2c45a382013-06-26 16:52:40 +00004916 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4917 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00004918 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004919 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4920 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004921 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4922 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00004923 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4924 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4925 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00004926 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004927 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004928 } else if (!isThumb()) {
4929 // Some instructions are only predicable in Thumb mode
4930 CanAcceptPredicationCode
4931 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4932 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4933 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4934 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4935 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4936 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4937 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4938 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00004939 if (hasV6MOps())
4940 CanAcceptPredicationCode = Mnemonic != "movs";
4941 else
4942 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004943 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004944 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004945}
4946
Jim Grosbach7283da92011-08-16 21:12:37 +00004947bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4948 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004949 // FIXME: This is all horribly hacky. We really need a better way to deal
4950 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004951
4952 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4953 // another does not. Specifically, the MOVW instruction does not. So we
4954 // special case it here and remove the defaulted (non-setting) cc_out
4955 // operand if that's the instruction we're trying to match.
4956 //
4957 // We do this as post-processing of the explicit operands rather than just
4958 // conditionally adding the cc_out in the first place because we need
4959 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004960 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004961 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4962 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4963 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4964 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004965
4966 // Register-register 'add' for thumb does not have a cc_out operand
4967 // when there are only two register operands.
4968 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4969 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4970 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4971 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4972 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004973 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004974 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4975 // have to check the immediate range here since Thumb2 has a variant
4976 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004977 if (((isThumb() && Mnemonic == "add") ||
4978 (isThumbTwo() && Mnemonic == "sub")) &&
4979 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004980 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4981 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4982 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004983 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004984 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004985 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004986 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004987 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4988 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004989 // selecting via the generic "add" mnemonic, so to know that we
4990 // should remove the cc_out operand, we have to explicitly check that
4991 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004992 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4993 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004994 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4995 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4996 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4997 // Nest conditions rather than one big 'if' statement for readability.
4998 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004999 // If both registers are low, we're in an IT block, and the immediate is
5000 // in range, we should use encoding T1 instead, which has a cc_out.
5001 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005002 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005003 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5004 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5005 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005006 // Check against T3. If the second register is the PC, this is an
5007 // alternate form of ADR, which uses encoding T4, so check for that too.
5008 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5009 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5010 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005011
5012 // Otherwise, we use encoding T4, which does not have a cc_out
5013 // operand.
5014 return true;
5015 }
5016
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005017 // The thumb2 multiply instruction doesn't have a CCOut register, so
5018 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5019 // use the 16-bit encoding or not.
5020 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5021 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5022 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5023 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5024 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5025 // If the registers aren't low regs, the destination reg isn't the
5026 // same as one of the source regs, or the cc_out operand is zero
5027 // outside of an IT block, we have to use the 32-bit encoding, so
5028 // remove the cc_out operand.
5029 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5030 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00005031 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005032 !inITBlock() ||
5033 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5034 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5035 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5036 static_cast<ARMOperand*>(Operands[4])->getReg())))
5037 return true;
5038
Jim Grosbachefa7e952011-11-15 19:55:16 +00005039 // Also check the 'mul' syntax variant that doesn't specify an explicit
5040 // destination register.
5041 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5042 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5043 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5044 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5045 // If the registers aren't low regs or the cc_out operand is zero
5046 // outside of an IT block, we have to use the 32-bit encoding, so
5047 // remove the cc_out operand.
5048 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5049 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5050 !inITBlock()))
5051 return true;
5052
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005053
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005054
Jim Grosbach4b701af2011-08-24 21:42:27 +00005055 // Register-register 'add/sub' for thumb does not have a cc_out operand
5056 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5057 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5058 // right, this will result in better diagnostics (which operand is off)
5059 // anyway.
5060 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5061 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005062 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5063 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005064 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5065 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5066 (Operands.size() == 6 &&
5067 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005068 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005069
Jim Grosbach7283da92011-08-16 21:12:37 +00005070 return false;
5071}
5072
Joey Goulye8602552013-07-19 16:34:16 +00005073bool ARMAsmParser::shouldOmitPredicateOperand(
5074 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5075 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5076 unsigned RegIdx = 3;
5077 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5078 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5079 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5080 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5081 RegIdx = 4;
5082
5083 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5084 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5085 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5086 ARMMCRegisterClasses[ARM::QPRRegClassID]
5087 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5088 return true;
5089 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005090 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005091}
5092
Jim Grosbach12952fe2011-11-11 23:08:10 +00005093static bool isDataTypeToken(StringRef Tok) {
5094 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5095 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5096 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5097 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5098 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5099 Tok == ".f" || Tok == ".d";
5100}
5101
5102// FIXME: This bit should probably be handled via an explicit match class
5103// in the .td files that matches the suffix instead of having it be
5104// a literal string token the way it is now.
5105static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5106 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5107}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005108static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5109 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005110/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005111bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5112 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005113 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005114 // Apply mnemonic aliases before doing anything else, as the destination
5115 // mnemnonic may include suffices and we want to handle them normally.
5116 // The generic tblgen'erated code does this later, at the start of
5117 // MatchInstructionImpl(), but that's too late for aliases that include
5118 // any sort of suffix.
5119 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005120 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5121 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005122
Jim Grosbachab5830e2011-12-14 02:16:11 +00005123 // First check for the ARM-specific .req directive.
5124 if (Parser.getTok().is(AsmToken::Identifier) &&
5125 Parser.getTok().getIdentifier() == ".req") {
5126 parseDirectiveReq(Name, NameLoc);
5127 // We always return 'error' for this, as we're done with this
5128 // statement and don't need to match the 'instruction."
5129 return true;
5130 }
5131
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005132 // Create the leading tokens for the mnemonic, split by '.' characters.
5133 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005134 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005135
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005136 // Split out the predication code and carry setting flag from the mnemonic.
5137 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005138 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005139 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005140 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005141 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005142 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005143
Jim Grosbach1c171b12011-08-25 17:23:55 +00005144 // In Thumb1, only the branch (B) instruction can be predicated.
5145 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005146 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005147 return Error(NameLoc, "conditional execution not supported in Thumb1");
5148 }
5149
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005150 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5151
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005152 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5153 // is the mask as it will be for the IT encoding if the conditional
5154 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5155 // where the conditional bit0 is zero, the instruction post-processing
5156 // will adjust the mask accordingly.
5157 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005158 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5159 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005160 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005161 return Error(Loc, "too many conditions on IT instruction");
5162 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005163 unsigned Mask = 8;
5164 for (unsigned i = ITMask.size(); i != 0; --i) {
5165 char pos = ITMask[i - 1];
5166 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005167 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005168 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005169 }
5170 Mask >>= 1;
5171 if (ITMask[i - 1] == 't')
5172 Mask |= 8;
5173 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005174 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005175 }
5176
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005177 // FIXME: This is all a pretty gross hack. We should automatically handle
5178 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005179
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005180 // Next, add the CCOut and ConditionCode operands, if needed.
5181 //
5182 // For mnemonics which can ever incorporate a carry setting bit or predication
5183 // code, our matching model involves us always generating CCOut and
5184 // ConditionCode operands to match the mnemonic "as written" and then we let
5185 // the matcher deal with finding the right instruction or generating an
5186 // appropriate error.
5187 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005188 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005189
Jim Grosbach03a8a162011-07-14 22:04:21 +00005190 // If we had a carry-set on an instruction that can't do that, issue an
5191 // error.
5192 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005193 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005194 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005195 "' can not set flags, but 's' suffix specified");
5196 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005197 // If we had a predication code on an instruction that can't do that, issue an
5198 // error.
5199 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005200 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005201 return Error(NameLoc, "instruction '" + Mnemonic +
5202 "' is not predicable, but condition code specified");
5203 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005204
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005205 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005206 if (CanAcceptCarrySet) {
5207 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005208 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005209 Loc));
5210 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005211
5212 // Add the predication code operand, if necessary.
5213 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005214 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5215 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005216 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005217 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005218 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005219
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005220 // Add the processor imod operand, if necessary.
5221 if (ProcessorIMod) {
5222 Operands.push_back(ARMOperand::CreateImm(
5223 MCConstantExpr::Create(ProcessorIMod, getContext()),
5224 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005225 }
5226
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005227 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005228 while (Next != StringRef::npos) {
5229 Start = Next;
5230 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005231 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005232
Jim Grosbach12952fe2011-11-11 23:08:10 +00005233 // Some NEON instructions have an optional datatype suffix that is
5234 // completely ignored. Check for that.
5235 if (isDataTypeToken(ExtraToken) &&
5236 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5237 continue;
5238
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005239 // For for ARM mode generate an error if the .n qualifier is used.
5240 if (ExtraToken == ".n" && !isThumb()) {
5241 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5242 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5243 "arm mode");
5244 }
5245
5246 // The .n qualifier is always discarded as that is what the tables
5247 // and matcher expect. In ARM mode the .w qualifier has no effect,
5248 // so discard it to avoid errors that can be caused by the matcher.
5249 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005250 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5251 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5252 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005253 }
5254
5255 // Read the remaining operands.
5256 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005257 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005258 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005259 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005260 return true;
5261 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005262
5263 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005264 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005265
5266 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005267 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005268 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005269 return true;
5270 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005271 }
5272 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005273
Chris Lattnera2a9d162010-09-11 16:18:25 +00005274 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005275 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005276 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005277 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005278 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005279
Chris Lattner91689c12010-09-08 05:10:46 +00005280 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005281
Jim Grosbach7283da92011-08-16 21:12:37 +00005282 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5283 // do and don't have a cc_out optional-def operand. With some spot-checks
5284 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005285 // parse and adjust accordingly before actually matching. We shouldn't ever
5286 // try to remove a cc_out operand that was explicitly set on the the
5287 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5288 // table driven matcher doesn't fit well with the ARM instruction set.
5289 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005290 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5291 Operands.erase(Operands.begin() + 1);
5292 delete Op;
5293 }
5294
Joey Goulye8602552013-07-19 16:34:16 +00005295 // Some instructions have the same mnemonic, but don't always
5296 // have a predicate. Distinguish them here and delete the
5297 // predicate if needed.
5298 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5299 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5300 Operands.erase(Operands.begin() + 1);
5301 delete Op;
5302 }
5303
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005304 // ARM mode 'blx' need special handling, as the register operand version
5305 // is predicable, but the label operand version is not. So, we can't rely
5306 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005307 // a k_CondCode operand in the list. If we're trying to match the label
5308 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005309 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5310 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5311 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5312 Operands.erase(Operands.begin() + 1);
5313 delete Op;
5314 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005315
Weiming Zhao8f56f882012-11-16 21:55:34 +00005316 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5317 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5318 // a single GPRPair reg operand is used in the .td file to replace the two
5319 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5320 // expressed as a GPRPair, so we have to manually merge them.
5321 // FIXME: We would really like to be able to tablegen'erate this.
5322 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005323 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5324 Mnemonic == "stlexd")) {
5325 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005326 unsigned Idx = isLoad ? 2 : 3;
5327 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5328 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5329
5330 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5331 // Adjust only if Op1 and Op2 are GPRs.
5332 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5333 MRC.contains(Op2->getReg())) {
5334 unsigned Reg1 = Op1->getReg();
5335 unsigned Reg2 = Op2->getReg();
5336 unsigned Rt = MRI->getEncodingValue(Reg1);
5337 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5338
5339 // Rt2 must be Rt + 1 and Rt must be even.
5340 if (Rt + 1 != Rt2 || (Rt & 1)) {
5341 Error(Op2->getStartLoc(), isLoad ?
5342 "destination operands must be sequential" :
5343 "source operands must be sequential");
5344 return true;
5345 }
5346 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5347 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5348 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5349 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5350 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5351 delete Op1;
5352 delete Op2;
5353 }
5354 }
5355
Kevin Enderby78f95722013-07-31 21:05:30 +00005356 // FIXME: As said above, this is all a pretty gross hack. This instruction
5357 // does not fit with other "subs" and tblgen.
5358 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5359 // so the Mnemonic is the original name "subs" and delete the predicate
5360 // operand so it will match the table entry.
5361 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5362 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5363 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5364 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5365 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5366 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5367 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5368 Operands.erase(Operands.begin());
5369 delete Op0;
5370 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5371
5372 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5373 Operands.erase(Operands.begin() + 1);
5374 delete Op1;
5375 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005376 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005377}
5378
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005379// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005380
5381// return 'true' if register list contains non-low GPR registers,
5382// 'false' otherwise. If Reg is in the register list or is HiReg, set
5383// 'containsReg' to true.
5384static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5385 unsigned HiReg, bool &containsReg) {
5386 containsReg = false;
5387 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5388 unsigned OpReg = Inst.getOperand(i).getReg();
5389 if (OpReg == Reg)
5390 containsReg = true;
5391 // Anything other than a low register isn't legal here.
5392 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5393 return true;
5394 }
5395 return false;
5396}
5397
Jim Grosbacha31f2232011-09-07 18:05:34 +00005398// Check if the specified regisgter is in the register list of the inst,
5399// starting at the indicated operand number.
5400static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5401 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5402 unsigned OpReg = Inst.getOperand(i).getReg();
5403 if (OpReg == Reg)
5404 return true;
5405 }
5406 return false;
5407}
5408
Richard Barton8d519fe2013-09-05 14:14:19 +00005409// Return true if instruction has the interesting property of being
5410// allowed in IT blocks, but not being predicable.
5411static bool instIsBreakpoint(const MCInst &Inst) {
5412 return Inst.getOpcode() == ARM::tBKPT ||
5413 Inst.getOpcode() == ARM::BKPT ||
5414 Inst.getOpcode() == ARM::tHLT ||
5415 Inst.getOpcode() == ARM::HLT;
5416
5417}
5418
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005419// FIXME: We would really like to be able to tablegen'erate this.
5420bool ARMAsmParser::
5421validateInstruction(MCInst &Inst,
5422 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005423 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005424 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005425
Jim Grosbached16ec42011-08-29 22:24:09 +00005426 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005427 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005428 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005429 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005430 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005431 if (ITState.FirstCond)
5432 ITState.FirstCond = false;
5433 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005434 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005435 // The instruction must be predicable.
5436 if (!MCID.isPredicable())
5437 return Error(Loc, "instructions in IT block must be predicable");
5438 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005439 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005440 ARMCC::getOppositeCondition(ITState.Cond);
5441 if (Cond != ITCond) {
5442 // Find the condition code Operand to get its SMLoc information.
5443 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005444 for (unsigned I = 1; I < Operands.size(); ++I)
5445 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5446 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005447 return Error(CondLoc, "incorrect condition in IT block; got '" +
5448 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5449 "', but expected '" +
5450 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5451 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005452 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005453 } else if (isThumbTwo() && MCID.isPredicable() &&
5454 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005455 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5456 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005457 return Error(Loc, "predicated instructions must be in IT block");
5458
Tilmann Scheller255722b2013-09-30 16:11:48 +00005459 const unsigned Opcode = Inst.getOpcode();
5460 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005461 case ARM::LDRD:
5462 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005463 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005464 const unsigned RtReg = Inst.getOperand(0).getReg();
5465
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005466 // Rt can't be R14.
5467 if (RtReg == ARM::LR)
5468 return Error(Operands[3]->getStartLoc(),
5469 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005470
5471 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005472 // Rt must be even-numbered.
5473 if ((Rt & 1) == 1)
5474 return Error(Operands[3]->getStartLoc(),
5475 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005476
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005477 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005478 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005479 if (Rt2 != Rt + 1)
5480 return Error(Operands[3]->getStartLoc(),
5481 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005482
5483 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5484 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5485 // For addressing modes with writeback, the base register needs to be
5486 // different from the destination registers.
5487 if (Rn == Rt || Rn == Rt2)
5488 return Error(Operands[3]->getStartLoc(),
5489 "base register needs to be different from destination "
5490 "registers");
5491 }
5492
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005493 return false;
5494 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005495 case ARM::t2LDRDi8:
5496 case ARM::t2LDRD_PRE:
5497 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005498 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005499 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5500 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5501 if (Rt2 == Rt)
5502 return Error(Operands[3]->getStartLoc(),
5503 "destination operands can't be identical");
5504 return false;
5505 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005506 case ARM::STRD: {
5507 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005508 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5509 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005510 if (Rt2 != Rt + 1)
5511 return Error(Operands[3]->getStartLoc(),
5512 "source operands must be sequential");
5513 return false;
5514 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005515 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005516 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005517 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005518 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5519 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005520 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005521 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005522 "source operands must be sequential");
5523 return false;
5524 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005525 case ARM::SBFX:
5526 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005527 // Width must be in range [1, 32-lsb].
5528 unsigned LSB = Inst.getOperand(2).getImm();
5529 unsigned Widthm1 = Inst.getOperand(3).getImm();
5530 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005531 return Error(Operands[5]->getStartLoc(),
5532 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005533 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005534 }
Tim Northover08a86602013-10-22 19:00:39 +00005535 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005536 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005537 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005538 // most cases that are normally illegal for a Thumb1 LDM instruction.
5539 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005540 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005541 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005542 // in the register list.
5543 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005544 bool HasWritebackToken =
Jim Grosbach139acd22011-08-22 23:01:07 +00005545 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5546 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005547 bool ListContainsBase;
5548 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5549 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005550 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005551 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005552 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005553 return Error(Operands[2]->getStartLoc(),
5554 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005555 // If we should not have writeback, there must not be a '!'. This is
5556 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005557 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005558 return Error(Operands[3]->getStartLoc(),
5559 "writeback operator '!' not allowed when base register "
5560 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005561
5562 break;
5563 }
Tim Northover08a86602013-10-22 19:00:39 +00005564 case ARM::LDMIA_UPD:
5565 case ARM::LDMDB_UPD:
5566 case ARM::LDMIB_UPD:
5567 case ARM::LDMDA_UPD:
5568 // ARM variants loading and updating the same register are only officially
5569 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5570 if (!hasV7Ops())
5571 break;
5572 // Fallthrough
5573 case ARM::t2LDMIA_UPD:
5574 case ARM::t2LDMDB_UPD:
5575 case ARM::t2STMIA_UPD:
5576 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005577 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
Tim Northover741e6ef2013-10-24 09:37:18 +00005578 return Error(Operands.back()->getStartLoc(),
5579 "writeback register not allowed in register list");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005580 break;
5581 }
Tim Northover8eaf1542013-11-12 21:32:41 +00005582 case ARM::sysLDMIA_UPD:
5583 case ARM::sysLDMDA_UPD:
5584 case ARM::sysLDMDB_UPD:
5585 case ARM::sysLDMIB_UPD:
5586 if (!listContainsReg(Inst, 3, ARM::PC))
5587 return Error(Operands[4]->getStartLoc(),
5588 "writeback register only allowed on system LDM "
5589 "if PC in register-list");
5590 break;
5591 case ARM::sysSTMIA_UPD:
5592 case ARM::sysSTMDA_UPD:
5593 case ARM::sysSTMDB_UPD:
5594 case ARM::sysSTMIB_UPD:
5595 return Error(Operands[2]->getStartLoc(),
5596 "system STM cannot have writeback register");
5597 break;
Chad Rosier8513ffb2012-08-30 23:20:38 +00005598 case ARM::tMUL: {
5599 // The second source operand must be the same register as the destination
5600 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005601 //
5602 // In this case, we must directly check the parsed operands because the
5603 // cvtThumbMultiply() function is written in such a way that it guarantees
5604 // this first statement is always true for the new Inst. Essentially, the
5605 // destination is unconditionally copied into the second source operand
5606 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005607 if (Operands.size() == 6 &&
5608 (((ARMOperand*)Operands[3])->getReg() !=
5609 ((ARMOperand*)Operands[5])->getReg()) &&
5610 (((ARMOperand*)Operands[3])->getReg() !=
5611 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005612 return Error(Operands[3]->getStartLoc(),
5613 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005614 }
5615 break;
5616 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005617 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5618 // so only issue a diagnostic for thumb1. The instructions will be
5619 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005620 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005621 bool ListContainsBase;
5622 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005623 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005624 return Error(Operands[2]->getStartLoc(),
5625 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005626 break;
5627 }
5628 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005629 bool ListContainsBase;
5630 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005631 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005632 return Error(Operands[2]->getStartLoc(),
5633 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005634 break;
5635 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005636 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005637 bool ListContainsBase, InvalidLowList;
5638 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5639 0, ListContainsBase);
5640 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005641 return Error(Operands[4]->getStartLoc(),
5642 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005643
5644 // This would be converted to a 32-bit stm, but that's not valid if the
5645 // writeback register is in the list.
5646 if (InvalidLowList && ListContainsBase)
5647 return Error(Operands[4]->getStartLoc(),
5648 "writeback operator '!' not allowed when base register "
5649 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005650 break;
5651 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005652 case ARM::tADDrSP: {
5653 // If the non-SP source operand and the destination operand are not the
5654 // same, we need thumb2 (for the wide encoding), or we have an error.
5655 if (!isThumbTwo() &&
5656 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5657 return Error(Operands[4]->getStartLoc(),
5658 "source register must be the same as destination");
5659 }
5660 break;
5661 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005662 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005663 case ARM::tB:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005664 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5665 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005666 break;
5667 case ARM::t2B: {
5668 int op = (Operands[2]->isImm()) ? 2 : 3;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005669 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5670 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005671 break;
5672 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005673 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005674 case ARM::tBcc:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005675 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5676 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005677 break;
5678 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005679 int Op = (Operands[2]->isImm()) ? 2 : 3;
5680 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5681 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005682 break;
5683 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005684 }
5685
5686 return false;
5687}
5688
Jim Grosbach1a747242012-01-23 23:45:44 +00005689static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005690 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005691 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005692 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005693 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5694 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5695 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5696 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5697 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5698 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5699 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5700 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5701 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005702
5703 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005704 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5705 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5706 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5707 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5708 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005709
Jim Grosbach1e946a42012-01-24 00:43:12 +00005710 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5711 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5712 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5713 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5714 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005715
Jim Grosbach1e946a42012-01-24 00:43:12 +00005716 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5717 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5718 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5719 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5720 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005721
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005722 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005723 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5724 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5725 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5726 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5727 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5728 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5729 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5730 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5731 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5732 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5733 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5734 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5735 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5736 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5737 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005738
Jim Grosbach1a747242012-01-23 23:45:44 +00005739 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005740 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5741 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5742 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5743 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5744 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5745 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5746 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5747 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5748 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5749 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5750 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5751 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5752 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5753 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5754 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5755 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5756 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5757 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005758
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005759 // VST4LN
5760 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5761 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5762 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5763 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5764 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5765 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5766 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5767 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5768 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5769 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5770 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5771 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5772 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5773 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5774 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5775
Jim Grosbachda70eac2012-01-24 00:58:13 +00005776 // VST4
5777 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5778 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5779 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5780 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5781 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5782 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5783 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5784 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5785 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5786 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5787 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5788 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5789 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5790 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5791 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5792 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5793 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5794 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005795 }
5796}
5797
Jim Grosbach1a747242012-01-23 23:45:44 +00005798static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005799 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005800 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005801 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005802 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5803 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5804 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5805 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5806 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5807 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5808 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5809 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5810 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005811
5812 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005813 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5814 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5815 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5816 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5817 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5818 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5819 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5820 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5821 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5822 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5823 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5824 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5825 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5826 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5827 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005828
Jim Grosbachb78403c2012-01-24 23:47:04 +00005829 // VLD3DUP
5830 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5831 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5832 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5833 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5834 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5835 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5836 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5837 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5838 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5839 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5840 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5841 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5842 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5843 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5844 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5845 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5846 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5847 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5848
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005849 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005850 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5851 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5852 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5853 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5854 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5855 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5856 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5857 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5858 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5859 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5860 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5861 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5862 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5863 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5864 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005865
5866 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005867 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5868 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5869 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5870 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5871 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5872 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5873 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5874 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5875 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5876 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5877 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5878 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5879 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5880 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5881 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5882 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5883 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5884 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005885
Jim Grosbach14952a02012-01-24 18:37:25 +00005886 // VLD4LN
5887 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5888 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5889 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5890 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5891 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5892 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5893 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5894 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5895 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5896 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5897 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5898 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5899 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5900 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5901 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5902
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005903 // VLD4DUP
5904 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5905 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5906 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5907 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5908 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5909 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5910 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5911 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5912 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5913 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5914 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5915 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5916 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5917 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5918 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5919 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5920 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5921 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5922
Jim Grosbached561fc2012-01-24 00:43:17 +00005923 // VLD4
5924 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5925 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5926 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5927 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5928 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5929 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5930 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5931 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5932 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5933 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5934 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5935 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5936 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5937 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5938 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5939 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5940 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5941 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005942 }
5943}
5944
Jim Grosbachafad0532011-11-10 23:42:14 +00005945bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005946processInstruction(MCInst &Inst,
5947 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5948 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005949 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5950 case ARM::ADDri: {
5951 if (Inst.getOperand(1).getReg() != ARM::PC ||
5952 Inst.getOperand(5).getReg() != 0)
5953 return false;
5954 MCInst TmpInst;
5955 TmpInst.setOpcode(ARM::ADR);
5956 TmpInst.addOperand(Inst.getOperand(0));
5957 TmpInst.addOperand(Inst.getOperand(2));
5958 TmpInst.addOperand(Inst.getOperand(3));
5959 TmpInst.addOperand(Inst.getOperand(4));
5960 Inst = TmpInst;
5961 return true;
5962 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005963 // Aliases for alternate PC+imm syntax of LDR instructions.
5964 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005965 // Select the narrow version if the immediate will fit.
5966 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005967 Inst.getOperand(1).getImm() <= 0xff &&
5968 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5969 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005970 Inst.setOpcode(ARM::tLDRpci);
5971 else
5972 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005973 return true;
5974 case ARM::t2LDRBpcrel:
5975 Inst.setOpcode(ARM::t2LDRBpci);
5976 return true;
5977 case ARM::t2LDRHpcrel:
5978 Inst.setOpcode(ARM::t2LDRHpci);
5979 return true;
5980 case ARM::t2LDRSBpcrel:
5981 Inst.setOpcode(ARM::t2LDRSBpci);
5982 return true;
5983 case ARM::t2LDRSHpcrel:
5984 Inst.setOpcode(ARM::t2LDRSHpci);
5985 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005986 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005987 case ARM::VST1LNdWB_register_Asm_8:
5988 case ARM::VST1LNdWB_register_Asm_16:
5989 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005990 MCInst TmpInst;
5991 // Shuffle the operands around so the lane index operand is in the
5992 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005993 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005994 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005995 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5996 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5997 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5998 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5999 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6000 TmpInst.addOperand(Inst.getOperand(1)); // lane
6001 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6002 TmpInst.addOperand(Inst.getOperand(6));
6003 Inst = TmpInst;
6004 return true;
6005 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006006
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006007 case ARM::VST2LNdWB_register_Asm_8:
6008 case ARM::VST2LNdWB_register_Asm_16:
6009 case ARM::VST2LNdWB_register_Asm_32:
6010 case ARM::VST2LNqWB_register_Asm_16:
6011 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006012 MCInst TmpInst;
6013 // Shuffle the operands around so the lane index operand is in the
6014 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006015 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006016 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006017 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6018 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6019 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6020 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6021 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006022 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6023 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006024 TmpInst.addOperand(Inst.getOperand(1)); // lane
6025 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6026 TmpInst.addOperand(Inst.getOperand(6));
6027 Inst = TmpInst;
6028 return true;
6029 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006030
6031 case ARM::VST3LNdWB_register_Asm_8:
6032 case ARM::VST3LNdWB_register_Asm_16:
6033 case ARM::VST3LNdWB_register_Asm_32:
6034 case ARM::VST3LNqWB_register_Asm_16:
6035 case ARM::VST3LNqWB_register_Asm_32: {
6036 MCInst TmpInst;
6037 // Shuffle the operands around so the lane index operand is in the
6038 // right place.
6039 unsigned Spacing;
6040 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6041 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6042 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6043 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6044 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6045 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6046 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6047 Spacing));
6048 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6049 Spacing * 2));
6050 TmpInst.addOperand(Inst.getOperand(1)); // lane
6051 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6052 TmpInst.addOperand(Inst.getOperand(6));
6053 Inst = TmpInst;
6054 return true;
6055 }
6056
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006057 case ARM::VST4LNdWB_register_Asm_8:
6058 case ARM::VST4LNdWB_register_Asm_16:
6059 case ARM::VST4LNdWB_register_Asm_32:
6060 case ARM::VST4LNqWB_register_Asm_16:
6061 case ARM::VST4LNqWB_register_Asm_32: {
6062 MCInst TmpInst;
6063 // Shuffle the operands around so the lane index operand is in the
6064 // right place.
6065 unsigned Spacing;
6066 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6067 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6068 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6069 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6070 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6071 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6072 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6073 Spacing));
6074 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6075 Spacing * 2));
6076 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6077 Spacing * 3));
6078 TmpInst.addOperand(Inst.getOperand(1)); // lane
6079 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6080 TmpInst.addOperand(Inst.getOperand(6));
6081 Inst = TmpInst;
6082 return true;
6083 }
6084
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006085 case ARM::VST1LNdWB_fixed_Asm_8:
6086 case ARM::VST1LNdWB_fixed_Asm_16:
6087 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006088 MCInst TmpInst;
6089 // Shuffle the operands around so the lane index operand is in the
6090 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006091 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006092 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006093 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6094 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6095 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6096 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6097 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6098 TmpInst.addOperand(Inst.getOperand(1)); // lane
6099 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6100 TmpInst.addOperand(Inst.getOperand(5));
6101 Inst = TmpInst;
6102 return true;
6103 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006104
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006105 case ARM::VST2LNdWB_fixed_Asm_8:
6106 case ARM::VST2LNdWB_fixed_Asm_16:
6107 case ARM::VST2LNdWB_fixed_Asm_32:
6108 case ARM::VST2LNqWB_fixed_Asm_16:
6109 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006110 MCInst TmpInst;
6111 // Shuffle the operands around so the lane index operand is in the
6112 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006113 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006114 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006115 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6116 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6117 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6118 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6119 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006120 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6121 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006122 TmpInst.addOperand(Inst.getOperand(1)); // lane
6123 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6124 TmpInst.addOperand(Inst.getOperand(5));
6125 Inst = TmpInst;
6126 return true;
6127 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006128
6129 case ARM::VST3LNdWB_fixed_Asm_8:
6130 case ARM::VST3LNdWB_fixed_Asm_16:
6131 case ARM::VST3LNdWB_fixed_Asm_32:
6132 case ARM::VST3LNqWB_fixed_Asm_16:
6133 case ARM::VST3LNqWB_fixed_Asm_32: {
6134 MCInst TmpInst;
6135 // Shuffle the operands around so the lane index operand is in the
6136 // right place.
6137 unsigned Spacing;
6138 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6139 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6140 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6141 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6142 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6143 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6144 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6145 Spacing));
6146 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6147 Spacing * 2));
6148 TmpInst.addOperand(Inst.getOperand(1)); // lane
6149 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6150 TmpInst.addOperand(Inst.getOperand(5));
6151 Inst = TmpInst;
6152 return true;
6153 }
6154
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006155 case ARM::VST4LNdWB_fixed_Asm_8:
6156 case ARM::VST4LNdWB_fixed_Asm_16:
6157 case ARM::VST4LNdWB_fixed_Asm_32:
6158 case ARM::VST4LNqWB_fixed_Asm_16:
6159 case ARM::VST4LNqWB_fixed_Asm_32: {
6160 MCInst TmpInst;
6161 // Shuffle the operands around so the lane index operand is in the
6162 // right place.
6163 unsigned Spacing;
6164 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6165 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6166 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6167 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6168 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6169 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6171 Spacing));
6172 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6173 Spacing * 2));
6174 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6175 Spacing * 3));
6176 TmpInst.addOperand(Inst.getOperand(1)); // lane
6177 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6178 TmpInst.addOperand(Inst.getOperand(5));
6179 Inst = TmpInst;
6180 return true;
6181 }
6182
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006183 case ARM::VST1LNdAsm_8:
6184 case ARM::VST1LNdAsm_16:
6185 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006186 MCInst TmpInst;
6187 // Shuffle the operands around so the lane index operand is in the
6188 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006189 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006190 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006191 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6192 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6193 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6194 TmpInst.addOperand(Inst.getOperand(1)); // lane
6195 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6196 TmpInst.addOperand(Inst.getOperand(5));
6197 Inst = TmpInst;
6198 return true;
6199 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006200
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006201 case ARM::VST2LNdAsm_8:
6202 case ARM::VST2LNdAsm_16:
6203 case ARM::VST2LNdAsm_32:
6204 case ARM::VST2LNqAsm_16:
6205 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006206 MCInst TmpInst;
6207 // Shuffle the operands around so the lane index operand is in the
6208 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006209 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006210 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006211 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6212 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6213 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006214 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6215 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006216 TmpInst.addOperand(Inst.getOperand(1)); // lane
6217 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6218 TmpInst.addOperand(Inst.getOperand(5));
6219 Inst = TmpInst;
6220 return true;
6221 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006222
6223 case ARM::VST3LNdAsm_8:
6224 case ARM::VST3LNdAsm_16:
6225 case ARM::VST3LNdAsm_32:
6226 case ARM::VST3LNqAsm_16:
6227 case ARM::VST3LNqAsm_32: {
6228 MCInst TmpInst;
6229 // Shuffle the operands around so the lane index operand is in the
6230 // right place.
6231 unsigned Spacing;
6232 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6233 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6234 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6235 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6236 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6237 Spacing));
6238 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6239 Spacing * 2));
6240 TmpInst.addOperand(Inst.getOperand(1)); // lane
6241 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6242 TmpInst.addOperand(Inst.getOperand(5));
6243 Inst = TmpInst;
6244 return true;
6245 }
6246
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006247 case ARM::VST4LNdAsm_8:
6248 case ARM::VST4LNdAsm_16:
6249 case ARM::VST4LNdAsm_32:
6250 case ARM::VST4LNqAsm_16:
6251 case ARM::VST4LNqAsm_32: {
6252 MCInst TmpInst;
6253 // Shuffle the operands around so the lane index operand is in the
6254 // right place.
6255 unsigned Spacing;
6256 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6257 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6258 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6259 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6260 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6261 Spacing));
6262 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6263 Spacing * 2));
6264 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6265 Spacing * 3));
6266 TmpInst.addOperand(Inst.getOperand(1)); // lane
6267 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6268 TmpInst.addOperand(Inst.getOperand(5));
6269 Inst = TmpInst;
6270 return true;
6271 }
6272
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006273 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006274 case ARM::VLD1LNdWB_register_Asm_8:
6275 case ARM::VLD1LNdWB_register_Asm_16:
6276 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006277 MCInst TmpInst;
6278 // Shuffle the operands around so the lane index operand is in the
6279 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006280 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006281 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006282 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6283 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6284 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6285 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6286 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6287 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6288 TmpInst.addOperand(Inst.getOperand(1)); // lane
6289 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6290 TmpInst.addOperand(Inst.getOperand(6));
6291 Inst = TmpInst;
6292 return true;
6293 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006294
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006295 case ARM::VLD2LNdWB_register_Asm_8:
6296 case ARM::VLD2LNdWB_register_Asm_16:
6297 case ARM::VLD2LNdWB_register_Asm_32:
6298 case ARM::VLD2LNqWB_register_Asm_16:
6299 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006300 MCInst TmpInst;
6301 // Shuffle the operands around so the lane index operand is in the
6302 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006303 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006304 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006305 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006306 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6307 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006308 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6309 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6310 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6311 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6312 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006313 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6314 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006315 TmpInst.addOperand(Inst.getOperand(1)); // lane
6316 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6317 TmpInst.addOperand(Inst.getOperand(6));
6318 Inst = TmpInst;
6319 return true;
6320 }
6321
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006322 case ARM::VLD3LNdWB_register_Asm_8:
6323 case ARM::VLD3LNdWB_register_Asm_16:
6324 case ARM::VLD3LNdWB_register_Asm_32:
6325 case ARM::VLD3LNqWB_register_Asm_16:
6326 case ARM::VLD3LNqWB_register_Asm_32: {
6327 MCInst TmpInst;
6328 // Shuffle the operands around so the lane index operand is in the
6329 // right place.
6330 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006331 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006332 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6334 Spacing));
6335 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006336 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006337 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6338 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6339 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6340 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6341 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6342 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6343 Spacing));
6344 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006345 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006346 TmpInst.addOperand(Inst.getOperand(1)); // lane
6347 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6348 TmpInst.addOperand(Inst.getOperand(6));
6349 Inst = TmpInst;
6350 return true;
6351 }
6352
Jim Grosbach14952a02012-01-24 18:37:25 +00006353 case ARM::VLD4LNdWB_register_Asm_8:
6354 case ARM::VLD4LNdWB_register_Asm_16:
6355 case ARM::VLD4LNdWB_register_Asm_32:
6356 case ARM::VLD4LNqWB_register_Asm_16:
6357 case ARM::VLD4LNqWB_register_Asm_32: {
6358 MCInst TmpInst;
6359 // Shuffle the operands around so the lane index operand is in the
6360 // right place.
6361 unsigned Spacing;
6362 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6363 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6365 Spacing));
6366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6367 Spacing * 2));
6368 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6369 Spacing * 3));
6370 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6371 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6372 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6373 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6374 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6375 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6376 Spacing));
6377 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6378 Spacing * 2));
6379 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6380 Spacing * 3));
6381 TmpInst.addOperand(Inst.getOperand(1)); // lane
6382 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6383 TmpInst.addOperand(Inst.getOperand(6));
6384 Inst = TmpInst;
6385 return true;
6386 }
6387
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006388 case ARM::VLD1LNdWB_fixed_Asm_8:
6389 case ARM::VLD1LNdWB_fixed_Asm_16:
6390 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006391 MCInst TmpInst;
6392 // Shuffle the operands around so the lane index operand is in the
6393 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006394 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006395 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006396 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6397 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6398 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6399 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6400 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6401 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6402 TmpInst.addOperand(Inst.getOperand(1)); // lane
6403 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6404 TmpInst.addOperand(Inst.getOperand(5));
6405 Inst = TmpInst;
6406 return true;
6407 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006408
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006409 case ARM::VLD2LNdWB_fixed_Asm_8:
6410 case ARM::VLD2LNdWB_fixed_Asm_16:
6411 case ARM::VLD2LNdWB_fixed_Asm_32:
6412 case ARM::VLD2LNqWB_fixed_Asm_16:
6413 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006414 MCInst TmpInst;
6415 // Shuffle the operands around so the lane index operand is in the
6416 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006417 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006418 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006419 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6421 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006422 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6423 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6424 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6425 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6426 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006427 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6428 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006429 TmpInst.addOperand(Inst.getOperand(1)); // lane
6430 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6431 TmpInst.addOperand(Inst.getOperand(5));
6432 Inst = TmpInst;
6433 return true;
6434 }
6435
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006436 case ARM::VLD3LNdWB_fixed_Asm_8:
6437 case ARM::VLD3LNdWB_fixed_Asm_16:
6438 case ARM::VLD3LNdWB_fixed_Asm_32:
6439 case ARM::VLD3LNqWB_fixed_Asm_16:
6440 case ARM::VLD3LNqWB_fixed_Asm_32: {
6441 MCInst TmpInst;
6442 // Shuffle the operands around so the lane index operand is in the
6443 // right place.
6444 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006445 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006446 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6447 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6448 Spacing));
6449 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006450 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006451 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6452 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6453 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6454 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6455 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6456 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6457 Spacing));
6458 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006459 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006460 TmpInst.addOperand(Inst.getOperand(1)); // lane
6461 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6462 TmpInst.addOperand(Inst.getOperand(5));
6463 Inst = TmpInst;
6464 return true;
6465 }
6466
Jim Grosbach14952a02012-01-24 18:37:25 +00006467 case ARM::VLD4LNdWB_fixed_Asm_8:
6468 case ARM::VLD4LNdWB_fixed_Asm_16:
6469 case ARM::VLD4LNdWB_fixed_Asm_32:
6470 case ARM::VLD4LNqWB_fixed_Asm_16:
6471 case ARM::VLD4LNqWB_fixed_Asm_32: {
6472 MCInst TmpInst;
6473 // Shuffle the operands around so the lane index operand is in the
6474 // right place.
6475 unsigned Spacing;
6476 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6477 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6478 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6479 Spacing));
6480 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6481 Spacing * 2));
6482 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6483 Spacing * 3));
6484 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6485 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6486 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6487 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6488 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6489 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6490 Spacing));
6491 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6492 Spacing * 2));
6493 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6494 Spacing * 3));
6495 TmpInst.addOperand(Inst.getOperand(1)); // lane
6496 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6497 TmpInst.addOperand(Inst.getOperand(5));
6498 Inst = TmpInst;
6499 return true;
6500 }
6501
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006502 case ARM::VLD1LNdAsm_8:
6503 case ARM::VLD1LNdAsm_16:
6504 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006505 MCInst TmpInst;
6506 // Shuffle the operands around so the lane index operand is in the
6507 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006508 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006509 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006510 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6511 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6512 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6513 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6514 TmpInst.addOperand(Inst.getOperand(1)); // lane
6515 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6516 TmpInst.addOperand(Inst.getOperand(5));
6517 Inst = TmpInst;
6518 return true;
6519 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006520
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006521 case ARM::VLD2LNdAsm_8:
6522 case ARM::VLD2LNdAsm_16:
6523 case ARM::VLD2LNdAsm_32:
6524 case ARM::VLD2LNqAsm_16:
6525 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006526 MCInst TmpInst;
6527 // Shuffle the operands around so the lane index operand is in the
6528 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006529 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006530 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006531 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6533 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006534 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6535 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6536 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006539 TmpInst.addOperand(Inst.getOperand(1)); // lane
6540 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6541 TmpInst.addOperand(Inst.getOperand(5));
6542 Inst = TmpInst;
6543 return true;
6544 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006545
6546 case ARM::VLD3LNdAsm_8:
6547 case ARM::VLD3LNdAsm_16:
6548 case ARM::VLD3LNdAsm_32:
6549 case ARM::VLD3LNqAsm_16:
6550 case ARM::VLD3LNqAsm_32: {
6551 MCInst TmpInst;
6552 // Shuffle the operands around so the lane index operand is in the
6553 // right place.
6554 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006555 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006556 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6557 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6558 Spacing));
6559 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006560 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006561 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6562 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6563 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6564 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6565 Spacing));
6566 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006567 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006568 TmpInst.addOperand(Inst.getOperand(1)); // lane
6569 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6570 TmpInst.addOperand(Inst.getOperand(5));
6571 Inst = TmpInst;
6572 return true;
6573 }
6574
Jim Grosbach14952a02012-01-24 18:37:25 +00006575 case ARM::VLD4LNdAsm_8:
6576 case ARM::VLD4LNdAsm_16:
6577 case ARM::VLD4LNdAsm_32:
6578 case ARM::VLD4LNqAsm_16:
6579 case ARM::VLD4LNqAsm_32: {
6580 MCInst TmpInst;
6581 // Shuffle the operands around so the lane index operand is in the
6582 // right place.
6583 unsigned Spacing;
6584 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6585 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6586 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6587 Spacing));
6588 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6589 Spacing * 2));
6590 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6591 Spacing * 3));
6592 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6593 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6594 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6596 Spacing));
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6598 Spacing * 2));
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6600 Spacing * 3));
6601 TmpInst.addOperand(Inst.getOperand(1)); // lane
6602 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6603 TmpInst.addOperand(Inst.getOperand(5));
6604 Inst = TmpInst;
6605 return true;
6606 }
6607
Jim Grosbachb78403c2012-01-24 23:47:04 +00006608 // VLD3DUP single 3-element structure to all lanes instructions.
6609 case ARM::VLD3DUPdAsm_8:
6610 case ARM::VLD3DUPdAsm_16:
6611 case ARM::VLD3DUPdAsm_32:
6612 case ARM::VLD3DUPqAsm_8:
6613 case ARM::VLD3DUPqAsm_16:
6614 case ARM::VLD3DUPqAsm_32: {
6615 MCInst TmpInst;
6616 unsigned Spacing;
6617 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6618 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6620 Spacing));
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6622 Spacing * 2));
6623 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6624 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6625 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6626 TmpInst.addOperand(Inst.getOperand(4));
6627 Inst = TmpInst;
6628 return true;
6629 }
6630
6631 case ARM::VLD3DUPdWB_fixed_Asm_8:
6632 case ARM::VLD3DUPdWB_fixed_Asm_16:
6633 case ARM::VLD3DUPdWB_fixed_Asm_32:
6634 case ARM::VLD3DUPqWB_fixed_Asm_8:
6635 case ARM::VLD3DUPqWB_fixed_Asm_16:
6636 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6637 MCInst TmpInst;
6638 unsigned Spacing;
6639 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6640 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6642 Spacing));
6643 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6644 Spacing * 2));
6645 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6646 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6647 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6648 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6649 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6650 TmpInst.addOperand(Inst.getOperand(4));
6651 Inst = TmpInst;
6652 return true;
6653 }
6654
6655 case ARM::VLD3DUPdWB_register_Asm_8:
6656 case ARM::VLD3DUPdWB_register_Asm_16:
6657 case ARM::VLD3DUPdWB_register_Asm_32:
6658 case ARM::VLD3DUPqWB_register_Asm_8:
6659 case ARM::VLD3DUPqWB_register_Asm_16:
6660 case ARM::VLD3DUPqWB_register_Asm_32: {
6661 MCInst TmpInst;
6662 unsigned Spacing;
6663 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6664 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6666 Spacing));
6667 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6668 Spacing * 2));
6669 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6670 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6671 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6672 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6673 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6674 TmpInst.addOperand(Inst.getOperand(5));
6675 Inst = TmpInst;
6676 return true;
6677 }
6678
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006679 // VLD3 multiple 3-element structure instructions.
6680 case ARM::VLD3dAsm_8:
6681 case ARM::VLD3dAsm_16:
6682 case ARM::VLD3dAsm_32:
6683 case ARM::VLD3qAsm_8:
6684 case ARM::VLD3qAsm_16:
6685 case ARM::VLD3qAsm_32: {
6686 MCInst TmpInst;
6687 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006688 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006689 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6690 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6691 Spacing));
6692 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6693 Spacing * 2));
6694 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6695 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6696 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6697 TmpInst.addOperand(Inst.getOperand(4));
6698 Inst = TmpInst;
6699 return true;
6700 }
6701
6702 case ARM::VLD3dWB_fixed_Asm_8:
6703 case ARM::VLD3dWB_fixed_Asm_16:
6704 case ARM::VLD3dWB_fixed_Asm_32:
6705 case ARM::VLD3qWB_fixed_Asm_8:
6706 case ARM::VLD3qWB_fixed_Asm_16:
6707 case ARM::VLD3qWB_fixed_Asm_32: {
6708 MCInst TmpInst;
6709 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006710 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006711 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6712 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6713 Spacing));
6714 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6715 Spacing * 2));
6716 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6717 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6718 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6719 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6720 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6721 TmpInst.addOperand(Inst.getOperand(4));
6722 Inst = TmpInst;
6723 return true;
6724 }
6725
6726 case ARM::VLD3dWB_register_Asm_8:
6727 case ARM::VLD3dWB_register_Asm_16:
6728 case ARM::VLD3dWB_register_Asm_32:
6729 case ARM::VLD3qWB_register_Asm_8:
6730 case ARM::VLD3qWB_register_Asm_16:
6731 case ARM::VLD3qWB_register_Asm_32: {
6732 MCInst TmpInst;
6733 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006734 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006735 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6736 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6737 Spacing));
6738 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6739 Spacing * 2));
6740 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6741 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6742 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6743 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6744 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6745 TmpInst.addOperand(Inst.getOperand(5));
6746 Inst = TmpInst;
6747 return true;
6748 }
6749
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006750 // VLD4DUP single 3-element structure to all lanes instructions.
6751 case ARM::VLD4DUPdAsm_8:
6752 case ARM::VLD4DUPdAsm_16:
6753 case ARM::VLD4DUPdAsm_32:
6754 case ARM::VLD4DUPqAsm_8:
6755 case ARM::VLD4DUPqAsm_16:
6756 case ARM::VLD4DUPqAsm_32: {
6757 MCInst TmpInst;
6758 unsigned Spacing;
6759 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6760 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6761 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6762 Spacing));
6763 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6764 Spacing * 2));
6765 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6766 Spacing * 3));
6767 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6768 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6769 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6770 TmpInst.addOperand(Inst.getOperand(4));
6771 Inst = TmpInst;
6772 return true;
6773 }
6774
6775 case ARM::VLD4DUPdWB_fixed_Asm_8:
6776 case ARM::VLD4DUPdWB_fixed_Asm_16:
6777 case ARM::VLD4DUPdWB_fixed_Asm_32:
6778 case ARM::VLD4DUPqWB_fixed_Asm_8:
6779 case ARM::VLD4DUPqWB_fixed_Asm_16:
6780 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6781 MCInst TmpInst;
6782 unsigned Spacing;
6783 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6784 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6786 Spacing));
6787 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6788 Spacing * 2));
6789 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6790 Spacing * 3));
6791 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6792 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6793 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6794 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6795 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6796 TmpInst.addOperand(Inst.getOperand(4));
6797 Inst = TmpInst;
6798 return true;
6799 }
6800
6801 case ARM::VLD4DUPdWB_register_Asm_8:
6802 case ARM::VLD4DUPdWB_register_Asm_16:
6803 case ARM::VLD4DUPdWB_register_Asm_32:
6804 case ARM::VLD4DUPqWB_register_Asm_8:
6805 case ARM::VLD4DUPqWB_register_Asm_16:
6806 case ARM::VLD4DUPqWB_register_Asm_32: {
6807 MCInst TmpInst;
6808 unsigned Spacing;
6809 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6810 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6811 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6812 Spacing));
6813 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6814 Spacing * 2));
6815 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6816 Spacing * 3));
6817 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6818 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6819 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6820 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6821 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6822 TmpInst.addOperand(Inst.getOperand(5));
6823 Inst = TmpInst;
6824 return true;
6825 }
6826
6827 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006828 case ARM::VLD4dAsm_8:
6829 case ARM::VLD4dAsm_16:
6830 case ARM::VLD4dAsm_32:
6831 case ARM::VLD4qAsm_8:
6832 case ARM::VLD4qAsm_16:
6833 case ARM::VLD4qAsm_32: {
6834 MCInst TmpInst;
6835 unsigned Spacing;
6836 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6837 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6838 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6839 Spacing));
6840 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6841 Spacing * 2));
6842 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6843 Spacing * 3));
6844 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6845 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6846 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6847 TmpInst.addOperand(Inst.getOperand(4));
6848 Inst = TmpInst;
6849 return true;
6850 }
6851
6852 case ARM::VLD4dWB_fixed_Asm_8:
6853 case ARM::VLD4dWB_fixed_Asm_16:
6854 case ARM::VLD4dWB_fixed_Asm_32:
6855 case ARM::VLD4qWB_fixed_Asm_8:
6856 case ARM::VLD4qWB_fixed_Asm_16:
6857 case ARM::VLD4qWB_fixed_Asm_32: {
6858 MCInst TmpInst;
6859 unsigned Spacing;
6860 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6861 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6862 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6863 Spacing));
6864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6865 Spacing * 2));
6866 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6867 Spacing * 3));
6868 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6869 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6870 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6871 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6872 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6873 TmpInst.addOperand(Inst.getOperand(4));
6874 Inst = TmpInst;
6875 return true;
6876 }
6877
6878 case ARM::VLD4dWB_register_Asm_8:
6879 case ARM::VLD4dWB_register_Asm_16:
6880 case ARM::VLD4dWB_register_Asm_32:
6881 case ARM::VLD4qWB_register_Asm_8:
6882 case ARM::VLD4qWB_register_Asm_16:
6883 case ARM::VLD4qWB_register_Asm_32: {
6884 MCInst TmpInst;
6885 unsigned Spacing;
6886 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6887 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6888 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6889 Spacing));
6890 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6891 Spacing * 2));
6892 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6893 Spacing * 3));
6894 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6895 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6896 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6897 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6898 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6899 TmpInst.addOperand(Inst.getOperand(5));
6900 Inst = TmpInst;
6901 return true;
6902 }
6903
Jim Grosbach1a747242012-01-23 23:45:44 +00006904 // VST3 multiple 3-element structure instructions.
6905 case ARM::VST3dAsm_8:
6906 case ARM::VST3dAsm_16:
6907 case ARM::VST3dAsm_32:
6908 case ARM::VST3qAsm_8:
6909 case ARM::VST3qAsm_16:
6910 case ARM::VST3qAsm_32: {
6911 MCInst TmpInst;
6912 unsigned Spacing;
6913 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6914 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6915 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6916 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6917 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6918 Spacing));
6919 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6920 Spacing * 2));
6921 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6922 TmpInst.addOperand(Inst.getOperand(4));
6923 Inst = TmpInst;
6924 return true;
6925 }
6926
6927 case ARM::VST3dWB_fixed_Asm_8:
6928 case ARM::VST3dWB_fixed_Asm_16:
6929 case ARM::VST3dWB_fixed_Asm_32:
6930 case ARM::VST3qWB_fixed_Asm_8:
6931 case ARM::VST3qWB_fixed_Asm_16:
6932 case ARM::VST3qWB_fixed_Asm_32: {
6933 MCInst TmpInst;
6934 unsigned Spacing;
6935 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6936 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6937 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6938 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6939 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6940 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6941 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6942 Spacing));
6943 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6944 Spacing * 2));
6945 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6946 TmpInst.addOperand(Inst.getOperand(4));
6947 Inst = TmpInst;
6948 return true;
6949 }
6950
6951 case ARM::VST3dWB_register_Asm_8:
6952 case ARM::VST3dWB_register_Asm_16:
6953 case ARM::VST3dWB_register_Asm_32:
6954 case ARM::VST3qWB_register_Asm_8:
6955 case ARM::VST3qWB_register_Asm_16:
6956 case ARM::VST3qWB_register_Asm_32: {
6957 MCInst TmpInst;
6958 unsigned Spacing;
6959 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6960 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6961 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6962 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6963 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6964 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6965 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6966 Spacing));
6967 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6968 Spacing * 2));
6969 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6970 TmpInst.addOperand(Inst.getOperand(5));
6971 Inst = TmpInst;
6972 return true;
6973 }
6974
Jim Grosbachda70eac2012-01-24 00:58:13 +00006975 // VST4 multiple 3-element structure instructions.
6976 case ARM::VST4dAsm_8:
6977 case ARM::VST4dAsm_16:
6978 case ARM::VST4dAsm_32:
6979 case ARM::VST4qAsm_8:
6980 case ARM::VST4qAsm_16:
6981 case ARM::VST4qAsm_32: {
6982 MCInst TmpInst;
6983 unsigned Spacing;
6984 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6985 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6986 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6987 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6988 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6989 Spacing));
6990 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6991 Spacing * 2));
6992 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6993 Spacing * 3));
6994 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6995 TmpInst.addOperand(Inst.getOperand(4));
6996 Inst = TmpInst;
6997 return true;
6998 }
6999
7000 case ARM::VST4dWB_fixed_Asm_8:
7001 case ARM::VST4dWB_fixed_Asm_16:
7002 case ARM::VST4dWB_fixed_Asm_32:
7003 case ARM::VST4qWB_fixed_Asm_8:
7004 case ARM::VST4qWB_fixed_Asm_16:
7005 case ARM::VST4qWB_fixed_Asm_32: {
7006 MCInst TmpInst;
7007 unsigned Spacing;
7008 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7009 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7010 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7011 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7012 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7013 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7014 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7015 Spacing));
7016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7017 Spacing * 2));
7018 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7019 Spacing * 3));
7020 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7021 TmpInst.addOperand(Inst.getOperand(4));
7022 Inst = TmpInst;
7023 return true;
7024 }
7025
7026 case ARM::VST4dWB_register_Asm_8:
7027 case ARM::VST4dWB_register_Asm_16:
7028 case ARM::VST4dWB_register_Asm_32:
7029 case ARM::VST4qWB_register_Asm_8:
7030 case ARM::VST4qWB_register_Asm_16:
7031 case ARM::VST4qWB_register_Asm_32: {
7032 MCInst TmpInst;
7033 unsigned Spacing;
7034 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7035 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7036 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7037 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7038 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7039 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7040 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7041 Spacing));
7042 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7043 Spacing * 2));
7044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7045 Spacing * 3));
7046 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7047 TmpInst.addOperand(Inst.getOperand(5));
7048 Inst = TmpInst;
7049 return true;
7050 }
7051
Jim Grosbachad66de12012-04-11 00:15:16 +00007052 // Handle encoding choice for the shift-immediate instructions.
7053 case ARM::t2LSLri:
7054 case ARM::t2LSRri:
7055 case ARM::t2ASRri: {
7056 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7057 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7058 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7059 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7060 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7061 unsigned NewOpc;
7062 switch (Inst.getOpcode()) {
7063 default: llvm_unreachable("unexpected opcode");
7064 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7065 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7066 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7067 }
7068 // The Thumb1 operands aren't in the same order. Awesome, eh?
7069 MCInst TmpInst;
7070 TmpInst.setOpcode(NewOpc);
7071 TmpInst.addOperand(Inst.getOperand(0));
7072 TmpInst.addOperand(Inst.getOperand(5));
7073 TmpInst.addOperand(Inst.getOperand(1));
7074 TmpInst.addOperand(Inst.getOperand(2));
7075 TmpInst.addOperand(Inst.getOperand(3));
7076 TmpInst.addOperand(Inst.getOperand(4));
7077 Inst = TmpInst;
7078 return true;
7079 }
7080 return false;
7081 }
7082
Jim Grosbach485e5622011-12-13 22:45:11 +00007083 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007084 case ARM::t2MOVsr:
7085 case ARM::t2MOVSsr: {
7086 // Which instruction to expand to depends on the CCOut operand and
7087 // whether we're in an IT block if the register operands are low
7088 // registers.
7089 bool isNarrow = false;
7090 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7091 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7092 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7093 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7094 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7095 isNarrow = true;
7096 MCInst TmpInst;
7097 unsigned newOpc;
7098 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7099 default: llvm_unreachable("unexpected opcode!");
7100 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7101 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7102 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7103 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7104 }
7105 TmpInst.setOpcode(newOpc);
7106 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7107 if (isNarrow)
7108 TmpInst.addOperand(MCOperand::CreateReg(
7109 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7110 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7111 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7112 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7113 TmpInst.addOperand(Inst.getOperand(5));
7114 if (!isNarrow)
7115 TmpInst.addOperand(MCOperand::CreateReg(
7116 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7117 Inst = TmpInst;
7118 return true;
7119 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007120 case ARM::t2MOVsi:
7121 case ARM::t2MOVSsi: {
7122 // Which instruction to expand to depends on the CCOut operand and
7123 // whether we're in an IT block if the register operands are low
7124 // registers.
7125 bool isNarrow = false;
7126 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7127 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7128 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7129 isNarrow = true;
7130 MCInst TmpInst;
7131 unsigned newOpc;
7132 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7133 default: llvm_unreachable("unexpected opcode!");
7134 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7135 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7136 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7137 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007138 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007139 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007140 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7141 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007142 TmpInst.setOpcode(newOpc);
7143 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7144 if (isNarrow)
7145 TmpInst.addOperand(MCOperand::CreateReg(
7146 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7147 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007148 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007149 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007150 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7151 TmpInst.addOperand(Inst.getOperand(4));
7152 if (!isNarrow)
7153 TmpInst.addOperand(MCOperand::CreateReg(
7154 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7155 Inst = TmpInst;
7156 return true;
7157 }
7158 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007159 case ARM::ASRr:
7160 case ARM::LSRr:
7161 case ARM::LSLr:
7162 case ARM::RORr: {
7163 ARM_AM::ShiftOpc ShiftTy;
7164 switch(Inst.getOpcode()) {
7165 default: llvm_unreachable("unexpected opcode!");
7166 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7167 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7168 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7169 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7170 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007171 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7172 MCInst TmpInst;
7173 TmpInst.setOpcode(ARM::MOVsr);
7174 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7175 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7176 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7177 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7178 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7179 TmpInst.addOperand(Inst.getOperand(4));
7180 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7181 Inst = TmpInst;
7182 return true;
7183 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007184 case ARM::ASRi:
7185 case ARM::LSRi:
7186 case ARM::LSLi:
7187 case ARM::RORi: {
7188 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007189 switch(Inst.getOpcode()) {
7190 default: llvm_unreachable("unexpected opcode!");
7191 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7192 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7193 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7194 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7195 }
7196 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007197 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007198 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007199 // A shift by 32 should be encoded as 0 when permitted
7200 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7201 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007202 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007203 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007204 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007205 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7206 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007207 if (Opc == ARM::MOVsi)
7208 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007209 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7210 TmpInst.addOperand(Inst.getOperand(4));
7211 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7212 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007213 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007214 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007215 case ARM::RRXi: {
7216 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7217 MCInst TmpInst;
7218 TmpInst.setOpcode(ARM::MOVsi);
7219 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7220 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7221 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7222 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7223 TmpInst.addOperand(Inst.getOperand(3));
7224 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7225 Inst = TmpInst;
7226 return true;
7227 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007228 case ARM::t2LDMIA_UPD: {
7229 // If this is a load of a single register, then we should use
7230 // a post-indexed LDR instruction instead, per the ARM ARM.
7231 if (Inst.getNumOperands() != 5)
7232 return false;
7233 MCInst TmpInst;
7234 TmpInst.setOpcode(ARM::t2LDR_POST);
7235 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7236 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7237 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7238 TmpInst.addOperand(MCOperand::CreateImm(4));
7239 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7240 TmpInst.addOperand(Inst.getOperand(3));
7241 Inst = TmpInst;
7242 return true;
7243 }
7244 case ARM::t2STMDB_UPD: {
7245 // If this is a store of a single register, then we should use
7246 // a pre-indexed STR instruction instead, per the ARM ARM.
7247 if (Inst.getNumOperands() != 5)
7248 return false;
7249 MCInst TmpInst;
7250 TmpInst.setOpcode(ARM::t2STR_PRE);
7251 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7252 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7253 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7254 TmpInst.addOperand(MCOperand::CreateImm(-4));
7255 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7256 TmpInst.addOperand(Inst.getOperand(3));
7257 Inst = TmpInst;
7258 return true;
7259 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007260 case ARM::LDMIA_UPD:
7261 // If this is a load of a single register via a 'pop', then we should use
7262 // a post-indexed LDR instruction instead, per the ARM ARM.
7263 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7264 Inst.getNumOperands() == 5) {
7265 MCInst TmpInst;
7266 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7267 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7268 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7269 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7270 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7271 TmpInst.addOperand(MCOperand::CreateImm(4));
7272 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7273 TmpInst.addOperand(Inst.getOperand(3));
7274 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007275 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007276 }
7277 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007278 case ARM::STMDB_UPD:
7279 // If this is a store of a single register via a 'push', then we should use
7280 // a pre-indexed STR instruction instead, per the ARM ARM.
7281 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7282 Inst.getNumOperands() == 5) {
7283 MCInst TmpInst;
7284 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7285 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7286 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7287 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7288 TmpInst.addOperand(MCOperand::CreateImm(-4));
7289 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7290 TmpInst.addOperand(Inst.getOperand(3));
7291 Inst = TmpInst;
7292 }
7293 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007294 case ARM::t2ADDri12:
7295 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7296 // mnemonic was used (not "addw"), encoding T3 is preferred.
7297 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7298 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7299 break;
7300 Inst.setOpcode(ARM::t2ADDri);
7301 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7302 break;
7303 case ARM::t2SUBri12:
7304 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7305 // mnemonic was used (not "subw"), encoding T3 is preferred.
7306 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7307 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7308 break;
7309 Inst.setOpcode(ARM::t2SUBri);
7310 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7311 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007312 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007313 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007314 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7315 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7316 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007317 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007318 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007319 return true;
7320 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007321 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007322 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007323 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007324 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7325 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7326 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007327 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007328 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007329 return true;
7330 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007331 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007332 case ARM::t2ADDri:
7333 case ARM::t2SUBri: {
7334 // If the destination and first source operand are the same, and
7335 // the flags are compatible with the current IT status, use encoding T2
7336 // instead of T3. For compatibility with the system 'as'. Make sure the
7337 // wide encoding wasn't explicit.
7338 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007339 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007340 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7341 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7342 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7343 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7344 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7345 break;
7346 MCInst TmpInst;
7347 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7348 ARM::tADDi8 : ARM::tSUBi8);
7349 TmpInst.addOperand(Inst.getOperand(0));
7350 TmpInst.addOperand(Inst.getOperand(5));
7351 TmpInst.addOperand(Inst.getOperand(0));
7352 TmpInst.addOperand(Inst.getOperand(2));
7353 TmpInst.addOperand(Inst.getOperand(3));
7354 TmpInst.addOperand(Inst.getOperand(4));
7355 Inst = TmpInst;
7356 return true;
7357 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007358 case ARM::t2ADDrr: {
7359 // If the destination and first source operand are the same, and
7360 // there's no setting of the flags, use encoding T2 instead of T3.
7361 // Note that this is only for ADD, not SUB. This mirrors the system
7362 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7363 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7364 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007365 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7366 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007367 break;
7368 MCInst TmpInst;
7369 TmpInst.setOpcode(ARM::tADDhirr);
7370 TmpInst.addOperand(Inst.getOperand(0));
7371 TmpInst.addOperand(Inst.getOperand(0));
7372 TmpInst.addOperand(Inst.getOperand(2));
7373 TmpInst.addOperand(Inst.getOperand(3));
7374 TmpInst.addOperand(Inst.getOperand(4));
7375 Inst = TmpInst;
7376 return true;
7377 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007378 case ARM::tADDrSP: {
7379 // If the non-SP source operand and the destination operand are not the
7380 // same, we need to use the 32-bit encoding if it's available.
7381 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7382 Inst.setOpcode(ARM::t2ADDrr);
7383 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7384 return true;
7385 }
7386 break;
7387 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007388 case ARM::tB:
7389 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007390 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007391 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007392 return true;
7393 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007394 break;
7395 case ARM::t2B:
7396 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007397 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007398 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007399 return true;
7400 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007401 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007402 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007403 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007404 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007405 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007406 return true;
7407 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007408 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007409 case ARM::tBcc:
7410 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007411 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007412 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007413 return true;
7414 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007415 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007416 case ARM::tLDMIA: {
7417 // If the register list contains any high registers, or if the writeback
7418 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7419 // instead if we're in Thumb2. Otherwise, this should have generated
7420 // an error in validateInstruction().
7421 unsigned Rn = Inst.getOperand(0).getReg();
7422 bool hasWritebackToken =
7423 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7424 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7425 bool listContainsBase;
7426 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7427 (!listContainsBase && !hasWritebackToken) ||
7428 (listContainsBase && hasWritebackToken)) {
7429 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7430 assert (isThumbTwo());
7431 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7432 // If we're switching to the updating version, we need to insert
7433 // the writeback tied operand.
7434 if (hasWritebackToken)
7435 Inst.insert(Inst.begin(),
7436 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007437 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007438 }
7439 break;
7440 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007441 case ARM::tSTMIA_UPD: {
7442 // If the register list contains any high registers, we need to use
7443 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7444 // should have generated an error in validateInstruction().
7445 unsigned Rn = Inst.getOperand(0).getReg();
7446 bool listContainsBase;
7447 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7448 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7449 assert (isThumbTwo());
7450 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007451 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007452 }
7453 break;
7454 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007455 case ARM::tPOP: {
7456 bool listContainsBase;
7457 // If the register list contains any high registers, we need to use
7458 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7459 // should have generated an error in validateInstruction().
7460 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007461 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007462 assert (isThumbTwo());
7463 Inst.setOpcode(ARM::t2LDMIA_UPD);
7464 // Add the base register and writeback operands.
7465 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7466 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007467 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007468 }
7469 case ARM::tPUSH: {
7470 bool listContainsBase;
7471 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007472 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007473 assert (isThumbTwo());
7474 Inst.setOpcode(ARM::t2STMDB_UPD);
7475 // Add the base register and writeback operands.
7476 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7477 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007478 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007479 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007480 case ARM::t2MOVi: {
7481 // If we can use the 16-bit encoding and the user didn't explicitly
7482 // request the 32-bit variant, transform it here.
7483 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007484 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007485 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7486 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7487 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007488 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7489 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7490 // The operands aren't in the same order for tMOVi8...
7491 MCInst TmpInst;
7492 TmpInst.setOpcode(ARM::tMOVi8);
7493 TmpInst.addOperand(Inst.getOperand(0));
7494 TmpInst.addOperand(Inst.getOperand(4));
7495 TmpInst.addOperand(Inst.getOperand(1));
7496 TmpInst.addOperand(Inst.getOperand(2));
7497 TmpInst.addOperand(Inst.getOperand(3));
7498 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007499 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007500 }
7501 break;
7502 }
7503 case ARM::t2MOVr: {
7504 // If we can use the 16-bit encoding and the user didn't explicitly
7505 // request the 32-bit variant, transform it here.
7506 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7507 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7508 Inst.getOperand(2).getImm() == ARMCC::AL &&
7509 Inst.getOperand(4).getReg() == ARM::CPSR &&
7510 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7511 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7512 // The operands aren't the same for tMOV[S]r... (no cc_out)
7513 MCInst TmpInst;
7514 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7515 TmpInst.addOperand(Inst.getOperand(0));
7516 TmpInst.addOperand(Inst.getOperand(1));
7517 TmpInst.addOperand(Inst.getOperand(2));
7518 TmpInst.addOperand(Inst.getOperand(3));
7519 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007520 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007521 }
7522 break;
7523 }
Jim Grosbach82213192011-09-19 20:29:33 +00007524 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007525 case ARM::t2SXTB:
7526 case ARM::t2UXTH:
7527 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007528 // If we can use the 16-bit encoding and the user didn't explicitly
7529 // request the 32-bit variant, transform it here.
7530 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7531 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7532 Inst.getOperand(2).getImm() == 0 &&
7533 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7534 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007535 unsigned NewOpc;
7536 switch (Inst.getOpcode()) {
7537 default: llvm_unreachable("Illegal opcode!");
7538 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7539 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7540 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7541 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7542 }
Jim Grosbach82213192011-09-19 20:29:33 +00007543 // The operands aren't the same for thumb1 (no rotate operand).
7544 MCInst TmpInst;
7545 TmpInst.setOpcode(NewOpc);
7546 TmpInst.addOperand(Inst.getOperand(0));
7547 TmpInst.addOperand(Inst.getOperand(1));
7548 TmpInst.addOperand(Inst.getOperand(3));
7549 TmpInst.addOperand(Inst.getOperand(4));
7550 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007551 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007552 }
7553 break;
7554 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007555 case ARM::MOVsi: {
7556 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007557 // rrx shifts and asr/lsr of #32 is encoded as 0
7558 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7559 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007560 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7561 // Shifting by zero is accepted as a vanilla 'MOVr'
7562 MCInst TmpInst;
7563 TmpInst.setOpcode(ARM::MOVr);
7564 TmpInst.addOperand(Inst.getOperand(0));
7565 TmpInst.addOperand(Inst.getOperand(1));
7566 TmpInst.addOperand(Inst.getOperand(3));
7567 TmpInst.addOperand(Inst.getOperand(4));
7568 TmpInst.addOperand(Inst.getOperand(5));
7569 Inst = TmpInst;
7570 return true;
7571 }
7572 return false;
7573 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007574 case ARM::ANDrsi:
7575 case ARM::ORRrsi:
7576 case ARM::EORrsi:
7577 case ARM::BICrsi:
7578 case ARM::SUBrsi:
7579 case ARM::ADDrsi: {
7580 unsigned newOpc;
7581 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7582 if (SOpc == ARM_AM::rrx) return false;
7583 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007584 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007585 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7586 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7587 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7588 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7589 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7590 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7591 }
7592 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007593 // The exception is for right shifts, where 0 == 32
7594 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7595 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007596 MCInst TmpInst;
7597 TmpInst.setOpcode(newOpc);
7598 TmpInst.addOperand(Inst.getOperand(0));
7599 TmpInst.addOperand(Inst.getOperand(1));
7600 TmpInst.addOperand(Inst.getOperand(2));
7601 TmpInst.addOperand(Inst.getOperand(4));
7602 TmpInst.addOperand(Inst.getOperand(5));
7603 TmpInst.addOperand(Inst.getOperand(6));
7604 Inst = TmpInst;
7605 return true;
7606 }
7607 return false;
7608 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007609 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007610 case ARM::t2IT: {
7611 // The mask bits for all but the first condition are represented as
7612 // the low bit of the condition code value implies 't'. We currently
7613 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007614 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007615 MCOperand &MO = Inst.getOperand(1);
7616 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007617 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007618 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007619 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007620 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007621 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007622 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007623 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007624
7625 // Set up the IT block state according to the IT instruction we just
7626 // matched.
7627 assert(!inITBlock() && "nested IT blocks?!");
7628 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7629 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7630 ITState.CurPosition = 0;
7631 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007632 break;
7633 }
Richard Bartona39625e2012-07-09 16:12:24 +00007634 case ARM::t2LSLrr:
7635 case ARM::t2LSRrr:
7636 case ARM::t2ASRrr:
7637 case ARM::t2SBCrr:
7638 case ARM::t2RORrr:
7639 case ARM::t2BICrr:
7640 {
Richard Bartond5660372012-07-09 16:14:28 +00007641 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007642 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7643 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7644 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007645 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7646 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007647 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7648 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7649 unsigned NewOpc;
7650 switch (Inst.getOpcode()) {
7651 default: llvm_unreachable("unexpected opcode");
7652 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7653 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7654 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7655 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7656 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7657 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7658 }
7659 MCInst TmpInst;
7660 TmpInst.setOpcode(NewOpc);
7661 TmpInst.addOperand(Inst.getOperand(0));
7662 TmpInst.addOperand(Inst.getOperand(5));
7663 TmpInst.addOperand(Inst.getOperand(1));
7664 TmpInst.addOperand(Inst.getOperand(2));
7665 TmpInst.addOperand(Inst.getOperand(3));
7666 TmpInst.addOperand(Inst.getOperand(4));
7667 Inst = TmpInst;
7668 return true;
7669 }
7670 return false;
7671 }
7672 case ARM::t2ANDrr:
7673 case ARM::t2EORrr:
7674 case ARM::t2ADCrr:
7675 case ARM::t2ORRrr:
7676 {
Richard Bartond5660372012-07-09 16:14:28 +00007677 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007678 // These instructions are special in that they are commutable, so shorter encodings
7679 // are available more often.
7680 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7681 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7682 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7683 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007684 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7685 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007686 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7687 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7688 unsigned NewOpc;
7689 switch (Inst.getOpcode()) {
7690 default: llvm_unreachable("unexpected opcode");
7691 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7692 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7693 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7694 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7695 }
7696 MCInst TmpInst;
7697 TmpInst.setOpcode(NewOpc);
7698 TmpInst.addOperand(Inst.getOperand(0));
7699 TmpInst.addOperand(Inst.getOperand(5));
7700 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7701 TmpInst.addOperand(Inst.getOperand(1));
7702 TmpInst.addOperand(Inst.getOperand(2));
7703 } else {
7704 TmpInst.addOperand(Inst.getOperand(2));
7705 TmpInst.addOperand(Inst.getOperand(1));
7706 }
7707 TmpInst.addOperand(Inst.getOperand(3));
7708 TmpInst.addOperand(Inst.getOperand(4));
7709 Inst = TmpInst;
7710 return true;
7711 }
7712 return false;
7713 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007714 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007715 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007716}
7717
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007718unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7719 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7720 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007721 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007722 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007723 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7724 assert(MCID.hasOptionalDef() &&
7725 "optionally flag setting instruction missing optional def operand");
7726 assert(MCID.NumOperands == Inst.getNumOperands() &&
7727 "operand count mismatch!");
7728 // Find the optional-def operand (cc_out).
7729 unsigned OpNo;
7730 for (OpNo = 0;
7731 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7732 ++OpNo)
7733 ;
7734 // If we're parsing Thumb1, reject it completely.
7735 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7736 return Match_MnemonicFail;
7737 // If we're parsing Thumb2, which form is legal depends on whether we're
7738 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007739 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7740 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007741 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007742 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7743 inITBlock())
7744 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007745 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007746 // Some high-register supporting Thumb1 encodings only allow both registers
7747 // to be from r0-r7 when in Thumb2.
7748 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7749 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7750 isARMLowRegister(Inst.getOperand(2).getReg()))
7751 return Match_RequiresThumb2;
7752 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007753 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007754 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7755 isARMLowRegister(Inst.getOperand(1).getReg()))
7756 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007757 return Match_Success;
7758}
7759
Jim Grosbach5117ef72012-04-24 22:40:08 +00007760static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007761bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007762MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007763 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007764 MCStreamer &Out, unsigned &ErrorInfo,
7765 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007766 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007767 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007768
Chad Rosier2f480a82012-10-12 22:53:36 +00007769 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007770 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007771 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007772 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007773 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007774 // Context sensitive operand constraints aren't handled by the matcher,
7775 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007776 if (validateInstruction(Inst, Operands)) {
7777 // Still progress the IT block, otherwise one wrong condition causes
7778 // nasty cascading errors.
7779 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007780 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007781 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007782
Amara Emerson52cfb6a2013-10-03 09:31:51 +00007783 { // processInstruction() updates inITBlock state, we need to save it away
7784 bool wasInITBlock = inITBlock();
7785
7786 // Some instructions need post-processing to, for example, tweak which
7787 // encoding is selected. Loop on it while changes happen so the
7788 // individual transformations can chain off each other. E.g.,
7789 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7790 while (processInstruction(Inst, Operands))
7791 ;
7792
7793 // Only after the instruction is fully processed, we can validate it
7794 if (wasInITBlock && hasV8Ops() && isThumb() &&
7795 !isV8EligibleForIT(&Inst, 2)) {
7796 Warning(IDLoc, "deprecated instruction in IT block");
7797 }
7798 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007799
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007800 // Only move forward at the very end so that everything in validate
7801 // and process gets a consistent answer about whether we're in an IT
7802 // block.
7803 forwardITPosition();
7804
Jim Grosbach82f76d12012-01-25 19:52:01 +00007805 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7806 // doesn't actually encode.
7807 if (Inst.getOpcode() == ARM::ITasm)
7808 return false;
7809
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007810 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007811 Out.EmitInstruction(Inst);
7812 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007813 case Match_MissingFeature: {
7814 assert(ErrorInfo && "Unknown missing feature!");
7815 // Special case the error message for the very common case where only
7816 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7817 std::string Msg = "instruction requires:";
7818 unsigned Mask = 1;
7819 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7820 if (ErrorInfo & Mask) {
7821 Msg += " ";
7822 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7823 }
7824 Mask <<= 1;
7825 }
7826 return Error(IDLoc, Msg);
7827 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007828 case Match_InvalidOperand: {
7829 SMLoc ErrorLoc = IDLoc;
7830 if (ErrorInfo != ~0U) {
7831 if (ErrorInfo >= Operands.size())
7832 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007833
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007834 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7835 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7836 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007837
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007838 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007839 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007840 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007841 return Error(IDLoc, "invalid instruction",
7842 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007843 case Match_RequiresNotITBlock:
7844 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007845 case Match_RequiresITBlock:
7846 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007847 case Match_RequiresV6:
7848 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7849 case Match_RequiresThumb2:
7850 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007851 case Match_ImmRange0_15: {
7852 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7853 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7854 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7855 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00007856 case Match_ImmRange0_239: {
7857 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7858 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7859 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7860 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007861 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007862
Eric Christopher91d7b902010-10-29 09:26:59 +00007863 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007864}
7865
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007866/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007867bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7868 StringRef IDVal = DirectiveID.getIdentifier();
7869 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007870 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007871 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007872 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007873 else if (IDVal == ".arm")
7874 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007875 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007876 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007877 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007878 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007879 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007880 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007881 else if (IDVal == ".unreq")
7882 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007883 else if (IDVal == ".arch")
7884 return parseDirectiveArch(DirectiveID.getLoc());
7885 else if (IDVal == ".eabi_attribute")
7886 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien8cbb80d2013-10-28 17:51:12 +00007887 else if (IDVal == ".cpu")
7888 return parseDirectiveCPU(DirectiveID.getLoc());
7889 else if (IDVal == ".fpu")
7890 return parseDirectiveFPU(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007891 else if (IDVal == ".fnstart")
7892 return parseDirectiveFnStart(DirectiveID.getLoc());
7893 else if (IDVal == ".fnend")
7894 return parseDirectiveFnEnd(DirectiveID.getLoc());
7895 else if (IDVal == ".cantunwind")
7896 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7897 else if (IDVal == ".personality")
7898 return parseDirectivePersonality(DirectiveID.getLoc());
7899 else if (IDVal == ".handlerdata")
7900 return parseDirectiveHandlerData(DirectiveID.getLoc());
7901 else if (IDVal == ".setfp")
7902 return parseDirectiveSetFP(DirectiveID.getLoc());
7903 else if (IDVal == ".pad")
7904 return parseDirectivePad(DirectiveID.getLoc());
7905 else if (IDVal == ".save")
7906 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7907 else if (IDVal == ".vsave")
7908 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00007909 else if (IDVal == ".inst")
7910 return parseDirectiveInst(DirectiveID.getLoc());
7911 else if (IDVal == ".inst.n")
7912 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7913 else if (IDVal == ".inst.w")
7914 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00007915 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00007916 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00007917 else if (IDVal == ".even")
7918 return parseDirectiveEven(DirectiveID.getLoc());
Kevin Enderbyccab3172009-09-15 00:27:25 +00007919 return true;
7920}
7921
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007922/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007923/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007924bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007925 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7926 for (;;) {
7927 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007928 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007929 return true;
7930
Eric Christopherbf7bc492013-01-09 03:52:05 +00007931 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007932
7933 if (getLexer().is(AsmToken::EndOfStatement))
7934 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007935
Kevin Enderbyccab3172009-09-15 00:27:25 +00007936 // FIXME: Improve diagnostic.
7937 if (getLexer().isNot(AsmToken::Comma))
7938 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007939 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007940 }
7941 }
7942
Sean Callanana83fd7d2010-01-19 20:27:46 +00007943 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007944 return false;
7945}
7946
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007947/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007948/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007949bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007950 if (getLexer().isNot(AsmToken::EndOfStatement))
7951 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007952 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007953
Tim Northovera2292d02013-06-10 23:20:58 +00007954 if (!hasThumb())
7955 return Error(L, "target does not support Thumb mode");
7956
Jim Grosbach7f882392011-12-07 18:04:19 +00007957 if (!isThumb())
7958 SwitchMode();
7959 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7960 return false;
7961}
7962
7963/// parseDirectiveARM
7964/// ::= .arm
7965bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7966 if (getLexer().isNot(AsmToken::EndOfStatement))
7967 return Error(L, "unexpected token in directive");
7968 Parser.Lex();
7969
Tim Northovera2292d02013-06-10 23:20:58 +00007970 if (!hasARM())
7971 return Error(L, "target does not support ARM mode");
7972
Jim Grosbach7f882392011-12-07 18:04:19 +00007973 if (isThumb())
7974 SwitchMode();
7975 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007976 return false;
7977}
7978
Tim Northover1744d0a2013-10-25 12:49:50 +00007979void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
7980 if (NextSymbolIsThumb) {
7981 getParser().getStreamer().EmitThumbFunc(Symbol);
7982 NextSymbolIsThumb = false;
7983 }
7984}
7985
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007986/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007987/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007988bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007989 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7990 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007991
Jim Grosbach1152cc02011-12-21 22:30:16 +00007992 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007993 // ELF doesn't
7994 if (isMachO) {
7995 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007996 if (Tok.isNot(AsmToken::EndOfStatement)) {
7997 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7998 return Error(L, "unexpected token in .thumb_func directive");
Tim Northover1744d0a2013-10-25 12:49:50 +00007999 MCSymbol *Func =
8000 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8001 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008002 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008003 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008004 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008005 }
8006
Jim Grosbach1152cc02011-12-21 22:30:16 +00008007 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00008008 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00008009
Tim Northover1744d0a2013-10-25 12:49:50 +00008010 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008011
Kevin Enderby146dcf22009-10-15 20:48:48 +00008012 return false;
8013}
8014
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008015/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008016/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008017bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008018 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008019 if (Tok.isNot(AsmToken::Identifier))
8020 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00008021 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00008022 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00008023 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00008024 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00008025 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00008026 else
8027 return Error(L, "unrecognized syntax mode in .syntax directive");
8028
8029 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00008030 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00008031 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008032
8033 // TODO tell the MC streamer the mode
8034 // getParser().getStreamer().Emit???();
8035 return false;
8036}
8037
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008038/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008039/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008040bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008041 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008042 if (Tok.isNot(AsmToken::Integer))
8043 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00008044 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00008045 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00008046 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00008047 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00008048 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008049 else
8050 return Error(L, "invalid operand to .code directive");
8051
8052 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00008053 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00008054 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008055
Evan Cheng284b4672011-07-08 22:36:29 +00008056 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00008057 if (!hasThumb())
8058 return Error(L, "target does not support Thumb mode");
8059
Jim Grosbachf471ac32011-09-06 18:46:23 +00008060 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008061 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008062 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008063 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00008064 if (!hasARM())
8065 return Error(L, "target does not support ARM mode");
8066
Jim Grosbachf471ac32011-09-06 18:46:23 +00008067 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008068 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008069 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008070 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008071
Kevin Enderby146dcf22009-10-15 20:48:48 +00008072 return false;
8073}
8074
Jim Grosbachab5830e2011-12-14 02:16:11 +00008075/// parseDirectiveReq
8076/// ::= name .req registername
8077bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8078 Parser.Lex(); // Eat the '.req' token.
8079 unsigned Reg;
8080 SMLoc SRegLoc, ERegLoc;
8081 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008082 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008083 return Error(SRegLoc, "register name expected");
8084 }
8085
8086 // Shouldn't be anything else.
8087 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008088 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008089 return Error(Parser.getTok().getLoc(),
8090 "unexpected input in .req directive.");
8091 }
8092
8093 Parser.Lex(); // Consume the EndOfStatement
8094
8095 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
8096 return Error(SRegLoc, "redefinition of '" + Name +
8097 "' does not match original.");
8098
8099 return false;
8100}
8101
8102/// parseDirectiveUneq
8103/// ::= .unreq registername
8104bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8105 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008106 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008107 return Error(L, "unexpected input in .unreq directive.");
8108 }
8109 RegisterReqs.erase(Parser.getTok().getIdentifier());
8110 Parser.Lex(); // Eat the identifier.
8111 return false;
8112}
8113
Jason W Kim135d2442011-12-20 17:38:12 +00008114/// parseDirectiveArch
8115/// ::= .arch token
8116bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008117 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8118
8119 unsigned ID = StringSwitch<unsigned>(Arch)
8120#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8121 .Case(NAME, ARM::ID)
8122#include "MCTargetDesc/ARMArchName.def"
8123 .Default(ARM::INVALID_ARCH);
8124
8125 if (ID == ARM::INVALID_ARCH)
8126 return Error(L, "Unknown arch name");
8127
8128 getTargetStreamer().emitArch(ID);
8129 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008130}
8131
8132/// parseDirectiveEabiAttr
8133/// ::= .eabi_attribute int, int
8134bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Logan Chien8cbb80d2013-10-28 17:51:12 +00008135 if (Parser.getTok().isNot(AsmToken::Integer))
8136 return Error(L, "integer expected");
8137 int64_t Tag = Parser.getTok().getIntVal();
8138 Parser.Lex(); // eat tag integer
8139
8140 if (Parser.getTok().isNot(AsmToken::Comma))
8141 return Error(L, "comma expected");
8142 Parser.Lex(); // skip comma
8143
8144 L = Parser.getTok().getLoc();
8145 if (Parser.getTok().isNot(AsmToken::Integer))
8146 return Error(L, "integer expected");
8147 int64_t Value = Parser.getTok().getIntVal();
8148 Parser.Lex(); // eat value integer
8149
8150 getTargetStreamer().emitAttribute(Tag, Value);
8151 return false;
8152}
8153
8154/// parseDirectiveCPU
8155/// ::= .cpu str
8156bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8157 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8158 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8159 return false;
8160}
8161
8162/// parseDirectiveFPU
8163/// ::= .fpu str
8164bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8165 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8166
8167 unsigned ID = StringSwitch<unsigned>(FPU)
8168#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8169#include "ARMFPUName.def"
8170 .Default(ARM::INVALID_FPU);
8171
8172 if (ID == ARM::INVALID_FPU)
8173 return Error(L, "Unknown FPU name");
8174
8175 getTargetStreamer().emitFPU(ID);
8176 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008177}
8178
Logan Chien4ea23b52013-05-10 16:17:24 +00008179/// parseDirectiveFnStart
8180/// ::= .fnstart
8181bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8182 if (FnStartLoc.isValid()) {
8183 Error(L, ".fnstart starts before the end of previous one");
8184 Error(FnStartLoc, "previous .fnstart starts here");
8185 return true;
8186 }
8187
8188 FnStartLoc = L;
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008189 getTargetStreamer().emitFnStart();
Logan Chien4ea23b52013-05-10 16:17:24 +00008190 return false;
8191}
8192
8193/// parseDirectiveFnEnd
8194/// ::= .fnend
8195bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8196 // Check the ordering of unwind directives
8197 if (!FnStartLoc.isValid())
8198 return Error(L, ".fnstart must precede .fnend directive");
8199
8200 // Reset the unwind directives parser state
8201 resetUnwindDirectiveParserState();
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008202 getTargetStreamer().emitFnEnd();
Logan Chien4ea23b52013-05-10 16:17:24 +00008203 return false;
8204}
8205
8206/// parseDirectiveCantUnwind
8207/// ::= .cantunwind
8208bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8209 // Check the ordering of unwind directives
8210 CantUnwindLoc = L;
8211 if (!FnStartLoc.isValid())
8212 return Error(L, ".fnstart must precede .cantunwind directive");
8213 if (HandlerDataLoc.isValid()) {
8214 Error(L, ".cantunwind can't be used with .handlerdata directive");
8215 Error(HandlerDataLoc, ".handlerdata was specified here");
8216 return true;
8217 }
8218 if (PersonalityLoc.isValid()) {
8219 Error(L, ".cantunwind can't be used with .personality directive");
8220 Error(PersonalityLoc, ".personality was specified here");
8221 return true;
8222 }
8223
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008224 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008225 return false;
8226}
8227
8228/// parseDirectivePersonality
8229/// ::= .personality name
8230bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8231 // Check the ordering of unwind directives
8232 PersonalityLoc = L;
8233 if (!FnStartLoc.isValid())
8234 return Error(L, ".fnstart must precede .personality directive");
8235 if (CantUnwindLoc.isValid()) {
8236 Error(L, ".personality can't be used with .cantunwind directive");
8237 Error(CantUnwindLoc, ".cantunwind was specified here");
8238 return true;
8239 }
8240 if (HandlerDataLoc.isValid()) {
8241 Error(L, ".personality must precede .handlerdata directive");
8242 Error(HandlerDataLoc, ".handlerdata was specified here");
8243 return true;
8244 }
8245
8246 // Parse the name of the personality routine
8247 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8248 Parser.eatToEndOfStatement();
8249 return Error(L, "unexpected input in .personality directive.");
8250 }
8251 StringRef Name(Parser.getTok().getIdentifier());
8252 Parser.Lex();
8253
8254 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008255 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008256 return false;
8257}
8258
8259/// parseDirectiveHandlerData
8260/// ::= .handlerdata
8261bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8262 // Check the ordering of unwind directives
8263 HandlerDataLoc = L;
8264 if (!FnStartLoc.isValid())
8265 return Error(L, ".fnstart must precede .personality directive");
8266 if (CantUnwindLoc.isValid()) {
8267 Error(L, ".handlerdata can't be used with .cantunwind directive");
8268 Error(CantUnwindLoc, ".cantunwind was specified here");
8269 return true;
8270 }
8271
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008272 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008273 return false;
8274}
8275
8276/// parseDirectiveSetFP
8277/// ::= .setfp fpreg, spreg [, offset]
8278bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8279 // Check the ordering of unwind directives
8280 if (!FnStartLoc.isValid())
8281 return Error(L, ".fnstart must precede .setfp directive");
8282 if (HandlerDataLoc.isValid())
8283 return Error(L, ".setfp must precede .handlerdata directive");
8284
8285 // Parse fpreg
8286 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8287 int NewFPReg = tryParseRegister();
8288 if (NewFPReg == -1)
8289 return Error(NewFPRegLoc, "frame pointer register expected");
8290
8291 // Consume comma
8292 if (!Parser.getTok().is(AsmToken::Comma))
8293 return Error(Parser.getTok().getLoc(), "comma expected");
8294 Parser.Lex(); // skip comma
8295
8296 // Parse spreg
8297 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8298 int NewSPReg = tryParseRegister();
8299 if (NewSPReg == -1)
8300 return Error(NewSPRegLoc, "stack pointer register expected");
8301
8302 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8303 return Error(NewSPRegLoc,
8304 "register should be either $sp or the latest fp register");
8305
8306 // Update the frame pointer register
8307 FPReg = NewFPReg;
8308
8309 // Parse offset
8310 int64_t Offset = 0;
8311 if (Parser.getTok().is(AsmToken::Comma)) {
8312 Parser.Lex(); // skip comma
8313
8314 if (Parser.getTok().isNot(AsmToken::Hash) &&
8315 Parser.getTok().isNot(AsmToken::Dollar)) {
8316 return Error(Parser.getTok().getLoc(), "'#' expected");
8317 }
8318 Parser.Lex(); // skip hash token.
8319
8320 const MCExpr *OffsetExpr;
8321 SMLoc ExLoc = Parser.getTok().getLoc();
8322 SMLoc EndLoc;
8323 if (getParser().parseExpression(OffsetExpr, EndLoc))
8324 return Error(ExLoc, "malformed setfp offset");
8325 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8326 if (!CE)
8327 return Error(ExLoc, "setfp offset must be an immediate");
8328
8329 Offset = CE->getValue();
8330 }
8331
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008332 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8333 static_cast<unsigned>(NewSPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008334 return false;
8335}
8336
8337/// parseDirective
8338/// ::= .pad offset
8339bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8340 // Check the ordering of unwind directives
8341 if (!FnStartLoc.isValid())
8342 return Error(L, ".fnstart must precede .pad directive");
8343 if (HandlerDataLoc.isValid())
8344 return Error(L, ".pad must precede .handlerdata directive");
8345
8346 // Parse the offset
8347 if (Parser.getTok().isNot(AsmToken::Hash) &&
8348 Parser.getTok().isNot(AsmToken::Dollar)) {
8349 return Error(Parser.getTok().getLoc(), "'#' expected");
8350 }
8351 Parser.Lex(); // skip hash token.
8352
8353 const MCExpr *OffsetExpr;
8354 SMLoc ExLoc = Parser.getTok().getLoc();
8355 SMLoc EndLoc;
8356 if (getParser().parseExpression(OffsetExpr, EndLoc))
8357 return Error(ExLoc, "malformed pad offset");
8358 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8359 if (!CE)
8360 return Error(ExLoc, "pad offset must be an immediate");
8361
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008362 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008363 return false;
8364}
8365
8366/// parseDirectiveRegSave
8367/// ::= .save { registers }
8368/// ::= .vsave { registers }
8369bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8370 // Check the ordering of unwind directives
8371 if (!FnStartLoc.isValid())
8372 return Error(L, ".fnstart must precede .save or .vsave directives");
8373 if (HandlerDataLoc.isValid())
8374 return Error(L, ".save or .vsave must precede .handlerdata directive");
8375
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008376 // RAII object to make sure parsed operands are deleted.
8377 struct CleanupObject {
8378 SmallVector<MCParsedAsmOperand *, 1> Operands;
8379 ~CleanupObject() {
8380 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8381 delete Operands[I];
8382 }
8383 } CO;
8384
Logan Chien4ea23b52013-05-10 16:17:24 +00008385 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008386 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008387 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008388 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008389 if (!IsVector && !Op->isRegList())
8390 return Error(L, ".save expects GPR registers");
8391 if (IsVector && !Op->isDPRRegList())
8392 return Error(L, ".vsave expects DPR registers");
8393
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008394 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008395 return false;
8396}
8397
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008398/// parseDirectiveInst
8399/// ::= .inst opcode [, ...]
8400/// ::= .inst.n opcode [, ...]
8401/// ::= .inst.w opcode [, ...]
8402bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8403 int Width;
8404
8405 if (isThumb()) {
8406 switch (Suffix) {
8407 case 'n':
8408 Width = 2;
8409 break;
8410 case 'w':
8411 Width = 4;
8412 break;
8413 default:
8414 Parser.eatToEndOfStatement();
8415 return Error(Loc, "cannot determine Thumb instruction size, "
8416 "use inst.n/inst.w instead");
8417 }
8418 } else {
8419 if (Suffix) {
8420 Parser.eatToEndOfStatement();
8421 return Error(Loc, "width suffixes are invalid in ARM mode");
8422 }
8423 Width = 4;
8424 }
8425
8426 if (getLexer().is(AsmToken::EndOfStatement)) {
8427 Parser.eatToEndOfStatement();
8428 return Error(Loc, "expected expression following directive");
8429 }
8430
8431 for (;;) {
8432 const MCExpr *Expr;
8433
8434 if (getParser().parseExpression(Expr))
8435 return Error(Loc, "expected expression");
8436
8437 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
8438 if (!Value)
8439 return Error(Loc, "expected constant expression");
8440
8441 switch (Width) {
8442 case 2:
8443 if (Value->getValue() > 0xffff)
8444 return Error(Loc, "inst.n operand is too big, use inst.w instead");
8445 break;
8446 case 4:
8447 if (Value->getValue() > 0xffffffff)
8448 return Error(Loc,
8449 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8450 break;
8451 default:
8452 llvm_unreachable("only supported widths are 2 and 4");
8453 }
8454
8455 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8456
8457 if (getLexer().is(AsmToken::EndOfStatement))
8458 break;
8459
8460 if (getLexer().isNot(AsmToken::Comma))
8461 return Error(Loc, "unexpected token in directive");
8462
8463 Parser.Lex();
8464 }
8465
8466 Parser.Lex();
8467 return false;
8468}
8469
David Peixotto80c083a2013-12-19 18:26:07 +00008470/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008471/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00008472bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
8473 MCStreamer &Streamer = getParser().getStreamer();
8474 const MCSection *Section = Streamer.getCurrentSection().first;
8475
8476 if (ConstantPool *CP = getConstantPool(Section)) {
David Peixotto52303f62013-12-19 22:41:56 +00008477 if (!CP->empty())
8478 CP->emitEntries(Streamer);
David Peixotto80c083a2013-12-19 18:26:07 +00008479 }
8480 return false;
8481}
8482
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008483bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
8484 const MCSection *Section = getStreamer().getCurrentSection().first;
8485
8486 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8487 TokError("unexpected token in directive");
8488 return false;
8489 }
8490
8491 if (!Section) {
8492 getStreamer().InitToTextSection();
8493 Section = getStreamer().getCurrentSection().first;
8494 }
8495
8496 if (Section->UseCodeAlign())
8497 getStreamer().EmitCodeAlignment(2, 0);
8498 else
8499 getStreamer().EmitValueToAlignment(2, 0, 1, 0);
8500
8501 return false;
8502}
8503
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008504/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008505extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008506 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8507 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008508}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008509
Chris Lattner3e4582a2010-09-06 19:11:01 +00008510#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008511#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008512#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008513#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008514
8515// Define this matcher function after the auto-generated include so we
8516// have the match class enum definitions.
8517unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8518 unsigned Kind) {
8519 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8520 // If the kind is a token for a literal immediate, check if our asm
8521 // operand matches. This is for InstAliases which have a fixed-value
8522 // immediate in the syntax.
8523 if (Kind == MCK__35_0 && Op->isImm()) {
8524 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8525 if (!CE)
8526 return Match_InvalidOperand;
8527 if (CE->getValue() == 0)
8528 return Match_Success;
8529 }
8530 return Match_InvalidOperand;
8531}
David Peixottoe407d092013-12-19 18:12:36 +00008532
8533void ARMAsmParser::finishParse() {
8534 // Dump contents of assembler constant pools.
8535 MCStreamer &Streamer = getParser().getStreamer();
8536 for (ConstantPoolMapTy::iterator CPI = ConstantPools.begin(),
8537 CPE = ConstantPools.end();
8538 CPI != CPE; ++CPI) {
8539 const MCSection *Section = CPI->first;
8540 ConstantPool &CP = CPI->second;
8541
David Peixotto52303f62013-12-19 22:41:56 +00008542 // Dump non-empty assembler constant pools at the end of the section.
8543 if (!CP.empty()) {
8544 Streamer.SwitchSection(Section);
8545 CP.emitEntries(Streamer);
8546 }
David Peixottoe407d092013-12-19 18:12:36 +00008547 }
8548}