blob: 8ebf1e41ebfd2642c802bb531d6c4ca561314964 [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"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000019#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000020#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000021#include "llvm/ADT/SmallVector.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000022#include "llvm/ADT/StringExtras.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000023#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000024#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000025#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000026#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000027#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000028#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000029#include "llvm/MC/MCExpr.h"
30#include "llvm/MC/MCInst.h"
31#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000032#include "llvm/MC/MCInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000033#include "llvm/MC/MCParser/MCAsmLexer.h"
34#include "llvm/MC/MCParser/MCAsmParser.h"
35#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
36#include "llvm/MC/MCRegisterInfo.h"
37#include "llvm/MC/MCStreamer.h"
38#include "llvm/MC/MCSubtargetInfo.h"
David Peixottoe407d092013-12-19 18:12:36 +000039#include "llvm/MC/MCSymbol.h"
Jack Carter718da0b2013-01-30 02:24:33 +000040#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000041#include "llvm/Support/MathExtras.h"
42#include "llvm/Support/SourceMgr.h"
43#include "llvm/Support/TargetRegistry.h"
44#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000045
Kevin Enderbyccab3172009-09-15 00:27:25 +000046using namespace llvm;
47
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000048namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000049
50class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000051
Jim Grosbach04945c42011-12-02 00:35:16 +000052enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000053
David Peixottoe407d092013-12-19 18:12:36 +000054// A class to keep track of assembler-generated constant pools that are use to
55// implement the ldr-pseudo.
56class ConstantPool {
57 typedef SmallVector<std::pair<MCSymbol *, const MCExpr *>, 4> EntryVecTy;
58 EntryVecTy Entries;
59
60public:
61 // Initialize a new empty constant pool
62 ConstantPool() { }
63
64 // Add a new entry to the constant pool in the next slot.
65 // \param Value is the new entry to put in the constant pool.
66 //
67 // \returns a MCExpr that references the newly inserted value
68 const MCExpr *addEntry(const MCExpr *Value, MCContext &Context) {
69 MCSymbol *CPEntryLabel = Context.CreateTempSymbol();
70
71 Entries.push_back(std::make_pair(CPEntryLabel, Value));
72 return MCSymbolRefExpr::Create(CPEntryLabel, Context);
73 }
74
75 // Emit the contents of the constant pool using the provided streamer.
76 void emitEntries(MCStreamer &Streamer) const {
77 Streamer.EmitCodeAlignment(4); // align to 4-byte address
78 Streamer.EmitDataRegion(MCDR_DataRegion);
79 for (EntryVecTy::const_iterator I = Entries.begin(), E = Entries.end();
80 I != E; ++I) {
81 Streamer.EmitLabel(I->first);
82 Streamer.EmitValue(I->second, 4);
83 }
84 Streamer.EmitDataRegion(MCDR_DataRegionEnd);
85 }
86};
87
88// Map type used to keep track of per-Section constant pools used by the
89// ldr-pseudo opcode. The map associates a section to its constant pool. The
90// constant pool is a vector of (label, value) pairs. When the ldr
91// pseudo is parsed we insert a new (label, value) pair into the constant pool
92// for the current section and add MCSymbolRefExpr to the new label as
93// an opcode to the ldr. After we have parsed all the user input we
94// output the (label, value) pairs in each constant pool at the end of the
95// section.
96typedef std::map<const MCSection *, ConstantPool> ConstantPoolMapTy;
97
Evan Cheng11424442011-07-26 00:24:13 +000098class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000099 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000100 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +0000101 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000102 const MCRegisterInfo *MRI;
David Peixottoe407d092013-12-19 18:12:36 +0000103 ConstantPoolMapTy ConstantPools;
104
105 // Assembler created constant pools for ldr pseudo
106 ConstantPool *getConstantPool(const MCSection *Section) {
107 ConstantPoolMapTy::iterator CP = ConstantPools.find(Section);
108 if (CP == ConstantPools.end())
109 return 0;
110
111 return &CP->second;
112 }
113
114 ConstantPool &getOrCreateConstantPool(const MCSection *Section) {
115 return ConstantPools[Section];
116 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000117
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000118 ARMTargetStreamer &getTargetStreamer() {
119 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
120 return static_cast<ARMTargetStreamer &>(TS);
121 }
122
Logan Chien4ea23b52013-05-10 16:17:24 +0000123 // Unwind directives state
124 SMLoc FnStartLoc;
125 SMLoc CantUnwindLoc;
126 SMLoc PersonalityLoc;
127 SMLoc HandlerDataLoc;
128 int FPReg;
129 void resetUnwindDirectiveParserState() {
130 FnStartLoc = SMLoc();
131 CantUnwindLoc = SMLoc();
132 PersonalityLoc = SMLoc();
133 HandlerDataLoc = SMLoc();
134 FPReg = -1;
135 }
136
Jim Grosbachab5830e2011-12-14 02:16:11 +0000137 // Map of register aliases registers via the .req directive.
138 StringMap<unsigned> RegisterReqs;
139
Tim Northover1744d0a2013-10-25 12:49:50 +0000140 bool NextSymbolIsThumb;
141
Jim Grosbached16ec42011-08-29 22:24:09 +0000142 struct {
143 ARMCC::CondCodes Cond; // Condition for IT block.
144 unsigned Mask:4; // Condition mask for instructions.
145 // Starting at first 1 (from lsb).
146 // '1' condition as indicated in IT.
147 // '0' inverse of condition (else).
148 // Count of instructions in IT block is
149 // 4 - trailingzeroes(mask)
150
151 bool FirstCond; // Explicit flag for when we're parsing the
152 // First instruction in the IT block. It's
153 // implied in the mask, so needs special
154 // handling.
155
156 unsigned CurPosition; // Current position in parsing of IT
157 // block. In range [0,3]. Initialized
158 // according to count of instructions in block.
159 // ~0U if no active IT block.
160 } ITState;
161 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000162 void forwardITPosition() {
163 if (!inITBlock()) return;
164 // Move to the next instruction in the IT block, if there is one. If not,
165 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000166 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000167 if (++ITState.CurPosition == 5 - TZ)
168 ITState.CurPosition = ~0U; // Done with the IT block after this.
169 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000170
171
Kevin Enderbyccab3172009-09-15 00:27:25 +0000172 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000173 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
174
Benjamin Kramer673824b2012-04-15 17:04:27 +0000175 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000176 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000177 return Parser.Warning(L, Msg, Ranges);
178 }
179 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000180 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000181 return Parser.Error(L, Msg, Ranges);
182 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000183
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000184 int tryParseRegister();
185 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000186 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000187 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000188 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000189 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
190 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000191 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
192 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000193 bool parseDirectiveWord(unsigned Size, SMLoc L);
194 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000195 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000196 bool parseDirectiveThumbFunc(SMLoc L);
197 bool parseDirectiveCode(SMLoc L);
198 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000199 bool parseDirectiveReq(StringRef Name, SMLoc L);
200 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000201 bool parseDirectiveArch(SMLoc L);
202 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000203 bool parseDirectiveCPU(SMLoc L);
204 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000205 bool parseDirectiveFnStart(SMLoc L);
206 bool parseDirectiveFnEnd(SMLoc L);
207 bool parseDirectiveCantUnwind(SMLoc L);
208 bool parseDirectivePersonality(SMLoc L);
209 bool parseDirectiveHandlerData(SMLoc L);
210 bool parseDirectiveSetFP(SMLoc L);
211 bool parseDirectivePad(SMLoc L);
212 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000213 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
Kevin Enderby146dcf22009-10-15 20:48:48 +0000214
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000215 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000216 bool &CarrySetting, unsigned &ProcessorIMod,
217 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000218 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
219 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000220 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000221
Evan Cheng4d1ca962011-07-08 01:53:10 +0000222 bool isThumb() const {
223 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000224 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000225 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000226 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000227 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000228 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000229 bool isThumbTwo() const {
230 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
231 }
Tim Northovera2292d02013-06-10 23:20:58 +0000232 bool hasThumb() const {
233 return STI.getFeatureBits() & ARM::HasV4TOps;
234 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000235 bool hasV6Ops() const {
236 return STI.getFeatureBits() & ARM::HasV6Ops;
237 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000238 bool hasV6MOps() const {
239 return STI.getFeatureBits() & ARM::HasV6MOps;
240 }
James Molloy21efa7d2011-09-28 14:21:38 +0000241 bool hasV7Ops() const {
242 return STI.getFeatureBits() & ARM::HasV7Ops;
243 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000244 bool hasV8Ops() const {
245 return STI.getFeatureBits() & ARM::HasV8Ops;
246 }
Tim Northovera2292d02013-06-10 23:20:58 +0000247 bool hasARM() const {
248 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
249 }
250
Evan Cheng284b4672011-07-08 22:36:29 +0000251 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000252 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
253 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000254 }
James Molloy21efa7d2011-09-28 14:21:38 +0000255 bool isMClass() const {
256 return STI.getFeatureBits() & ARM::FeatureMClass;
257 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000258
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000259 /// @name Auto-generated Match Functions
260 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000261
Chris Lattner3e4582a2010-09-06 19:11:01 +0000262#define GET_ASSEMBLER_HEADER
263#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000264
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000265 /// }
266
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000267 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000268 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000269 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000270 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000271 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000272 OperandMatchResultTy parseCoprocOptionOperand(
273 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000274 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000275 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000276 OperandMatchResultTy parseInstSyncBarrierOptOperand(
277 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000278 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000279 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000280 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000281 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000282 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
283 StringRef Op, int Low, int High);
284 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
285 return parsePKHImm(O, "lsl", 0, 31);
286 }
287 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
288 return parsePKHImm(O, "asr", 1, 32);
289 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000290 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000291 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000292 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000293 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000294 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000295 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000296 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000297 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000298 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
299 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000300
301 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000302 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000303 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000304 void cvtThumbBranches(MCInst &Inst,
305 const SmallVectorImpl<MCParsedAsmOperand*> &);
306
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000307 bool validateInstruction(MCInst &Inst,
308 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000309 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000310 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000311 bool shouldOmitCCOutOperand(StringRef Mnemonic,
312 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000313 bool shouldOmitPredicateOperand(StringRef Mnemonic,
314 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000315public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000316 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000317 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000318 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000319 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000320 Match_RequiresThumb2,
321#define GET_OPERAND_DIAGNOSTIC_TYPES
322#include "ARMGenAsmMatcher.inc"
323
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000324 };
325
Joey Gouly0e76fa72013-09-12 10:28:05 +0000326 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
327 const MCInstrInfo &MII)
328 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000329 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000330
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000331 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000332 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000333
Evan Cheng4d1ca962011-07-08 01:53:10 +0000334 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000335 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000336
337 // Not in an ITBlock to start with.
338 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000339
340 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000341 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000342
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000343 // Implementation of the MCTargetAsmParser interface:
344 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000345 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
346 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000347 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000348 bool ParseDirective(AsmToken DirectiveID);
349
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000350 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000351 unsigned checkTargetMatchPredicate(MCInst &Inst);
352
Chad Rosier49963552012-10-13 00:26:04 +0000353 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000354 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000355 MCStreamer &Out, unsigned &ErrorInfo,
356 bool MatchingInlineAsm);
Tim Northover1744d0a2013-10-25 12:49:50 +0000357 void onLabelParsed(MCSymbol *Symbol);
David Peixottoe407d092013-12-19 18:12:36 +0000358 void finishParse();
Kevin Enderbyccab3172009-09-15 00:27:25 +0000359};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000360} // end anonymous namespace
361
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000362namespace {
363
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000364/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000365/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000366class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000367 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000368 k_CondCode,
369 k_CCOut,
370 k_ITCondMask,
371 k_CoprocNum,
372 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000373 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000374 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000375 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000376 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000377 k_Memory,
378 k_PostIndexRegister,
379 k_MSRMask,
380 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000381 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000382 k_Register,
383 k_RegisterList,
384 k_DPRRegisterList,
385 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000386 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000387 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000388 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000389 k_ShiftedRegister,
390 k_ShiftedImmediate,
391 k_ShifterImmediate,
392 k_RotateImmediate,
393 k_BitfieldDescriptor,
394 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000395 } Kind;
396
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000397 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000398 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000399
Eric Christopher8996c5d2013-03-15 00:42:55 +0000400 struct CCOp {
401 ARMCC::CondCodes Val;
402 };
403
404 struct CopOp {
405 unsigned Val;
406 };
407
408 struct CoprocOptionOp {
409 unsigned Val;
410 };
411
412 struct ITMaskOp {
413 unsigned Mask:4;
414 };
415
416 struct MBOptOp {
417 ARM_MB::MemBOpt Val;
418 };
419
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000420 struct ISBOptOp {
421 ARM_ISB::InstSyncBOpt Val;
422 };
423
Eric Christopher8996c5d2013-03-15 00:42:55 +0000424 struct IFlagsOp {
425 ARM_PROC::IFlags Val;
426 };
427
428 struct MMaskOp {
429 unsigned Val;
430 };
431
432 struct TokOp {
433 const char *Data;
434 unsigned Length;
435 };
436
437 struct RegOp {
438 unsigned RegNum;
439 };
440
441 // A vector register list is a sequential list of 1 to 4 registers.
442 struct VectorListOp {
443 unsigned RegNum;
444 unsigned Count;
445 unsigned LaneIndex;
446 bool isDoubleSpaced;
447 };
448
449 struct VectorIndexOp {
450 unsigned Val;
451 };
452
453 struct ImmOp {
454 const MCExpr *Val;
455 };
456
457 /// Combined record for all forms of ARM address expressions.
458 struct MemoryOp {
459 unsigned BaseRegNum;
460 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
461 // was specified.
462 const MCConstantExpr *OffsetImm; // Offset immediate value
463 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
464 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
465 unsigned ShiftImm; // shift for OffsetReg.
466 unsigned Alignment; // 0 = no alignment specified
467 // n = alignment in bytes (2, 4, 8, 16, or 32)
468 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
469 };
470
471 struct PostIdxRegOp {
472 unsigned RegNum;
473 bool isAdd;
474 ARM_AM::ShiftOpc ShiftTy;
475 unsigned ShiftImm;
476 };
477
478 struct ShifterImmOp {
479 bool isASR;
480 unsigned Imm;
481 };
482
483 struct RegShiftedRegOp {
484 ARM_AM::ShiftOpc ShiftTy;
485 unsigned SrcReg;
486 unsigned ShiftReg;
487 unsigned ShiftImm;
488 };
489
490 struct RegShiftedImmOp {
491 ARM_AM::ShiftOpc ShiftTy;
492 unsigned SrcReg;
493 unsigned ShiftImm;
494 };
495
496 struct RotImmOp {
497 unsigned Imm;
498 };
499
500 struct BitfieldOp {
501 unsigned LSB;
502 unsigned Width;
503 };
504
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000505 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000506 struct CCOp CC;
507 struct CopOp Cop;
508 struct CoprocOptionOp CoprocOption;
509 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000510 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000511 struct ITMaskOp ITMask;
512 struct IFlagsOp IFlags;
513 struct MMaskOp MMask;
514 struct TokOp Tok;
515 struct RegOp Reg;
516 struct VectorListOp VectorList;
517 struct VectorIndexOp VectorIndex;
518 struct ImmOp Imm;
519 struct MemoryOp Memory;
520 struct PostIdxRegOp PostIdxReg;
521 struct ShifterImmOp ShifterImm;
522 struct RegShiftedRegOp RegShiftedReg;
523 struct RegShiftedImmOp RegShiftedImm;
524 struct RotImmOp RotImm;
525 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000526 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000527
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000528 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
529public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000530 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
531 Kind = o.Kind;
532 StartLoc = o.StartLoc;
533 EndLoc = o.EndLoc;
534 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000535 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000536 CC = o.CC;
537 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000538 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000539 ITMask = o.ITMask;
540 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000541 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000542 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000543 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000544 case k_CCOut:
545 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000546 Reg = o.Reg;
547 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000548 case k_RegisterList:
549 case k_DPRRegisterList:
550 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000551 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000552 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000553 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000554 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000555 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000556 VectorList = o.VectorList;
557 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000558 case k_CoprocNum:
559 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000560 Cop = o.Cop;
561 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000562 case k_CoprocOption:
563 CoprocOption = o.CoprocOption;
564 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000565 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000566 Imm = o.Imm;
567 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000568 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000569 MBOpt = o.MBOpt;
570 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000571 case k_InstSyncBarrierOpt:
572 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000573 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000574 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000575 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000576 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000577 PostIdxReg = o.PostIdxReg;
578 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000579 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000580 MMask = o.MMask;
581 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000582 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000583 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000584 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000585 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000586 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000587 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000588 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000589 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000590 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000591 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000592 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000593 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000594 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000595 RotImm = o.RotImm;
596 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000597 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000598 Bitfield = o.Bitfield;
599 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000600 case k_VectorIndex:
601 VectorIndex = o.VectorIndex;
602 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000603 }
604 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000605
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000606 /// getStartLoc - Get the location of the first token of this operand.
607 SMLoc getStartLoc() const { return StartLoc; }
608 /// getEndLoc - Get the location of the last token of this operand.
609 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000610 /// getLocRange - Get the range between the first and last token of this
611 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000612 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
613
Daniel Dunbard8042b72010-08-11 06:36:53 +0000614 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000615 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000616 return CC.Val;
617 }
618
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000619 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000620 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000621 return Cop.Val;
622 }
623
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000624 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000625 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000626 return StringRef(Tok.Data, Tok.Length);
627 }
628
629 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000630 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000631 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000632 }
633
Bill Wendlingbed94652010-11-09 23:28:44 +0000634 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000635 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
636 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000637 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000638 }
639
Kevin Enderbyf5079942009-10-13 22:19:02 +0000640 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000641 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000642 return Imm.Val;
643 }
644
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000645 unsigned getVectorIndex() const {
646 assert(Kind == k_VectorIndex && "Invalid access!");
647 return VectorIndex.Val;
648 }
649
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000650 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000651 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000652 return MBOpt.Val;
653 }
654
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000655 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
656 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
657 return ISBOpt.Val;
658 }
659
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000660 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000661 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000662 return IFlags.Val;
663 }
664
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000665 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000666 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000667 return MMask.Val;
668 }
669
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000670 bool isCoprocNum() const { return Kind == k_CoprocNum; }
671 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000672 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000673 bool isCondCode() const { return Kind == k_CondCode; }
674 bool isCCOut() const { return Kind == k_CCOut; }
675 bool isITMask() const { return Kind == k_ITCondMask; }
676 bool isITCondCode() const { return Kind == k_CondCode; }
677 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000678 // checks whether this operand is an unsigned offset which fits is a field
679 // of specified width and scaled by a specific number of bits
680 template<unsigned width, unsigned scale>
681 bool isUnsignedOffset() const {
682 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000683 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000684 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
685 int64_t Val = CE->getValue();
686 int64_t Align = 1LL << scale;
687 int64_t Max = Align * ((1LL << width) - 1);
688 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
689 }
690 return false;
691 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000692 // checks whether this operand is an signed offset which fits is a field
693 // of specified width and scaled by a specific number of bits
694 template<unsigned width, unsigned scale>
695 bool isSignedOffset() const {
696 if (!isImm()) return false;
697 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
698 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
699 int64_t Val = CE->getValue();
700 int64_t Align = 1LL << scale;
701 int64_t Max = Align * ((1LL << (width-1)) - 1);
702 int64_t Min = -Align * (1LL << (width-1));
703 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
704 }
705 return false;
706 }
707
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000708 // checks whether this operand is a memory operand computed as an offset
709 // applied to PC. the offset may have 8 bits of magnitude and is represented
710 // with two bits of shift. textually it may be either [pc, #imm], #imm or
711 // relocable expression...
712 bool isThumbMemPC() const {
713 int64_t Val = 0;
714 if (isImm()) {
715 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
716 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
717 if (!CE) return false;
718 Val = CE->getValue();
719 }
720 else if (isMem()) {
721 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
722 if(Memory.BaseRegNum != ARM::PC) return false;
723 Val = Memory.OffsetImm->getValue();
724 }
725 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000726 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000727 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000728 bool isFPImm() const {
729 if (!isImm()) return false;
730 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
731 if (!CE) return false;
732 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
733 return Val != -1;
734 }
Jim Grosbachea231912011-12-22 22:19:05 +0000735 bool isFBits16() const {
736 if (!isImm()) return false;
737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
738 if (!CE) return false;
739 int64_t Value = CE->getValue();
740 return Value >= 0 && Value <= 16;
741 }
742 bool isFBits32() const {
743 if (!isImm()) return false;
744 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
745 if (!CE) return false;
746 int64_t Value = CE->getValue();
747 return Value >= 1 && Value <= 32;
748 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000749 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000750 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000751 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
752 if (!CE) return false;
753 int64_t Value = CE->getValue();
754 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
755 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000756 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000757 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000758 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
759 if (!CE) return false;
760 int64_t Value = CE->getValue();
761 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
762 }
763 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000764 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000765 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
766 if (!CE) return false;
767 int64_t Value = CE->getValue();
768 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
769 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000770 bool isImm0_508s4Neg() const {
771 if (!isImm()) return false;
772 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
773 if (!CE) return false;
774 int64_t Value = -CE->getValue();
775 // explicitly exclude zero. we want that to use the normal 0_508 version.
776 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
777 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000778 bool isImm0_239() const {
779 if (!isImm()) return false;
780 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
781 if (!CE) return false;
782 int64_t Value = CE->getValue();
783 return Value >= 0 && Value < 240;
784 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000785 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000786 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
788 if (!CE) return false;
789 int64_t Value = CE->getValue();
790 return Value >= 0 && Value < 256;
791 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000792 bool isImm0_4095() const {
793 if (!isImm()) return false;
794 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
795 if (!CE) return false;
796 int64_t Value = CE->getValue();
797 return Value >= 0 && Value < 4096;
798 }
799 bool isImm0_4095Neg() const {
800 if (!isImm()) return false;
801 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
802 if (!CE) return false;
803 int64_t Value = -CE->getValue();
804 return Value > 0 && Value < 4096;
805 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000806 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000807 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000808 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
809 if (!CE) return false;
810 int64_t Value = CE->getValue();
811 return Value >= 0 && Value < 2;
812 }
813 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000814 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000815 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
816 if (!CE) return false;
817 int64_t Value = CE->getValue();
818 return Value >= 0 && Value < 4;
819 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000820 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000821 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000822 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
823 if (!CE) return false;
824 int64_t Value = CE->getValue();
825 return Value >= 0 && Value < 8;
826 }
827 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000828 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000829 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
830 if (!CE) return false;
831 int64_t Value = CE->getValue();
832 return Value >= 0 && Value < 16;
833 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000834 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000835 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000836 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
837 if (!CE) return false;
838 int64_t Value = CE->getValue();
839 return Value >= 0 && Value < 32;
840 }
Jim Grosbach00326402011-12-08 01:30:04 +0000841 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000842 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000843 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
844 if (!CE) return false;
845 int64_t Value = CE->getValue();
846 return Value >= 0 && Value < 64;
847 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000848 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000849 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
851 if (!CE) return false;
852 int64_t Value = CE->getValue();
853 return Value == 8;
854 }
855 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000856 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000857 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
858 if (!CE) return false;
859 int64_t Value = CE->getValue();
860 return Value == 16;
861 }
862 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000863 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000864 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
865 if (!CE) return false;
866 int64_t Value = CE->getValue();
867 return Value == 32;
868 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000869 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000870 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000871 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
872 if (!CE) return false;
873 int64_t Value = CE->getValue();
874 return Value > 0 && Value <= 8;
875 }
876 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000877 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000878 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
879 if (!CE) return false;
880 int64_t Value = CE->getValue();
881 return Value > 0 && Value <= 16;
882 }
883 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000884 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000885 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
886 if (!CE) return false;
887 int64_t Value = CE->getValue();
888 return Value > 0 && Value <= 32;
889 }
890 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000891 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
893 if (!CE) return false;
894 int64_t Value = CE->getValue();
895 return Value > 0 && Value <= 64;
896 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000897 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000898 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000899 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
900 if (!CE) return false;
901 int64_t Value = CE->getValue();
902 return Value > 0 && Value < 8;
903 }
904 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000905 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
907 if (!CE) return false;
908 int64_t Value = CE->getValue();
909 return Value > 0 && Value < 16;
910 }
911 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000912 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
914 if (!CE) return false;
915 int64_t Value = CE->getValue();
916 return Value > 0 && Value < 32;
917 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000918 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000919 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000920 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
921 if (!CE) return false;
922 int64_t Value = CE->getValue();
923 return Value > 0 && Value < 17;
924 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000925 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000926 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
928 if (!CE) return false;
929 int64_t Value = CE->getValue();
930 return Value > 0 && Value < 33;
931 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000932 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000933 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
935 if (!CE) return false;
936 int64_t Value = CE->getValue();
937 return Value >= 0 && Value < 33;
938 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000939 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000940 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000941 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
942 if (!CE) return false;
943 int64_t Value = CE->getValue();
944 return Value >= 0 && Value < 65536;
945 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000946 bool isImm256_65535Expr() const {
947 if (!isImm()) return false;
948 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
949 // If it's not a constant expression, it'll generate a fixup and be
950 // handled later.
951 if (!CE) return true;
952 int64_t Value = CE->getValue();
953 return Value >= 256 && Value < 65536;
954 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000955 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000956 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000957 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
958 // If it's not a constant expression, it'll generate a fixup and be
959 // handled later.
960 if (!CE) return true;
961 int64_t Value = CE->getValue();
962 return Value >= 0 && Value < 65536;
963 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000964 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000965 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000966 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
967 if (!CE) return false;
968 int64_t Value = CE->getValue();
969 return Value >= 0 && Value <= 0xffffff;
970 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000971 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000972 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000973 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
974 if (!CE) return false;
975 int64_t Value = CE->getValue();
976 return Value > 0 && Value < 33;
977 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000978 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000979 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000980 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
981 if (!CE) return false;
982 int64_t Value = CE->getValue();
983 return Value >= 0 && Value < 32;
984 }
985 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000986 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000987 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
988 if (!CE) return false;
989 int64_t Value = CE->getValue();
990 return Value > 0 && Value <= 32;
991 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000992 bool isAdrLabel() const {
993 // If we have an immediate that's not a constant, treat it as a label
994 // reference needing a fixup. If it is a constant, but it can't fit
995 // into shift immediate encoding, we reject it.
996 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
997 else return (isARMSOImm() || isARMSOImmNeg());
998 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000999 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001000 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001001 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1002 if (!CE) return false;
1003 int64_t Value = CE->getValue();
1004 return ARM_AM::getSOImmVal(Value) != -1;
1005 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001006 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001007 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001008 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1009 if (!CE) return false;
1010 int64_t Value = CE->getValue();
1011 return ARM_AM::getSOImmVal(~Value) != -1;
1012 }
Jim Grosbach30506252011-12-08 00:31:07 +00001013 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001014 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001015 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1016 if (!CE) return false;
1017 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001018 // Only use this when not representable as a plain so_imm.
1019 return ARM_AM::getSOImmVal(Value) == -1 &&
1020 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001021 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001022 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001023 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001024 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1025 if (!CE) return false;
1026 int64_t Value = CE->getValue();
1027 return ARM_AM::getT2SOImmVal(Value) != -1;
1028 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001029 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001030 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001031 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1032 if (!CE) return false;
1033 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001034 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1035 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001036 }
Jim Grosbach30506252011-12-08 00:31:07 +00001037 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001038 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001039 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1040 if (!CE) return false;
1041 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001042 // Only use this when not representable as a plain so_imm.
1043 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1044 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001045 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001046 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001047 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1049 if (!CE) return false;
1050 int64_t Value = CE->getValue();
1051 return Value == 1 || Value == 0;
1052 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001053 bool isReg() const { return Kind == k_Register; }
1054 bool isRegList() const { return Kind == k_RegisterList; }
1055 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1056 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1057 bool isToken() const { return Kind == k_Token; }
1058 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001059 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +00001060 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001061 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1062 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1063 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1064 bool isRotImm() const { return Kind == k_RotateImmediate; }
1065 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1066 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001067 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001068 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001069 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001070 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +00001071 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001072 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001073 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +00001074 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1075 (alignOK || Memory.Alignment == 0);
1076 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001077 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001078 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001079 return false;
1080 // Base register must be PC.
1081 if (Memory.BaseRegNum != ARM::PC)
1082 return false;
1083 // Immediate offset in range [-4095, 4095].
1084 if (!Memory.OffsetImm) return true;
1085 int64_t Val = Memory.OffsetImm->getValue();
1086 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1087 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001088 bool isAlignedMemory() const {
1089 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001090 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001091 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001092 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001093 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001094 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001095 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001096 if (!Memory.OffsetImm) return true;
1097 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001098 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001099 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001100 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001101 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001102 // Immediate offset in range [-4095, 4095].
1103 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1104 if (!CE) return false;
1105 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001106 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001107 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001108 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001109 // If we have an immediate that's not a constant, treat it as a label
1110 // reference needing a fixup. If it is a constant, it's something else
1111 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001112 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001113 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001114 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001115 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001116 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001117 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001118 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001119 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001120 if (!Memory.OffsetImm) return true;
1121 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001122 // The #-0 offset is encoded as INT32_MIN, and we have to check
1123 // for this too.
1124 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001125 }
1126 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001127 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001128 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001129 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001130 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1131 // Immediate offset in range [-255, 255].
1132 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1133 if (!CE) return false;
1134 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001135 // Special case, #-0 is INT32_MIN.
1136 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001137 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001138 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001139 // If we have an immediate that's not a constant, treat it as a label
1140 // reference needing a fixup. If it is a constant, it's something else
1141 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001142 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001143 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001144 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001145 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001146 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001147 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001148 if (!Memory.OffsetImm) return true;
1149 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001150 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001151 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001152 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001153 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001154 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001155 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001156 return false;
1157 return true;
1158 }
1159 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001160 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001161 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1162 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001163 return false;
1164 return true;
1165 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001166 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001167 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001168 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001169 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001170 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001171 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001172 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001173 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001174 return false;
1175 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001176 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001177 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001178 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001179 return false;
1180 return true;
1181 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001182 bool isMemThumbRR() const {
1183 // Thumb reg+reg addressing is simple. Just two registers, a base and
1184 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001185 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001186 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001187 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001188 return isARMLowRegister(Memory.BaseRegNum) &&
1189 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001190 }
1191 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001192 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001193 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001194 return false;
1195 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001196 if (!Memory.OffsetImm) return true;
1197 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001198 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1199 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001200 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001201 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001202 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001203 return false;
1204 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001205 if (!Memory.OffsetImm) return true;
1206 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001207 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1208 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001209 bool isMemThumbRIs1() 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 Grosbacha32c7532011-08-19 18:49:59 +00001212 return false;
1213 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001214 if (!Memory.OffsetImm) return true;
1215 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001216 return Val >= 0 && Val <= 31;
1217 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001218 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001219 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001220 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001221 return false;
1222 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001223 if (!Memory.OffsetImm) return true;
1224 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001225 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001226 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001227 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001228 // If we have an immediate that's not a constant, treat it as a label
1229 // reference needing a fixup. If it is a constant, it's something else
1230 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001231 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001232 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001233 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001234 return false;
1235 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001236 if (!Memory.OffsetImm) return true;
1237 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001238 // Special case, #-0 is INT32_MIN.
1239 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001240 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001241 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001242 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001243 return false;
1244 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001245 if (!Memory.OffsetImm) return true;
1246 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001247 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1248 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001249 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001250 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001251 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001252 // Base reg of PC isn't allowed for these encodings.
1253 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001254 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001255 if (!Memory.OffsetImm) return true;
1256 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001257 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001258 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001259 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001260 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001261 return false;
1262 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001263 if (!Memory.OffsetImm) return true;
1264 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001265 return Val >= 0 && Val < 256;
1266 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001267 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001268 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +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 Grosbach5bfa8ba2011-09-07 20:58:57 +00001272 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001273 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001274 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001275 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001276 }
1277 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001278 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001279 return false;
1280 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001281 if (!Memory.OffsetImm) return true;
1282 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001283 return (Val >= 0 && Val < 4096);
1284 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001285 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001286 // If we have an immediate that's not a constant, treat it as a label
1287 // reference needing a fixup. If it is a constant, it's something else
1288 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001289 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001290 return true;
1291
Chad Rosier41099832012-09-11 23:02:35 +00001292 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001293 return false;
1294 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001295 if (!Memory.OffsetImm) return true;
1296 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001297 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001298 }
1299 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001300 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001301 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1302 if (!CE) return false;
1303 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001304 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001305 }
Jim Grosbach93981412011-10-11 21:55:36 +00001306 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001307 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001308 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1309 if (!CE) return false;
1310 int64_t Val = CE->getValue();
1311 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1312 (Val == INT32_MIN);
1313 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001314
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001315 bool isMSRMask() const { return Kind == k_MSRMask; }
1316 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001317
Jim Grosbach741cd732011-10-17 22:26:03 +00001318 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001319 bool isSingleSpacedVectorList() const {
1320 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1321 }
1322 bool isDoubleSpacedVectorList() const {
1323 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1324 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001325 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001326 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001327 return VectorList.Count == 1;
1328 }
1329
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001330 bool isVecListDPair() const {
1331 if (!isSingleSpacedVectorList()) return false;
1332 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1333 .contains(VectorList.RegNum));
1334 }
1335
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001336 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001337 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001338 return VectorList.Count == 3;
1339 }
1340
Jim Grosbach846bcff2011-10-21 20:35:01 +00001341 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001342 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001343 return VectorList.Count == 4;
1344 }
1345
Jim Grosbache5307f92012-03-05 21:43:40 +00001346 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001347 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001348 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1349 .contains(VectorList.RegNum));
1350 }
1351
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001352 bool isVecListThreeQ() const {
1353 if (!isDoubleSpacedVectorList()) return false;
1354 return VectorList.Count == 3;
1355 }
1356
Jim Grosbach1e946a42012-01-24 00:43:12 +00001357 bool isVecListFourQ() const {
1358 if (!isDoubleSpacedVectorList()) return false;
1359 return VectorList.Count == 4;
1360 }
1361
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001362 bool isSingleSpacedVectorAllLanes() const {
1363 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1364 }
1365 bool isDoubleSpacedVectorAllLanes() const {
1366 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1367 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001368 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001369 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001370 return VectorList.Count == 1;
1371 }
1372
Jim Grosbach13a292c2012-03-06 22:01:44 +00001373 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001374 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001375 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1376 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001377 }
1378
Jim Grosbached428bc2012-03-06 23:10:38 +00001379 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001380 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001381 return VectorList.Count == 2;
1382 }
1383
Jim Grosbachb78403c2012-01-24 23:47:04 +00001384 bool isVecListThreeDAllLanes() const {
1385 if (!isSingleSpacedVectorAllLanes()) return false;
1386 return VectorList.Count == 3;
1387 }
1388
1389 bool isVecListThreeQAllLanes() const {
1390 if (!isDoubleSpacedVectorAllLanes()) return false;
1391 return VectorList.Count == 3;
1392 }
1393
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001394 bool isVecListFourDAllLanes() const {
1395 if (!isSingleSpacedVectorAllLanes()) return false;
1396 return VectorList.Count == 4;
1397 }
1398
1399 bool isVecListFourQAllLanes() const {
1400 if (!isDoubleSpacedVectorAllLanes()) return false;
1401 return VectorList.Count == 4;
1402 }
1403
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001404 bool isSingleSpacedVectorIndexed() const {
1405 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1406 }
1407 bool isDoubleSpacedVectorIndexed() const {
1408 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1409 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001410 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001411 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001412 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1413 }
1414
Jim Grosbachda511042011-12-14 23:35:06 +00001415 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001416 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001417 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1418 }
1419
1420 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001421 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001422 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1423 }
1424
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001425 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001426 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001427 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1428 }
1429
Jim Grosbachda511042011-12-14 23:35:06 +00001430 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001431 if (!isSingleSpacedVectorIndexed()) return false;
1432 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1433 }
1434
1435 bool isVecListTwoQWordIndexed() const {
1436 if (!isDoubleSpacedVectorIndexed()) return false;
1437 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1438 }
1439
1440 bool isVecListTwoQHWordIndexed() const {
1441 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001442 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1443 }
1444
1445 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001446 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001447 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1448 }
1449
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001450 bool isVecListThreeDByteIndexed() const {
1451 if (!isSingleSpacedVectorIndexed()) return false;
1452 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1453 }
1454
1455 bool isVecListThreeDHWordIndexed() const {
1456 if (!isSingleSpacedVectorIndexed()) return false;
1457 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1458 }
1459
1460 bool isVecListThreeQWordIndexed() const {
1461 if (!isDoubleSpacedVectorIndexed()) return false;
1462 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1463 }
1464
1465 bool isVecListThreeQHWordIndexed() const {
1466 if (!isDoubleSpacedVectorIndexed()) return false;
1467 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1468 }
1469
1470 bool isVecListThreeDWordIndexed() const {
1471 if (!isSingleSpacedVectorIndexed()) return false;
1472 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1473 }
1474
Jim Grosbach14952a02012-01-24 18:37:25 +00001475 bool isVecListFourDByteIndexed() const {
1476 if (!isSingleSpacedVectorIndexed()) return false;
1477 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1478 }
1479
1480 bool isVecListFourDHWordIndexed() const {
1481 if (!isSingleSpacedVectorIndexed()) return false;
1482 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1483 }
1484
1485 bool isVecListFourQWordIndexed() const {
1486 if (!isDoubleSpacedVectorIndexed()) return false;
1487 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1488 }
1489
1490 bool isVecListFourQHWordIndexed() const {
1491 if (!isDoubleSpacedVectorIndexed()) return false;
1492 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1493 }
1494
1495 bool isVecListFourDWordIndexed() const {
1496 if (!isSingleSpacedVectorIndexed()) return false;
1497 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1498 }
1499
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001500 bool isVectorIndex8() const {
1501 if (Kind != k_VectorIndex) return false;
1502 return VectorIndex.Val < 8;
1503 }
1504 bool isVectorIndex16() const {
1505 if (Kind != k_VectorIndex) return false;
1506 return VectorIndex.Val < 4;
1507 }
1508 bool isVectorIndex32() const {
1509 if (Kind != k_VectorIndex) return false;
1510 return VectorIndex.Val < 2;
1511 }
1512
Jim Grosbach741cd732011-10-17 22:26:03 +00001513 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001514 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001515 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1516 // Must be a constant.
1517 if (!CE) return false;
1518 int64_t Value = CE->getValue();
1519 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1520 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001521 return Value >= 0 && Value < 256;
1522 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001523
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001524 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001525 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001526 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1527 // Must be a constant.
1528 if (!CE) return false;
1529 int64_t Value = CE->getValue();
1530 // i16 value in the range [0,255] or [0x0100, 0xff00]
1531 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1532 }
1533
Jim Grosbach8211c052011-10-18 00:22:00 +00001534 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001535 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001536 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1537 // Must be a constant.
1538 if (!CE) return false;
1539 int64_t Value = CE->getValue();
1540 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1541 return (Value >= 0 && Value < 256) ||
1542 (Value >= 0x0100 && Value <= 0xff00) ||
1543 (Value >= 0x010000 && Value <= 0xff0000) ||
1544 (Value >= 0x01000000 && Value <= 0xff000000);
1545 }
1546
1547 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001548 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1550 // Must be a constant.
1551 if (!CE) return false;
1552 int64_t Value = CE->getValue();
1553 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1554 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1555 return (Value >= 0 && Value < 256) ||
1556 (Value >= 0x0100 && Value <= 0xff00) ||
1557 (Value >= 0x010000 && Value <= 0xff0000) ||
1558 (Value >= 0x01000000 && Value <= 0xff000000) ||
1559 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1560 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1561 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001562 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001563 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001564 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1565 // Must be a constant.
1566 if (!CE) return false;
1567 int64_t Value = ~CE->getValue();
1568 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1569 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1570 return (Value >= 0 && Value < 256) ||
1571 (Value >= 0x0100 && Value <= 0xff00) ||
1572 (Value >= 0x010000 && Value <= 0xff0000) ||
1573 (Value >= 0x01000000 && Value <= 0xff000000) ||
1574 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1575 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1576 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001577
Jim Grosbache4454e02011-10-18 16:18:11 +00001578 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001579 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001580 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1581 // Must be a constant.
1582 if (!CE) return false;
1583 uint64_t Value = CE->getValue();
1584 // i64 value with each byte being either 0 or 0xff.
1585 for (unsigned i = 0; i < 8; ++i)
1586 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1587 return true;
1588 }
1589
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001590 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001591 // Add as immediates when possible. Null MCExpr = 0.
1592 if (Expr == 0)
1593 Inst.addOperand(MCOperand::CreateImm(0));
1594 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001595 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1596 else
1597 Inst.addOperand(MCOperand::CreateExpr(Expr));
1598 }
1599
Daniel Dunbard8042b72010-08-11 06:36:53 +00001600 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001601 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001602 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001603 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1604 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001605 }
1606
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001607 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1608 assert(N == 1 && "Invalid number of operands!");
1609 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1610 }
1611
Jim Grosbach48399582011-10-12 17:34:41 +00001612 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1613 assert(N == 1 && "Invalid number of operands!");
1614 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1615 }
1616
1617 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1618 assert(N == 1 && "Invalid number of operands!");
1619 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1620 }
1621
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001622 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1623 assert(N == 1 && "Invalid number of operands!");
1624 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1625 }
1626
1627 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
1629 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1630 }
1631
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001632 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1633 assert(N == 1 && "Invalid number of operands!");
1634 Inst.addOperand(MCOperand::CreateReg(getReg()));
1635 }
1636
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001637 void addRegOperands(MCInst &Inst, unsigned N) const {
1638 assert(N == 1 && "Invalid number of operands!");
1639 Inst.addOperand(MCOperand::CreateReg(getReg()));
1640 }
1641
Jim Grosbachac798e12011-07-25 20:49:51 +00001642 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001643 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001644 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001645 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001646 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1647 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001648 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001649 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001650 }
1651
Jim Grosbachac798e12011-07-25 20:49:51 +00001652 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001653 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001654 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001655 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001656 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001657 // Shift of #32 is encoded as 0 where permitted
1658 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001659 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001660 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001661 }
1662
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001663 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001664 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001665 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1666 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001667 }
1668
Bill Wendling8d2aa032010-11-08 23:49:57 +00001669 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001670 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001671 const SmallVectorImpl<unsigned> &RegList = getRegList();
1672 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001673 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1674 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001675 }
1676
Bill Wendling9898ac92010-11-17 04:32:08 +00001677 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1678 addRegListOperands(Inst, N);
1679 }
1680
1681 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1682 addRegListOperands(Inst, N);
1683 }
1684
Jim Grosbach833b9d32011-07-27 20:15:40 +00001685 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1686 assert(N == 1 && "Invalid number of operands!");
1687 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1688 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1689 }
1690
Jim Grosbach864b6092011-07-28 21:34:26 +00001691 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1692 assert(N == 1 && "Invalid number of operands!");
1693 // Munge the lsb/width into a bitfield mask.
1694 unsigned lsb = Bitfield.LSB;
1695 unsigned width = Bitfield.Width;
1696 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1697 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1698 (32 - (lsb + width)));
1699 Inst.addOperand(MCOperand::CreateImm(Mask));
1700 }
1701
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001702 void addImmOperands(MCInst &Inst, unsigned N) const {
1703 assert(N == 1 && "Invalid number of operands!");
1704 addExpr(Inst, getImm());
1705 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001706
Jim Grosbachea231912011-12-22 22:19:05 +00001707 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1708 assert(N == 1 && "Invalid number of operands!");
1709 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1710 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1711 }
1712
1713 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1714 assert(N == 1 && "Invalid number of operands!");
1715 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1716 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1717 }
1718
Jim Grosbache7fbce72011-10-03 23:38:36 +00001719 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1720 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001721 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1722 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1723 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001724 }
1725
Jim Grosbach7db8d692011-09-08 22:07:06 +00001726 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1727 assert(N == 1 && "Invalid number of operands!");
1728 // FIXME: We really want to scale the value here, but the LDRD/STRD
1729 // instruction don't encode operands that way yet.
1730 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1731 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1732 }
1733
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001734 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1735 assert(N == 1 && "Invalid number of operands!");
1736 // The immediate is scaled by four in the encoding and is stored
1737 // in the MCInst as such. Lop off the low two bits here.
1738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1739 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1740 }
1741
Jim Grosbach930f2f62012-04-05 20:57:13 +00001742 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1743 assert(N == 1 && "Invalid number of operands!");
1744 // The immediate is scaled by four in the encoding and is stored
1745 // in the MCInst as such. Lop off the low two bits here.
1746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1747 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1748 }
1749
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001750 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1751 assert(N == 1 && "Invalid number of operands!");
1752 // The immediate is scaled by four in the encoding and is stored
1753 // in the MCInst as such. Lop off the low two bits here.
1754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1755 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1756 }
1757
Jim Grosbach475c6db2011-07-25 23:09:14 +00001758 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1759 assert(N == 1 && "Invalid number of operands!");
1760 // The constant encodes as the immediate-1, and we store in the instruction
1761 // the bits as encoded, so subtract off one here.
1762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1763 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1764 }
1765
Jim Grosbach801e0a32011-07-22 23:16:18 +00001766 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1767 assert(N == 1 && "Invalid number of operands!");
1768 // The constant encodes as the immediate-1, and we store in the instruction
1769 // the bits as encoded, so subtract off one here.
1770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1771 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1772 }
1773
Jim Grosbach46dd4132011-08-17 21:51:27 +00001774 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1775 assert(N == 1 && "Invalid number of operands!");
1776 // The constant encodes as the immediate, except for 32, which encodes as
1777 // zero.
1778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1779 unsigned Imm = CE->getValue();
1780 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1781 }
1782
Jim Grosbach27c1e252011-07-21 17:23:04 +00001783 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1784 assert(N == 1 && "Invalid number of operands!");
1785 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1786 // the instruction as well.
1787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1788 int Val = CE->getValue();
1789 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1790 }
1791
Jim Grosbachb009a872011-10-28 22:36:30 +00001792 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1793 assert(N == 1 && "Invalid number of operands!");
1794 // The operand is actually a t2_so_imm, but we have its bitwise
1795 // negation in the assembly source, so twiddle it here.
1796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1797 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1798 }
1799
Jim Grosbach30506252011-12-08 00:31:07 +00001800 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1801 assert(N == 1 && "Invalid number of operands!");
1802 // The operand is actually a t2_so_imm, but we have its
1803 // negation in the assembly source, so twiddle it here.
1804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1805 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1806 }
1807
Jim Grosbach930f2f62012-04-05 20:57:13 +00001808 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1809 assert(N == 1 && "Invalid number of operands!");
1810 // The operand is actually an imm0_4095, but we have its
1811 // negation in the assembly source, so twiddle it here.
1812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1813 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1814 }
1815
Mihai Popad36cbaa2013-07-03 09:21:44 +00001816 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1817 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1818 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1819 return;
1820 }
1821
1822 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1823 assert(SR && "Unknown value type!");
1824 Inst.addOperand(MCOperand::CreateExpr(SR));
1825 }
1826
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001827 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1828 assert(N == 1 && "Invalid number of operands!");
1829 if (isImm()) {
1830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1831 if (CE) {
1832 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1833 return;
1834 }
1835
1836 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1837 assert(SR && "Unknown value type!");
1838 Inst.addOperand(MCOperand::CreateExpr(SR));
1839 return;
1840 }
1841
1842 assert(isMem() && "Unknown value type!");
1843 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1844 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1845 }
1846
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001847 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1848 assert(N == 1 && "Invalid number of operands!");
1849 // The operand is actually a so_imm, but we have its bitwise
1850 // negation in the assembly source, so twiddle it here.
1851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1852 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1853 }
1854
Jim Grosbach30506252011-12-08 00:31:07 +00001855 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1856 assert(N == 1 && "Invalid number of operands!");
1857 // The operand is actually a so_imm, but we have its
1858 // negation in the assembly source, so twiddle it here.
1859 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1860 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1861 }
1862
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001863 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1864 assert(N == 1 && "Invalid number of operands!");
1865 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1866 }
1867
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001868 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1869 assert(N == 1 && "Invalid number of operands!");
1870 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1871 }
1872
Jim Grosbachd3595712011-08-03 23:50:40 +00001873 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1874 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001875 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001876 }
1877
Jim Grosbach94298a92012-01-18 22:46:46 +00001878 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1879 assert(N == 1 && "Invalid number of operands!");
1880 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001881 Inst.addOperand(MCOperand::CreateImm(Imm));
1882 }
1883
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001884 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1885 assert(N == 1 && "Invalid number of operands!");
1886 assert(isImm() && "Not an immediate!");
1887
1888 // If we have an immediate that's not a constant, treat it as a label
1889 // reference needing a fixup.
1890 if (!isa<MCConstantExpr>(getImm())) {
1891 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1892 return;
1893 }
1894
1895 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1896 int Val = CE->getValue();
1897 Inst.addOperand(MCOperand::CreateImm(Val));
1898 }
1899
Jim Grosbacha95ec992011-10-11 17:29:55 +00001900 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1901 assert(N == 2 && "Invalid number of operands!");
1902 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1903 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1904 }
1905
Jim Grosbachd3595712011-08-03 23:50:40 +00001906 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1907 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001908 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1909 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001910 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1911 // Special case for #-0
1912 if (Val == INT32_MIN) Val = 0;
1913 if (Val < 0) Val = -Val;
1914 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1915 } else {
1916 // For register offset, we encode the shift type and negation flag
1917 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001918 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1919 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001920 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001921 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1922 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001923 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001924 }
1925
Jim Grosbachcd17c122011-08-04 23:01:30 +00001926 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1927 assert(N == 2 && "Invalid number of operands!");
1928 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1929 assert(CE && "non-constant AM2OffsetImm operand!");
1930 int32_t Val = CE->getValue();
1931 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1932 // Special case for #-0
1933 if (Val == INT32_MIN) Val = 0;
1934 if (Val < 0) Val = -Val;
1935 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1936 Inst.addOperand(MCOperand::CreateReg(0));
1937 Inst.addOperand(MCOperand::CreateImm(Val));
1938 }
1939
Jim Grosbach5b96b802011-08-10 20:29:19 +00001940 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1941 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001942 // If we have an immediate that's not a constant, treat it as a label
1943 // reference needing a fixup. If it is a constant, it's something else
1944 // and we reject it.
1945 if (isImm()) {
1946 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1947 Inst.addOperand(MCOperand::CreateReg(0));
1948 Inst.addOperand(MCOperand::CreateImm(0));
1949 return;
1950 }
1951
Jim Grosbach871dff72011-10-11 15:59:20 +00001952 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1953 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001954 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1955 // Special case for #-0
1956 if (Val == INT32_MIN) Val = 0;
1957 if (Val < 0) Val = -Val;
1958 Val = ARM_AM::getAM3Opc(AddSub, Val);
1959 } else {
1960 // For register offset, we encode the shift type and negation flag
1961 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001962 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001963 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001964 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1965 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001966 Inst.addOperand(MCOperand::CreateImm(Val));
1967 }
1968
1969 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1970 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001971 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001972 int32_t Val =
1973 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1974 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1975 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001976 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001977 }
1978
1979 // Constant offset.
1980 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1981 int32_t Val = CE->getValue();
1982 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1983 // Special case for #-0
1984 if (Val == INT32_MIN) Val = 0;
1985 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001986 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001987 Inst.addOperand(MCOperand::CreateReg(0));
1988 Inst.addOperand(MCOperand::CreateImm(Val));
1989 }
1990
Jim Grosbachd3595712011-08-03 23:50:40 +00001991 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1992 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001993 // If we have an immediate that's not a constant, treat it as a label
1994 // reference needing a fixup. If it is a constant, it's something else
1995 // and we reject it.
1996 if (isImm()) {
1997 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1998 Inst.addOperand(MCOperand::CreateImm(0));
1999 return;
2000 }
2001
Jim Grosbachd3595712011-08-03 23:50:40 +00002002 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002003 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002004 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2005 // Special case for #-0
2006 if (Val == INT32_MIN) Val = 0;
2007 if (Val < 0) Val = -Val;
2008 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002009 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002010 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002011 }
2012
Jim Grosbach7db8d692011-09-08 22:07:06 +00002013 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2014 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002015 // If we have an immediate that's not a constant, treat it as a label
2016 // reference needing a fixup. If it is a constant, it's something else
2017 // and we reject it.
2018 if (isImm()) {
2019 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2020 Inst.addOperand(MCOperand::CreateImm(0));
2021 return;
2022 }
2023
Jim Grosbach871dff72011-10-11 15:59:20 +00002024 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2025 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002026 Inst.addOperand(MCOperand::CreateImm(Val));
2027 }
2028
Jim Grosbacha05627e2011-09-09 18:37:27 +00002029 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2030 assert(N == 2 && "Invalid number of operands!");
2031 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002032 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2033 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002034 Inst.addOperand(MCOperand::CreateImm(Val));
2035 }
2036
Jim Grosbachd3595712011-08-03 23:50:40 +00002037 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2038 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002039 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2040 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002041 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002042 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002043
Jim Grosbach2392c532011-09-07 23:39:14 +00002044 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2045 addMemImm8OffsetOperands(Inst, N);
2046 }
2047
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002048 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002049 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002050 }
2051
2052 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 2 && "Invalid number of operands!");
2054 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002055 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002056 addExpr(Inst, getImm());
2057 Inst.addOperand(MCOperand::CreateImm(0));
2058 return;
2059 }
2060
2061 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002062 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2063 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002064 Inst.addOperand(MCOperand::CreateImm(Val));
2065 }
2066
Jim Grosbachd3595712011-08-03 23:50:40 +00002067 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2068 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002069 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002070 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002071 addExpr(Inst, getImm());
2072 Inst.addOperand(MCOperand::CreateImm(0));
2073 return;
2074 }
2075
2076 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002077 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2078 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002079 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002080 }
Bill Wendling811c9362010-11-30 07:44:32 +00002081
Jim Grosbach05541f42011-09-19 22:21:13 +00002082 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2083 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002084 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2085 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002086 }
2087
2088 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2089 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002090 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2091 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002092 }
2093
Jim Grosbachd3595712011-08-03 23:50:40 +00002094 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2095 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002096 unsigned Val =
2097 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2098 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002099 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2100 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002101 Inst.addOperand(MCOperand::CreateImm(Val));
2102 }
2103
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002104 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2105 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002106 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2107 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2108 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002109 }
2110
Jim Grosbachd3595712011-08-03 23:50:40 +00002111 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002113 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2114 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002115 }
2116
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002117 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2118 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002119 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2120 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002121 Inst.addOperand(MCOperand::CreateImm(Val));
2122 }
2123
Jim Grosbach26d35872011-08-19 18:55:51 +00002124 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2125 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002126 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2127 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002128 Inst.addOperand(MCOperand::CreateImm(Val));
2129 }
2130
Jim Grosbacha32c7532011-08-19 18:49:59 +00002131 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2132 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002133 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2134 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002135 Inst.addOperand(MCOperand::CreateImm(Val));
2136 }
2137
Jim Grosbach23983d62011-08-19 18:13:48 +00002138 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2139 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002140 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2141 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002142 Inst.addOperand(MCOperand::CreateImm(Val));
2143 }
2144
Jim Grosbachd3595712011-08-03 23:50:40 +00002145 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2146 assert(N == 1 && "Invalid number of operands!");
2147 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2148 assert(CE && "non-constant post-idx-imm8 operand!");
2149 int Imm = CE->getValue();
2150 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002151 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002152 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2153 Inst.addOperand(MCOperand::CreateImm(Imm));
2154 }
2155
Jim Grosbach93981412011-10-11 21:55:36 +00002156 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2157 assert(N == 1 && "Invalid number of operands!");
2158 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2159 assert(CE && "non-constant post-idx-imm8s4 operand!");
2160 int Imm = CE->getValue();
2161 bool isAdd = Imm >= 0;
2162 if (Imm == INT32_MIN) Imm = 0;
2163 // Immediate is scaled by 4.
2164 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2165 Inst.addOperand(MCOperand::CreateImm(Imm));
2166 }
2167
Jim Grosbachd3595712011-08-03 23:50:40 +00002168 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2169 assert(N == 2 && "Invalid number of operands!");
2170 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002171 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2172 }
2173
2174 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2175 assert(N == 2 && "Invalid number of operands!");
2176 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2177 // The sign, shift type, and shift amount are encoded in a single operand
2178 // using the AM2 encoding helpers.
2179 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2180 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2181 PostIdxReg.ShiftTy);
2182 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002183 }
2184
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002185 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2186 assert(N == 1 && "Invalid number of operands!");
2187 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2188 }
2189
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002190 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2191 assert(N == 1 && "Invalid number of operands!");
2192 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2193 }
2194
Jim Grosbach182b6a02011-11-29 23:51:09 +00002195 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002196 assert(N == 1 && "Invalid number of operands!");
2197 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2198 }
2199
Jim Grosbach04945c42011-12-02 00:35:16 +00002200 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2201 assert(N == 2 && "Invalid number of operands!");
2202 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2203 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2204 }
2205
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002206 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2207 assert(N == 1 && "Invalid number of operands!");
2208 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2209 }
2210
2211 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2212 assert(N == 1 && "Invalid number of operands!");
2213 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2214 }
2215
2216 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2217 assert(N == 1 && "Invalid number of operands!");
2218 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2219 }
2220
Jim Grosbach741cd732011-10-17 22:26:03 +00002221 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2222 assert(N == 1 && "Invalid number of operands!");
2223 // The immediate encodes the type of constant as well as the value.
2224 // Mask in that this is an i8 splat.
2225 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2226 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2227 }
2228
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002229 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2230 assert(N == 1 && "Invalid number of operands!");
2231 // The immediate encodes the type of constant as well as the value.
2232 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2233 unsigned Value = CE->getValue();
2234 if (Value >= 256)
2235 Value = (Value >> 8) | 0xa00;
2236 else
2237 Value |= 0x800;
2238 Inst.addOperand(MCOperand::CreateImm(Value));
2239 }
2240
Jim Grosbach8211c052011-10-18 00:22:00 +00002241 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2242 assert(N == 1 && "Invalid number of operands!");
2243 // The immediate encodes the type of constant as well as the value.
2244 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2245 unsigned Value = CE->getValue();
2246 if (Value >= 256 && Value <= 0xff00)
2247 Value = (Value >> 8) | 0x200;
2248 else if (Value > 0xffff && Value <= 0xff0000)
2249 Value = (Value >> 16) | 0x400;
2250 else if (Value > 0xffffff)
2251 Value = (Value >> 24) | 0x600;
2252 Inst.addOperand(MCOperand::CreateImm(Value));
2253 }
2254
2255 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2256 assert(N == 1 && "Invalid number of operands!");
2257 // The immediate encodes the type of constant as well as the value.
2258 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2259 unsigned Value = CE->getValue();
2260 if (Value >= 256 && Value <= 0xffff)
2261 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2262 else if (Value > 0xffff && Value <= 0xffffff)
2263 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2264 else if (Value > 0xffffff)
2265 Value = (Value >> 24) | 0x600;
2266 Inst.addOperand(MCOperand::CreateImm(Value));
2267 }
2268
Jim Grosbach045b6c72011-12-19 23:51:07 +00002269 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2270 assert(N == 1 && "Invalid number of operands!");
2271 // The immediate encodes the type of constant as well as the value.
2272 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2273 unsigned Value = ~CE->getValue();
2274 if (Value >= 256 && Value <= 0xffff)
2275 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2276 else if (Value > 0xffff && Value <= 0xffffff)
2277 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2278 else if (Value > 0xffffff)
2279 Value = (Value >> 24) | 0x600;
2280 Inst.addOperand(MCOperand::CreateImm(Value));
2281 }
2282
Jim Grosbache4454e02011-10-18 16:18:11 +00002283 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2284 assert(N == 1 && "Invalid number of operands!");
2285 // The immediate encodes the type of constant as well as the value.
2286 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2287 uint64_t Value = CE->getValue();
2288 unsigned Imm = 0;
2289 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2290 Imm |= (Value & 1) << i;
2291 }
2292 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2293 }
2294
Jim Grosbach602aa902011-07-13 15:34:57 +00002295 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002296
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002297 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002298 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002299 Op->ITMask.Mask = Mask;
2300 Op->StartLoc = S;
2301 Op->EndLoc = S;
2302 return Op;
2303 }
2304
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002305 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002306 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002307 Op->CC.Val = CC;
2308 Op->StartLoc = S;
2309 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002310 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002311 }
2312
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002313 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002314 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002315 Op->Cop.Val = CopVal;
2316 Op->StartLoc = S;
2317 Op->EndLoc = S;
2318 return Op;
2319 }
2320
2321 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002322 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002323 Op->Cop.Val = CopVal;
2324 Op->StartLoc = S;
2325 Op->EndLoc = S;
2326 return Op;
2327 }
2328
Jim Grosbach48399582011-10-12 17:34:41 +00002329 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2330 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2331 Op->Cop.Val = Val;
2332 Op->StartLoc = S;
2333 Op->EndLoc = E;
2334 return Op;
2335 }
2336
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002337 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002338 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002339 Op->Reg.RegNum = RegNum;
2340 Op->StartLoc = S;
2341 Op->EndLoc = S;
2342 return Op;
2343 }
2344
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002345 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002346 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002347 Op->Tok.Data = Str.data();
2348 Op->Tok.Length = Str.size();
2349 Op->StartLoc = S;
2350 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002351 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002352 }
2353
Bill Wendling2063b842010-11-18 23:43:05 +00002354 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002355 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002356 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002357 Op->StartLoc = S;
2358 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002359 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002360 }
2361
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002362 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2363 unsigned SrcReg,
2364 unsigned ShiftReg,
2365 unsigned ShiftImm,
2366 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002367 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002368 Op->RegShiftedReg.ShiftTy = ShTy;
2369 Op->RegShiftedReg.SrcReg = SrcReg;
2370 Op->RegShiftedReg.ShiftReg = ShiftReg;
2371 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002372 Op->StartLoc = S;
2373 Op->EndLoc = E;
2374 return Op;
2375 }
2376
Owen Andersonb595ed02011-07-21 18:54:16 +00002377 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2378 unsigned SrcReg,
2379 unsigned ShiftImm,
2380 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002381 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002382 Op->RegShiftedImm.ShiftTy = ShTy;
2383 Op->RegShiftedImm.SrcReg = SrcReg;
2384 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002385 Op->StartLoc = S;
2386 Op->EndLoc = E;
2387 return Op;
2388 }
2389
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002390 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002391 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002392 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002393 Op->ShifterImm.isASR = isASR;
2394 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002395 Op->StartLoc = S;
2396 Op->EndLoc = E;
2397 return Op;
2398 }
2399
Jim Grosbach833b9d32011-07-27 20:15:40 +00002400 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002401 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002402 Op->RotImm.Imm = Imm;
2403 Op->StartLoc = S;
2404 Op->EndLoc = E;
2405 return Op;
2406 }
2407
Jim Grosbach864b6092011-07-28 21:34:26 +00002408 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2409 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002410 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002411 Op->Bitfield.LSB = LSB;
2412 Op->Bitfield.Width = Width;
2413 Op->StartLoc = S;
2414 Op->EndLoc = E;
2415 return Op;
2416 }
2417
Bill Wendling2cae3272010-11-09 22:44:22 +00002418 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002419 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002420 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002421 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002422 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002423
Chad Rosierfa705ee2013-07-01 20:49:23 +00002424 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002425 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002426 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002427 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002428 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002429
Chad Rosierfa705ee2013-07-01 20:49:23 +00002430 // Sort based on the register encoding values.
2431 array_pod_sort(Regs.begin(), Regs.end());
2432
Bill Wendling9898ac92010-11-17 04:32:08 +00002433 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002434 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002435 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002436 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002437 Op->StartLoc = StartLoc;
2438 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002439 return Op;
2440 }
2441
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002442 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002443 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002444 ARMOperand *Op = new ARMOperand(k_VectorList);
2445 Op->VectorList.RegNum = RegNum;
2446 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002447 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002448 Op->StartLoc = S;
2449 Op->EndLoc = E;
2450 return Op;
2451 }
2452
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002453 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002454 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002455 SMLoc S, SMLoc E) {
2456 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2457 Op->VectorList.RegNum = RegNum;
2458 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002459 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002460 Op->StartLoc = S;
2461 Op->EndLoc = E;
2462 return Op;
2463 }
2464
Jim Grosbach04945c42011-12-02 00:35:16 +00002465 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002466 unsigned Index,
2467 bool isDoubleSpaced,
2468 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002469 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2470 Op->VectorList.RegNum = RegNum;
2471 Op->VectorList.Count = Count;
2472 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002473 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002474 Op->StartLoc = S;
2475 Op->EndLoc = E;
2476 return Op;
2477 }
2478
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002479 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2480 MCContext &Ctx) {
2481 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2482 Op->VectorIndex.Val = Idx;
2483 Op->StartLoc = S;
2484 Op->EndLoc = E;
2485 return Op;
2486 }
2487
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002488 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002489 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002490 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002491 Op->StartLoc = S;
2492 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002493 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002494 }
2495
Jim Grosbachd3595712011-08-03 23:50:40 +00002496 static ARMOperand *CreateMem(unsigned BaseRegNum,
2497 const MCConstantExpr *OffsetImm,
2498 unsigned OffsetRegNum,
2499 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002500 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002501 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002502 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002503 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002504 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002505 Op->Memory.BaseRegNum = BaseRegNum;
2506 Op->Memory.OffsetImm = OffsetImm;
2507 Op->Memory.OffsetRegNum = OffsetRegNum;
2508 Op->Memory.ShiftType = ShiftType;
2509 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002510 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002511 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002512 Op->StartLoc = S;
2513 Op->EndLoc = E;
2514 return Op;
2515 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002516
Jim Grosbachc320c852011-08-05 21:28:30 +00002517 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2518 ARM_AM::ShiftOpc ShiftTy,
2519 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002520 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002521 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002522 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002523 Op->PostIdxReg.isAdd = isAdd;
2524 Op->PostIdxReg.ShiftTy = ShiftTy;
2525 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002526 Op->StartLoc = S;
2527 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002528 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002529 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002530
2531 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002532 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002533 Op->MBOpt.Val = Opt;
2534 Op->StartLoc = S;
2535 Op->EndLoc = S;
2536 return Op;
2537 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002538
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002539 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2540 SMLoc S) {
2541 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2542 Op->ISBOpt.Val = Opt;
2543 Op->StartLoc = S;
2544 Op->EndLoc = S;
2545 return Op;
2546 }
2547
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002548 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002549 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002550 Op->IFlags.Val = IFlags;
2551 Op->StartLoc = S;
2552 Op->EndLoc = S;
2553 return Op;
2554 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002555
2556 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002557 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002558 Op->MMask.Val = MMask;
2559 Op->StartLoc = S;
2560 Op->EndLoc = S;
2561 return Op;
2562 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002563};
2564
2565} // end anonymous namespace.
2566
Jim Grosbach602aa902011-07-13 15:34:57 +00002567void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002568 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002569 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002570 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002571 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002572 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002573 OS << "<ccout " << getReg() << ">";
2574 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002575 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002576 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002577 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2578 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2579 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002580 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2581 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2582 break;
2583 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002584 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002585 OS << "<coprocessor number: " << getCoproc() << ">";
2586 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002587 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002588 OS << "<coprocessor register: " << getCoproc() << ">";
2589 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002590 case k_CoprocOption:
2591 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2592 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002593 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002594 OS << "<mask: " << getMSRMask() << ">";
2595 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002596 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002597 getImm()->print(OS);
2598 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002599 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002600 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002601 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002602 case k_InstSyncBarrierOpt:
2603 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2604 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002605 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002606 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002607 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002608 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002609 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002610 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002611 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2612 << PostIdxReg.RegNum;
2613 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2614 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2615 << PostIdxReg.ShiftImm;
2616 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002617 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002618 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002619 OS << "<ARM_PROC::";
2620 unsigned IFlags = getProcIFlags();
2621 for (int i=2; i >= 0; --i)
2622 if (IFlags & (1 << i))
2623 OS << ARM_PROC::IFlagsToString(1 << i);
2624 OS << ">";
2625 break;
2626 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002627 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002628 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002629 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002630 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002631 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2632 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002633 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002634 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002635 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002636 << RegShiftedReg.SrcReg << " "
2637 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2638 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002639 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002640 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002641 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002642 << RegShiftedImm.SrcReg << " "
2643 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2644 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002645 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002646 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002647 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2648 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002649 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002650 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2651 << ", width: " << Bitfield.Width << ">";
2652 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002653 case k_RegisterList:
2654 case k_DPRRegisterList:
2655 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002656 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002657
Bill Wendlingbed94652010-11-09 23:28:44 +00002658 const SmallVectorImpl<unsigned> &RegList = getRegList();
2659 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002660 I = RegList.begin(), E = RegList.end(); I != E; ) {
2661 OS << *I;
2662 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002663 }
2664
2665 OS << ">";
2666 break;
2667 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002668 case k_VectorList:
2669 OS << "<vector_list " << VectorList.Count << " * "
2670 << VectorList.RegNum << ">";
2671 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002672 case k_VectorListAllLanes:
2673 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2674 << VectorList.RegNum << ">";
2675 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002676 case k_VectorListIndexed:
2677 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2678 << VectorList.Count << " * " << VectorList.RegNum << ">";
2679 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002680 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002681 OS << "'" << getToken() << "'";
2682 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002683 case k_VectorIndex:
2684 OS << "<vectorindex " << getVectorIndex() << ">";
2685 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002686 }
2687}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002688
2689/// @name Auto-generated Match Functions
2690/// {
2691
2692static unsigned MatchRegisterName(StringRef Name);
2693
2694/// }
2695
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002696bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2697 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002698 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002699 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002700 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002701
2702 return (RegNo == (unsigned)-1);
2703}
2704
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002705/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002706/// and if it is a register name the token is eaten and the register number is
2707/// returned. Otherwise return -1.
2708///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002709int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002710 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002711 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002712
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002713 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002714 unsigned RegNum = MatchRegisterName(lowerCase);
2715 if (!RegNum) {
2716 RegNum = StringSwitch<unsigned>(lowerCase)
2717 .Case("r13", ARM::SP)
2718 .Case("r14", ARM::LR)
2719 .Case("r15", ARM::PC)
2720 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002721 // Additional register name aliases for 'gas' compatibility.
2722 .Case("a1", ARM::R0)
2723 .Case("a2", ARM::R1)
2724 .Case("a3", ARM::R2)
2725 .Case("a4", ARM::R3)
2726 .Case("v1", ARM::R4)
2727 .Case("v2", ARM::R5)
2728 .Case("v3", ARM::R6)
2729 .Case("v4", ARM::R7)
2730 .Case("v5", ARM::R8)
2731 .Case("v6", ARM::R9)
2732 .Case("v7", ARM::R10)
2733 .Case("v8", ARM::R11)
2734 .Case("sb", ARM::R9)
2735 .Case("sl", ARM::R10)
2736 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002737 .Default(0);
2738 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002739 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002740 // Check for aliases registered via .req. Canonicalize to lower case.
2741 // That's more consistent since register names are case insensitive, and
2742 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2743 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002744 // If no match, return failure.
2745 if (Entry == RegisterReqs.end())
2746 return -1;
2747 Parser.Lex(); // Eat identifier token.
2748 return Entry->getValue();
2749 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002750
Chris Lattner44e5981c2010-10-30 04:09:10 +00002751 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002752
Chris Lattner44e5981c2010-10-30 04:09:10 +00002753 return RegNum;
2754}
Jim Grosbach99710a82010-11-01 16:44:21 +00002755
Jim Grosbachbb24c592011-07-13 18:49:30 +00002756// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2757// If a recoverable error occurs, return 1. If an irrecoverable error
2758// occurs, return -1. An irrecoverable error is one where tokens have been
2759// consumed in the process of trying to parse the shifter (i.e., when it is
2760// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002761int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002762 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2763 SMLoc S = Parser.getTok().getLoc();
2764 const AsmToken &Tok = Parser.getTok();
2765 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2766
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002767 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002768 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002769 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002770 .Case("lsl", ARM_AM::lsl)
2771 .Case("lsr", ARM_AM::lsr)
2772 .Case("asr", ARM_AM::asr)
2773 .Case("ror", ARM_AM::ror)
2774 .Case("rrx", ARM_AM::rrx)
2775 .Default(ARM_AM::no_shift);
2776
2777 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002778 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002779
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002780 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002781
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002782 // The source register for the shift has already been added to the
2783 // operand list, so we need to pop it off and combine it into the shifted
2784 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002785 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002786 if (!PrevOp->isReg())
2787 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2788 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002789
2790 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002791 int64_t Imm = 0;
2792 int ShiftReg = 0;
2793 if (ShiftTy == ARM_AM::rrx) {
2794 // RRX Doesn't have an explicit shift amount. The encoder expects
2795 // the shift register to be the same as the source register. Seems odd,
2796 // but OK.
2797 ShiftReg = SrcReg;
2798 } else {
2799 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002800 if (Parser.getTok().is(AsmToken::Hash) ||
2801 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002802 Parser.Lex(); // Eat hash.
2803 SMLoc ImmLoc = Parser.getTok().getLoc();
2804 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002805 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002806 Error(ImmLoc, "invalid immediate shift value");
2807 return -1;
2808 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002809 // The expression must be evaluatable as an immediate.
2810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002811 if (!CE) {
2812 Error(ImmLoc, "invalid immediate shift value");
2813 return -1;
2814 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002815 // Range check the immediate.
2816 // lsl, ror: 0 <= imm <= 31
2817 // lsr, asr: 0 <= imm <= 32
2818 Imm = CE->getValue();
2819 if (Imm < 0 ||
2820 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2821 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002822 Error(ImmLoc, "immediate shift value out of range");
2823 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002824 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002825 // shift by zero is a nop. Always send it through as lsl.
2826 // ('as' compatibility)
2827 if (Imm == 0)
2828 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002829 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002830 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002831 EndLoc = Parser.getTok().getEndLoc();
2832 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002833 if (ShiftReg == -1) {
2834 Error (L, "expected immediate or register in shift operand");
2835 return -1;
2836 }
2837 } else {
2838 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002839 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002840 return -1;
2841 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002842 }
2843
Owen Andersonb595ed02011-07-21 18:54:16 +00002844 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2845 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002846 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002847 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002848 else
2849 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002850 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002851
Jim Grosbachbb24c592011-07-13 18:49:30 +00002852 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002853}
2854
2855
Bill Wendling2063b842010-11-18 23:43:05 +00002856/// Try to parse a register name. The token must be an Identifier when called.
2857/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2858/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002859///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002860/// TODO this is likely to change to allow different register types and or to
2861/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002862bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002863tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002864 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002865 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002866 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002867 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002868
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002869 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2870 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002871
Chris Lattner44e5981c2010-10-30 04:09:10 +00002872 const AsmToken &ExclaimTok = Parser.getTok();
2873 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002874 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2875 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002876 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002877 return false;
2878 }
2879
2880 // Also check for an index operand. This is only legal for vector registers,
2881 // but that'll get caught OK in operand matching, so we don't need to
2882 // explicitly filter everything else out here.
2883 if (Parser.getTok().is(AsmToken::LBrac)) {
2884 SMLoc SIdx = Parser.getTok().getLoc();
2885 Parser.Lex(); // Eat left bracket token.
2886
2887 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002888 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002889 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002890 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002891 if (!MCE)
2892 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002893
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002894 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002895 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002896
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002897 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002898 Parser.Lex(); // Eat right bracket token.
2899
2900 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2901 SIdx, E,
2902 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002903 }
2904
Bill Wendling2063b842010-11-18 23:43:05 +00002905 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002906}
2907
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002908/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2909/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2910/// "c5", ...
2911static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002912 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2913 // but efficient.
2914 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002915 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002916 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002917 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002918 return -1;
2919 switch (Name[1]) {
2920 default: return -1;
2921 case '0': return 0;
2922 case '1': return 1;
2923 case '2': return 2;
2924 case '3': return 3;
2925 case '4': return 4;
2926 case '5': return 5;
2927 case '6': return 6;
2928 case '7': return 7;
2929 case '8': return 8;
2930 case '9': return 9;
2931 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002932 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002933 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002934 return -1;
2935 switch (Name[2]) {
2936 default: return -1;
Artyom Skrobov86534432013-11-08 09:16:31 +00002937 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2938 case '0': return CoprocOp == 'p'? -1: 10;
2939 case '1': return CoprocOp == 'p'? -1: 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002940 case '2': return 12;
2941 case '3': return 13;
2942 case '4': return 14;
2943 case '5': return 15;
2944 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002945 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002946}
2947
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002948/// parseITCondCode - Try to parse a condition code for an IT instruction.
2949ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2950parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2951 SMLoc S = Parser.getTok().getLoc();
2952 const AsmToken &Tok = Parser.getTok();
2953 if (!Tok.is(AsmToken::Identifier))
2954 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002955 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002956 .Case("eq", ARMCC::EQ)
2957 .Case("ne", ARMCC::NE)
2958 .Case("hs", ARMCC::HS)
2959 .Case("cs", ARMCC::HS)
2960 .Case("lo", ARMCC::LO)
2961 .Case("cc", ARMCC::LO)
2962 .Case("mi", ARMCC::MI)
2963 .Case("pl", ARMCC::PL)
2964 .Case("vs", ARMCC::VS)
2965 .Case("vc", ARMCC::VC)
2966 .Case("hi", ARMCC::HI)
2967 .Case("ls", ARMCC::LS)
2968 .Case("ge", ARMCC::GE)
2969 .Case("lt", ARMCC::LT)
2970 .Case("gt", ARMCC::GT)
2971 .Case("le", ARMCC::LE)
2972 .Case("al", ARMCC::AL)
2973 .Default(~0U);
2974 if (CC == ~0U)
2975 return MatchOperand_NoMatch;
2976 Parser.Lex(); // Eat the token.
2977
2978 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2979
2980 return MatchOperand_Success;
2981}
2982
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002983/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002984/// token must be an Identifier when called, and if it is a coprocessor
2985/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002986ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002987parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002988 SMLoc S = Parser.getTok().getLoc();
2989 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002990 if (Tok.isNot(AsmToken::Identifier))
2991 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002992
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002993 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002994 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002995 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002996
2997 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002998 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002999 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003000}
3001
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003002/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003003/// token must be an Identifier when called, and if it is a coprocessor
3004/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003005ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003006parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003007 SMLoc S = Parser.getTok().getLoc();
3008 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003009 if (Tok.isNot(AsmToken::Identifier))
3010 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003011
3012 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3013 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003014 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003015
3016 Parser.Lex(); // Eat identifier token.
3017 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003018 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003019}
3020
Jim Grosbach48399582011-10-12 17:34:41 +00003021/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3022/// coproc_option : '{' imm0_255 '}'
3023ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3024parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3025 SMLoc S = Parser.getTok().getLoc();
3026
3027 // If this isn't a '{', this isn't a coprocessor immediate operand.
3028 if (Parser.getTok().isNot(AsmToken::LCurly))
3029 return MatchOperand_NoMatch;
3030 Parser.Lex(); // Eat the '{'
3031
3032 const MCExpr *Expr;
3033 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003034 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003035 Error(Loc, "illegal expression");
3036 return MatchOperand_ParseFail;
3037 }
3038 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3039 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3040 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3041 return MatchOperand_ParseFail;
3042 }
3043 int Val = CE->getValue();
3044
3045 // Check for and consume the closing '}'
3046 if (Parser.getTok().isNot(AsmToken::RCurly))
3047 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003048 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003049 Parser.Lex(); // Eat the '}'
3050
3051 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3052 return MatchOperand_Success;
3053}
3054
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003055// For register list parsing, we need to map from raw GPR register numbering
3056// to the enumeration values. The enumeration values aren't sorted by
3057// register number due to our using "sp", "lr" and "pc" as canonical names.
3058static unsigned getNextRegister(unsigned Reg) {
3059 // If this is a GPR, we need to do it manually, otherwise we can rely
3060 // on the sort ordering of the enumeration since the other reg-classes
3061 // are sane.
3062 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3063 return Reg + 1;
3064 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003065 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003066 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3067 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3068 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3069 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3070 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3071 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3072 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3073 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3074 }
3075}
3076
Jim Grosbach85a23432011-11-11 21:27:40 +00003077// Return the low-subreg of a given Q register.
3078static unsigned getDRegFromQReg(unsigned QReg) {
3079 switch (QReg) {
3080 default: llvm_unreachable("expected a Q register!");
3081 case ARM::Q0: return ARM::D0;
3082 case ARM::Q1: return ARM::D2;
3083 case ARM::Q2: return ARM::D4;
3084 case ARM::Q3: return ARM::D6;
3085 case ARM::Q4: return ARM::D8;
3086 case ARM::Q5: return ARM::D10;
3087 case ARM::Q6: return ARM::D12;
3088 case ARM::Q7: return ARM::D14;
3089 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003090 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003091 case ARM::Q10: return ARM::D20;
3092 case ARM::Q11: return ARM::D22;
3093 case ARM::Q12: return ARM::D24;
3094 case ARM::Q13: return ARM::D26;
3095 case ARM::Q14: return ARM::D28;
3096 case ARM::Q15: return ARM::D30;
3097 }
3098}
3099
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003100/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003101bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003102parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003103 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003104 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003105 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003106 Parser.Lex(); // Eat '{' token.
3107 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003108
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003109 // Check the first register in the list to see what register class
3110 // this is a list of.
3111 int Reg = tryParseRegister();
3112 if (Reg == -1)
3113 return Error(RegLoc, "register expected");
3114
Jim Grosbach85a23432011-11-11 21:27:40 +00003115 // The reglist instructions have at most 16 registers, so reserve
3116 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003117 int EReg = 0;
3118 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003119
3120 // Allow Q regs and just interpret them as the two D sub-registers.
3121 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3122 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003123 EReg = MRI->getEncodingValue(Reg);
3124 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003125 ++Reg;
3126 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003127 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003128 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3129 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3130 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3131 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3132 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3133 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3134 else
3135 return Error(RegLoc, "invalid register in register list");
3136
Jim Grosbach85a23432011-11-11 21:27:40 +00003137 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003138 EReg = MRI->getEncodingValue(Reg);
3139 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003140
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003141 // This starts immediately after the first register token in the list,
3142 // so we can see either a comma or a minus (range separator) as a legal
3143 // next token.
3144 while (Parser.getTok().is(AsmToken::Comma) ||
3145 Parser.getTok().is(AsmToken::Minus)) {
3146 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003147 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003148 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003149 int EndReg = tryParseRegister();
3150 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003151 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003152 // Allow Q regs and just interpret them as the two D sub-registers.
3153 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3154 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003155 // If the register is the same as the start reg, there's nothing
3156 // more to do.
3157 if (Reg == EndReg)
3158 continue;
3159 // The register must be in the same register class as the first.
3160 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003161 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003162 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003163 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003164 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003165
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003166 // Add all the registers in the range to the register list.
3167 while (Reg != EndReg) {
3168 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003169 EReg = MRI->getEncodingValue(Reg);
3170 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003171 }
3172 continue;
3173 }
3174 Parser.Lex(); // Eat the comma.
3175 RegLoc = Parser.getTok().getLoc();
3176 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003177 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003178 Reg = tryParseRegister();
3179 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003180 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003181 // Allow Q regs and just interpret them as the two D sub-registers.
3182 bool isQReg = false;
3183 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3184 Reg = getDRegFromQReg(Reg);
3185 isQReg = true;
3186 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003187 // The register must be in the same register class as the first.
3188 if (!RC->contains(Reg))
3189 return Error(RegLoc, "invalid register in register list");
3190 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003191 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003192 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3193 Warning(RegLoc, "register list not in ascending order");
3194 else
3195 return Error(RegLoc, "register list not in ascending order");
3196 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003197 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003198 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3199 ") in register list");
3200 continue;
3201 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003202 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003203 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3204 Reg != OldReg + 1)
3205 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003206 EReg = MRI->getEncodingValue(Reg);
3207 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3208 if (isQReg) {
3209 EReg = MRI->getEncodingValue(++Reg);
3210 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3211 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003212 }
3213
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003214 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003215 return Error(Parser.getTok().getLoc(), "'}' expected");
3216 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003217 Parser.Lex(); // Eat '}' token.
3218
Jim Grosbach18bf3632011-12-13 21:48:29 +00003219 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003220 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003221
3222 // The ARM system instruction variants for LDM/STM have a '^' token here.
3223 if (Parser.getTok().is(AsmToken::Caret)) {
3224 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3225 Parser.Lex(); // Eat '^' token.
3226 }
3227
Bill Wendling2063b842010-11-18 23:43:05 +00003228 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003229}
3230
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003231// Helper function to parse the lane index for vector lists.
3232ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003233parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003234 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003235 if (Parser.getTok().is(AsmToken::LBrac)) {
3236 Parser.Lex(); // Eat the '['.
3237 if (Parser.getTok().is(AsmToken::RBrac)) {
3238 // "Dn[]" is the 'all lanes' syntax.
3239 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003240 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003241 Parser.Lex(); // Eat the ']'.
3242 return MatchOperand_Success;
3243 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003244
3245 // There's an optional '#' token here. Normally there wouldn't be, but
3246 // inline assemble puts one in, and it's friendly to accept that.
3247 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003248 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003249
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003250 const MCExpr *LaneIndex;
3251 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003252 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003253 Error(Loc, "illegal expression");
3254 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003255 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003256 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3257 if (!CE) {
3258 Error(Loc, "lane index must be empty or an integer");
3259 return MatchOperand_ParseFail;
3260 }
3261 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3262 Error(Parser.getTok().getLoc(), "']' expected");
3263 return MatchOperand_ParseFail;
3264 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003265 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003266 Parser.Lex(); // Eat the ']'.
3267 int64_t Val = CE->getValue();
3268
3269 // FIXME: Make this range check context sensitive for .8, .16, .32.
3270 if (Val < 0 || Val > 7) {
3271 Error(Parser.getTok().getLoc(), "lane index out of range");
3272 return MatchOperand_ParseFail;
3273 }
3274 Index = Val;
3275 LaneKind = IndexedLane;
3276 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003277 }
3278 LaneKind = NoLanes;
3279 return MatchOperand_Success;
3280}
3281
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003282// parse a vector register list
3283ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3284parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003285 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003286 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003287 SMLoc S = Parser.getTok().getLoc();
3288 // As an extension (to match gas), support a plain D register or Q register
3289 // (without encosing curly braces) as a single or double entry list,
3290 // respectively.
3291 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003292 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003293 int Reg = tryParseRegister();
3294 if (Reg == -1)
3295 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003296 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003297 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003298 if (Res != MatchOperand_Success)
3299 return Res;
3300 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003301 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003302 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003303 break;
3304 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003305 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3306 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003307 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003308 case IndexedLane:
3309 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003310 LaneIndex,
3311 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003312 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003313 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003314 return MatchOperand_Success;
3315 }
3316 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3317 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003318 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003319 if (Res != MatchOperand_Success)
3320 return Res;
3321 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003322 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003323 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003324 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003325 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003326 break;
3327 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003328 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3329 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003330 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3331 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003332 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003333 case IndexedLane:
3334 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003335 LaneIndex,
3336 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003337 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003338 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003339 return MatchOperand_Success;
3340 }
3341 Error(S, "vector register expected");
3342 return MatchOperand_ParseFail;
3343 }
3344
3345 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003346 return MatchOperand_NoMatch;
3347
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003348 Parser.Lex(); // Eat '{' token.
3349 SMLoc RegLoc = Parser.getTok().getLoc();
3350
3351 int Reg = tryParseRegister();
3352 if (Reg == -1) {
3353 Error(RegLoc, "register expected");
3354 return MatchOperand_ParseFail;
3355 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003356 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003357 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003358 unsigned FirstReg = Reg;
3359 // The list is of D registers, but we also allow Q regs and just interpret
3360 // them as the two D sub-registers.
3361 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3362 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003363 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3364 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003365 ++Reg;
3366 ++Count;
3367 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003368
3369 SMLoc E;
3370 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003371 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003372
Jim Grosbache891fe82011-11-15 23:19:15 +00003373 while (Parser.getTok().is(AsmToken::Comma) ||
3374 Parser.getTok().is(AsmToken::Minus)) {
3375 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003376 if (!Spacing)
3377 Spacing = 1; // Register range implies a single spaced list.
3378 else if (Spacing == 2) {
3379 Error(Parser.getTok().getLoc(),
3380 "sequential registers in double spaced list");
3381 return MatchOperand_ParseFail;
3382 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003383 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003384 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003385 int EndReg = tryParseRegister();
3386 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003387 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003388 return MatchOperand_ParseFail;
3389 }
3390 // Allow Q regs and just interpret them as the two D sub-registers.
3391 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3392 EndReg = getDRegFromQReg(EndReg) + 1;
3393 // If the register is the same as the start reg, there's nothing
3394 // more to do.
3395 if (Reg == EndReg)
3396 continue;
3397 // The register must be in the same register class as the first.
3398 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003399 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003400 return MatchOperand_ParseFail;
3401 }
3402 // Ranges must go from low to high.
3403 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003404 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003405 return MatchOperand_ParseFail;
3406 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003407 // Parse the lane specifier if present.
3408 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003409 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003410 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3411 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003412 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003413 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003414 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003415 return MatchOperand_ParseFail;
3416 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003417
3418 // Add all the registers in the range to the register list.
3419 Count += EndReg - Reg;
3420 Reg = EndReg;
3421 continue;
3422 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003423 Parser.Lex(); // Eat the comma.
3424 RegLoc = Parser.getTok().getLoc();
3425 int OldReg = Reg;
3426 Reg = tryParseRegister();
3427 if (Reg == -1) {
3428 Error(RegLoc, "register expected");
3429 return MatchOperand_ParseFail;
3430 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003431 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003432 // It's OK to use the enumeration values directly here rather, as the
3433 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003434 //
3435 // The list is of D registers, but we also allow Q regs and just interpret
3436 // them as the two D sub-registers.
3437 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003438 if (!Spacing)
3439 Spacing = 1; // Register range implies a single spaced list.
3440 else if (Spacing == 2) {
3441 Error(RegLoc,
3442 "invalid register in double-spaced list (must be 'D' register')");
3443 return MatchOperand_ParseFail;
3444 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003445 Reg = getDRegFromQReg(Reg);
3446 if (Reg != OldReg + 1) {
3447 Error(RegLoc, "non-contiguous register range");
3448 return MatchOperand_ParseFail;
3449 }
3450 ++Reg;
3451 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003452 // Parse the lane specifier if present.
3453 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003454 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003455 SMLoc LaneLoc = Parser.getTok().getLoc();
3456 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3457 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003458 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003459 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003460 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003461 return MatchOperand_ParseFail;
3462 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003463 continue;
3464 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003465 // Normal D register.
3466 // Figure out the register spacing (single or double) of the list if
3467 // we don't know it already.
3468 if (!Spacing)
3469 Spacing = 1 + (Reg == OldReg + 2);
3470
3471 // Just check that it's contiguous and keep going.
3472 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003473 Error(RegLoc, "non-contiguous register range");
3474 return MatchOperand_ParseFail;
3475 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003476 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003477 // Parse the lane specifier if present.
3478 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003479 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003480 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003481 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003482 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003483 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003484 Error(EndLoc, "mismatched lane index in register list");
3485 return MatchOperand_ParseFail;
3486 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003487 }
3488
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003489 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003490 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003491 return MatchOperand_ParseFail;
3492 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003493 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003494 Parser.Lex(); // Eat '}' token.
3495
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003496 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003497 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003498 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003499 // composite register classes.
3500 if (Count == 2) {
3501 const MCRegisterClass *RC = (Spacing == 1) ?
3502 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3503 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3504 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3505 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003506
Jim Grosbach2f50e922011-12-15 21:44:33 +00003507 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3508 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003509 break;
3510 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003511 // Two-register operands have been converted to the
3512 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003513 if (Count == 2) {
3514 const MCRegisterClass *RC = (Spacing == 1) ?
3515 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3516 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003517 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3518 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003519 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003520 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003521 S, E));
3522 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003523 case IndexedLane:
3524 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003525 LaneIndex,
3526 (Spacing == 2),
3527 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003528 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003529 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003530 return MatchOperand_Success;
3531}
3532
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003533/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003534ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003535parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003536 SMLoc S = Parser.getTok().getLoc();
3537 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003538 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003539
Jiangning Liu288e1af2012-08-02 08:21:27 +00003540 if (Tok.is(AsmToken::Identifier)) {
3541 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003542
Jiangning Liu288e1af2012-08-02 08:21:27 +00003543 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3544 .Case("sy", ARM_MB::SY)
3545 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003546 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003547 .Case("sh", ARM_MB::ISH)
3548 .Case("ish", ARM_MB::ISH)
3549 .Case("shst", ARM_MB::ISHST)
3550 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003551 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003552 .Case("nsh", ARM_MB::NSH)
3553 .Case("un", ARM_MB::NSH)
3554 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003555 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003556 .Case("unst", ARM_MB::NSHST)
3557 .Case("osh", ARM_MB::OSH)
3558 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003559 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003560 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003561
Joey Gouly926d3f52013-09-05 15:35:24 +00003562 // ishld, oshld, nshld and ld are only available from ARMv8.
3563 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3564 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3565 Opt = ~0U;
3566
Jiangning Liu288e1af2012-08-02 08:21:27 +00003567 if (Opt == ~0U)
3568 return MatchOperand_NoMatch;
3569
3570 Parser.Lex(); // Eat identifier token.
3571 } else if (Tok.is(AsmToken::Hash) ||
3572 Tok.is(AsmToken::Dollar) ||
3573 Tok.is(AsmToken::Integer)) {
3574 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003575 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003576 SMLoc Loc = Parser.getTok().getLoc();
3577
3578 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003579 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003580 Error(Loc, "illegal expression");
3581 return MatchOperand_ParseFail;
3582 }
3583
3584 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3585 if (!CE) {
3586 Error(Loc, "constant expression expected");
3587 return MatchOperand_ParseFail;
3588 }
3589
3590 int Val = CE->getValue();
3591 if (Val & ~0xf) {
3592 Error(Loc, "immediate value out of range");
3593 return MatchOperand_ParseFail;
3594 }
3595
3596 Opt = ARM_MB::RESERVED_0 + Val;
3597 } else
3598 return MatchOperand_ParseFail;
3599
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003600 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003601 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003602}
3603
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003604/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3605ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3606parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3607 SMLoc S = Parser.getTok().getLoc();
3608 const AsmToken &Tok = Parser.getTok();
3609 unsigned Opt;
3610
3611 if (Tok.is(AsmToken::Identifier)) {
3612 StringRef OptStr = Tok.getString();
3613
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003614 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003615 Opt = ARM_ISB::SY;
3616 else
3617 return MatchOperand_NoMatch;
3618
3619 Parser.Lex(); // Eat identifier token.
3620 } else if (Tok.is(AsmToken::Hash) ||
3621 Tok.is(AsmToken::Dollar) ||
3622 Tok.is(AsmToken::Integer)) {
3623 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003624 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003625 SMLoc Loc = Parser.getTok().getLoc();
3626
3627 const MCExpr *ISBarrierID;
3628 if (getParser().parseExpression(ISBarrierID)) {
3629 Error(Loc, "illegal expression");
3630 return MatchOperand_ParseFail;
3631 }
3632
3633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3634 if (!CE) {
3635 Error(Loc, "constant expression expected");
3636 return MatchOperand_ParseFail;
3637 }
3638
3639 int Val = CE->getValue();
3640 if (Val & ~0xf) {
3641 Error(Loc, "immediate value out of range");
3642 return MatchOperand_ParseFail;
3643 }
3644
3645 Opt = ARM_ISB::RESERVED_0 + Val;
3646 } else
3647 return MatchOperand_ParseFail;
3648
3649 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3650 (ARM_ISB::InstSyncBOpt)Opt, S));
3651 return MatchOperand_Success;
3652}
3653
3654
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003655/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003656ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003657parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003658 SMLoc S = Parser.getTok().getLoc();
3659 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003660 if (!Tok.is(AsmToken::Identifier))
3661 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003662 StringRef IFlagsStr = Tok.getString();
3663
Owen Anderson10c5b122011-10-05 17:16:40 +00003664 // An iflags string of "none" is interpreted to mean that none of the AIF
3665 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003666 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003667 if (IFlagsStr != "none") {
3668 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3669 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3670 .Case("a", ARM_PROC::A)
3671 .Case("i", ARM_PROC::I)
3672 .Case("f", ARM_PROC::F)
3673 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003674
Owen Anderson10c5b122011-10-05 17:16:40 +00003675 // If some specific iflag is already set, it means that some letter is
3676 // present more than once, this is not acceptable.
3677 if (Flag == ~0U || (IFlags & Flag))
3678 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003679
Owen Anderson10c5b122011-10-05 17:16:40 +00003680 IFlags |= Flag;
3681 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003682 }
3683
3684 Parser.Lex(); // Eat identifier token.
3685 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3686 return MatchOperand_Success;
3687}
3688
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003689/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003690ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003691parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003692 SMLoc S = Parser.getTok().getLoc();
3693 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003694 if (!Tok.is(AsmToken::Identifier))
3695 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003696 StringRef Mask = Tok.getString();
3697
James Molloy21efa7d2011-09-28 14:21:38 +00003698 if (isMClass()) {
3699 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003700 std::string Name = Mask.lower();
3701 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003702 // Note: in the documentation:
3703 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3704 // for MSR APSR_nzcvq.
3705 // but we do make it an alias here. This is so to get the "mask encoding"
3706 // bits correct on MSR APSR writes.
3707 //
3708 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3709 // should really only be allowed when writing a special register. Note
3710 // they get dropped in the MRS instruction reading a special register as
3711 // the SYSm field is only 8 bits.
3712 //
3713 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3714 // includes the DSP extension but that is not checked.
3715 .Case("apsr", 0x800)
3716 .Case("apsr_nzcvq", 0x800)
3717 .Case("apsr_g", 0x400)
3718 .Case("apsr_nzcvqg", 0xc00)
3719 .Case("iapsr", 0x801)
3720 .Case("iapsr_nzcvq", 0x801)
3721 .Case("iapsr_g", 0x401)
3722 .Case("iapsr_nzcvqg", 0xc01)
3723 .Case("eapsr", 0x802)
3724 .Case("eapsr_nzcvq", 0x802)
3725 .Case("eapsr_g", 0x402)
3726 .Case("eapsr_nzcvqg", 0xc02)
3727 .Case("xpsr", 0x803)
3728 .Case("xpsr_nzcvq", 0x803)
3729 .Case("xpsr_g", 0x403)
3730 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003731 .Case("ipsr", 0x805)
3732 .Case("epsr", 0x806)
3733 .Case("iepsr", 0x807)
3734 .Case("msp", 0x808)
3735 .Case("psp", 0x809)
3736 .Case("primask", 0x810)
3737 .Case("basepri", 0x811)
3738 .Case("basepri_max", 0x812)
3739 .Case("faultmask", 0x813)
3740 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003741 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003742
James Molloy21efa7d2011-09-28 14:21:38 +00003743 if (FlagsVal == ~0U)
3744 return MatchOperand_NoMatch;
3745
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003746 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003747 // basepri, basepri_max and faultmask only valid for V7m.
3748 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003749
James Molloy21efa7d2011-09-28 14:21:38 +00003750 Parser.Lex(); // Eat identifier token.
3751 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3752 return MatchOperand_Success;
3753 }
3754
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003755 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3756 size_t Start = 0, Next = Mask.find('_');
3757 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003758 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003759 if (Next != StringRef::npos)
3760 Flags = Mask.slice(Next+1, Mask.size());
3761
3762 // FlagsVal contains the complete mask:
3763 // 3-0: Mask
3764 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3765 unsigned FlagsVal = 0;
3766
3767 if (SpecReg == "apsr") {
3768 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003769 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003770 .Case("g", 0x4) // same as CPSR_s
3771 .Case("nzcvqg", 0xc) // same as CPSR_fs
3772 .Default(~0U);
3773
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003774 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003775 if (!Flags.empty())
3776 return MatchOperand_NoMatch;
3777 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003778 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003779 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003780 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003781 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3782 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003783 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003784 for (int i = 0, e = Flags.size(); i != e; ++i) {
3785 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3786 .Case("c", 1)
3787 .Case("x", 2)
3788 .Case("s", 4)
3789 .Case("f", 8)
3790 .Default(~0U);
3791
3792 // If some specific flag is already set, it means that some letter is
3793 // present more than once, this is not acceptable.
3794 if (FlagsVal == ~0U || (FlagsVal & Flag))
3795 return MatchOperand_NoMatch;
3796 FlagsVal |= Flag;
3797 }
3798 } else // No match for special register.
3799 return MatchOperand_NoMatch;
3800
Owen Anderson03a173e2011-10-21 18:43:28 +00003801 // Special register without flags is NOT equivalent to "fc" flags.
3802 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3803 // two lines would enable gas compatibility at the expense of breaking
3804 // round-tripping.
3805 //
3806 // if (!FlagsVal)
3807 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003808
3809 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3810 if (SpecReg == "spsr")
3811 FlagsVal |= 16;
3812
3813 Parser.Lex(); // Eat identifier token.
3814 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3815 return MatchOperand_Success;
3816}
3817
Jim Grosbach27c1e252011-07-21 17:23:04 +00003818ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3819parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3820 int Low, int High) {
3821 const AsmToken &Tok = Parser.getTok();
3822 if (Tok.isNot(AsmToken::Identifier)) {
3823 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3824 return MatchOperand_ParseFail;
3825 }
3826 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003827 std::string LowerOp = Op.lower();
3828 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003829 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3830 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3831 return MatchOperand_ParseFail;
3832 }
3833 Parser.Lex(); // Eat shift type token.
3834
3835 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003836 if (Parser.getTok().isNot(AsmToken::Hash) &&
3837 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003838 Error(Parser.getTok().getLoc(), "'#' expected");
3839 return MatchOperand_ParseFail;
3840 }
3841 Parser.Lex(); // Eat hash token.
3842
3843 const MCExpr *ShiftAmount;
3844 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003845 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003846 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003847 Error(Loc, "illegal expression");
3848 return MatchOperand_ParseFail;
3849 }
3850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3851 if (!CE) {
3852 Error(Loc, "constant expression expected");
3853 return MatchOperand_ParseFail;
3854 }
3855 int Val = CE->getValue();
3856 if (Val < Low || Val > High) {
3857 Error(Loc, "immediate value out of range");
3858 return MatchOperand_ParseFail;
3859 }
3860
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003861 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003862
3863 return MatchOperand_Success;
3864}
3865
Jim Grosbach0a547702011-07-22 17:44:50 +00003866ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3867parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3868 const AsmToken &Tok = Parser.getTok();
3869 SMLoc S = Tok.getLoc();
3870 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003871 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003872 return MatchOperand_ParseFail;
3873 }
Tim Northover4d141442013-05-31 15:58:45 +00003874 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003875 .Case("be", 1)
3876 .Case("le", 0)
3877 .Default(-1);
3878 Parser.Lex(); // Eat the token.
3879
3880 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003881 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003882 return MatchOperand_ParseFail;
3883 }
3884 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3885 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003886 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003887 return MatchOperand_Success;
3888}
3889
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003890/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3891/// instructions. Legal values are:
3892/// lsl #n 'n' in [0,31]
3893/// asr #n 'n' in [1,32]
3894/// n == 32 encoded as n == 0.
3895ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3896parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3897 const AsmToken &Tok = Parser.getTok();
3898 SMLoc S = Tok.getLoc();
3899 if (Tok.isNot(AsmToken::Identifier)) {
3900 Error(S, "shift operator 'asr' or 'lsl' expected");
3901 return MatchOperand_ParseFail;
3902 }
3903 StringRef ShiftName = Tok.getString();
3904 bool isASR;
3905 if (ShiftName == "lsl" || ShiftName == "LSL")
3906 isASR = false;
3907 else if (ShiftName == "asr" || ShiftName == "ASR")
3908 isASR = true;
3909 else {
3910 Error(S, "shift operator 'asr' or 'lsl' expected");
3911 return MatchOperand_ParseFail;
3912 }
3913 Parser.Lex(); // Eat the operator.
3914
3915 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003916 if (Parser.getTok().isNot(AsmToken::Hash) &&
3917 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003918 Error(Parser.getTok().getLoc(), "'#' expected");
3919 return MatchOperand_ParseFail;
3920 }
3921 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003922 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003923
3924 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003925 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003926 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003927 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003928 return MatchOperand_ParseFail;
3929 }
3930 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3931 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003932 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003933 return MatchOperand_ParseFail;
3934 }
3935
3936 int64_t Val = CE->getValue();
3937 if (isASR) {
3938 // Shift amount must be in [1,32]
3939 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003940 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003941 return MatchOperand_ParseFail;
3942 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003943 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3944 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003945 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003946 return MatchOperand_ParseFail;
3947 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003948 if (Val == 32) Val = 0;
3949 } else {
3950 // Shift amount must be in [1,32]
3951 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003952 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003953 return MatchOperand_ParseFail;
3954 }
3955 }
3956
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003957 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003958
3959 return MatchOperand_Success;
3960}
3961
Jim Grosbach833b9d32011-07-27 20:15:40 +00003962/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3963/// of instructions. Legal values are:
3964/// ror #n 'n' in {0, 8, 16, 24}
3965ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3966parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3967 const AsmToken &Tok = Parser.getTok();
3968 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003969 if (Tok.isNot(AsmToken::Identifier))
3970 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003971 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003972 if (ShiftName != "ror" && ShiftName != "ROR")
3973 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003974 Parser.Lex(); // Eat the operator.
3975
3976 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003977 if (Parser.getTok().isNot(AsmToken::Hash) &&
3978 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003979 Error(Parser.getTok().getLoc(), "'#' expected");
3980 return MatchOperand_ParseFail;
3981 }
3982 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003983 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003984
3985 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003986 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003987 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003988 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003989 return MatchOperand_ParseFail;
3990 }
3991 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3992 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003993 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003994 return MatchOperand_ParseFail;
3995 }
3996
3997 int64_t Val = CE->getValue();
3998 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3999 // normally, zero is represented in asm by omitting the rotate operand
4000 // entirely.
4001 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004002 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004003 return MatchOperand_ParseFail;
4004 }
4005
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004006 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004007
4008 return MatchOperand_Success;
4009}
4010
Jim Grosbach864b6092011-07-28 21:34:26 +00004011ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4012parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4013 SMLoc S = Parser.getTok().getLoc();
4014 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004015 if (Parser.getTok().isNot(AsmToken::Hash) &&
4016 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004017 Error(Parser.getTok().getLoc(), "'#' expected");
4018 return MatchOperand_ParseFail;
4019 }
4020 Parser.Lex(); // Eat hash token.
4021
4022 const MCExpr *LSBExpr;
4023 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004024 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004025 Error(E, "malformed immediate expression");
4026 return MatchOperand_ParseFail;
4027 }
4028 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4029 if (!CE) {
4030 Error(E, "'lsb' operand must be an immediate");
4031 return MatchOperand_ParseFail;
4032 }
4033
4034 int64_t LSB = CE->getValue();
4035 // The LSB must be in the range [0,31]
4036 if (LSB < 0 || LSB > 31) {
4037 Error(E, "'lsb' operand must be in the range [0,31]");
4038 return MatchOperand_ParseFail;
4039 }
4040 E = Parser.getTok().getLoc();
4041
4042 // Expect another immediate operand.
4043 if (Parser.getTok().isNot(AsmToken::Comma)) {
4044 Error(Parser.getTok().getLoc(), "too few operands");
4045 return MatchOperand_ParseFail;
4046 }
4047 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004048 if (Parser.getTok().isNot(AsmToken::Hash) &&
4049 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004050 Error(Parser.getTok().getLoc(), "'#' expected");
4051 return MatchOperand_ParseFail;
4052 }
4053 Parser.Lex(); // Eat hash token.
4054
4055 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004056 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004057 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004058 Error(E, "malformed immediate expression");
4059 return MatchOperand_ParseFail;
4060 }
4061 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4062 if (!CE) {
4063 Error(E, "'width' operand must be an immediate");
4064 return MatchOperand_ParseFail;
4065 }
4066
4067 int64_t Width = CE->getValue();
4068 // The LSB must be in the range [1,32-lsb]
4069 if (Width < 1 || Width > 32 - LSB) {
4070 Error(E, "'width' operand must be in the range [1,32-lsb]");
4071 return MatchOperand_ParseFail;
4072 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004073
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004074 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004075
4076 return MatchOperand_Success;
4077}
4078
Jim Grosbachd3595712011-08-03 23:50:40 +00004079ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4080parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4081 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004082 // postidx_reg := '+' register {, shift}
4083 // | '-' register {, shift}
4084 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004085
4086 // This method must return MatchOperand_NoMatch without consuming any tokens
4087 // in the case where there is no match, as other alternatives take other
4088 // parse methods.
4089 AsmToken Tok = Parser.getTok();
4090 SMLoc S = Tok.getLoc();
4091 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004092 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004093 if (Tok.is(AsmToken::Plus)) {
4094 Parser.Lex(); // Eat the '+' token.
4095 haveEaten = true;
4096 } else if (Tok.is(AsmToken::Minus)) {
4097 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004098 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004099 haveEaten = true;
4100 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004101
4102 SMLoc E = Parser.getTok().getEndLoc();
4103 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004104 if (Reg == -1) {
4105 if (!haveEaten)
4106 return MatchOperand_NoMatch;
4107 Error(Parser.getTok().getLoc(), "register expected");
4108 return MatchOperand_ParseFail;
4109 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004110
Jim Grosbachc320c852011-08-05 21:28:30 +00004111 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4112 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004113 if (Parser.getTok().is(AsmToken::Comma)) {
4114 Parser.Lex(); // Eat the ','.
4115 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4116 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004117
4118 // FIXME: Only approximates end...may include intervening whitespace.
4119 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004120 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004121
4122 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4123 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004124
4125 return MatchOperand_Success;
4126}
4127
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004128ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4129parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4130 // Check for a post-index addressing register operand. Specifically:
4131 // am3offset := '+' register
4132 // | '-' register
4133 // | register
4134 // | # imm
4135 // | # + imm
4136 // | # - imm
4137
4138 // This method must return MatchOperand_NoMatch without consuming any tokens
4139 // in the case where there is no match, as other alternatives take other
4140 // parse methods.
4141 AsmToken Tok = Parser.getTok();
4142 SMLoc S = Tok.getLoc();
4143
4144 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004145 if (Parser.getTok().is(AsmToken::Hash) ||
4146 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004147 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004148 // Explicitly look for a '-', as we need to encode negative zero
4149 // differently.
4150 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4151 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004152 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004153 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004154 return MatchOperand_ParseFail;
4155 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4156 if (!CE) {
4157 Error(S, "constant expression expected");
4158 return MatchOperand_ParseFail;
4159 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004160 // Negative zero is encoded as the flag value INT32_MIN.
4161 int32_t Val = CE->getValue();
4162 if (isNegative && Val == 0)
4163 Val = INT32_MIN;
4164
4165 Operands.push_back(
4166 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4167
4168 return MatchOperand_Success;
4169 }
4170
4171
4172 bool haveEaten = false;
4173 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004174 if (Tok.is(AsmToken::Plus)) {
4175 Parser.Lex(); // Eat the '+' token.
4176 haveEaten = true;
4177 } else if (Tok.is(AsmToken::Minus)) {
4178 Parser.Lex(); // Eat the '-' token.
4179 isAdd = false;
4180 haveEaten = true;
4181 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004182
4183 Tok = Parser.getTok();
4184 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004185 if (Reg == -1) {
4186 if (!haveEaten)
4187 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004188 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004189 return MatchOperand_ParseFail;
4190 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004191
4192 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004193 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004194
4195 return MatchOperand_Success;
4196}
4197
Tim Northovereb5e4d52013-07-22 09:06:12 +00004198/// Convert parsed operands to MCInst. Needed here because this instruction
4199/// only has two register operands, but multiplication is commutative so
4200/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004201void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004202cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004203 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004204 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4205 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004206 // If we have a three-operand form, make sure to set Rn to be the operand
4207 // that isn't the same as Rd.
4208 unsigned RegOp = 4;
4209 if (Operands.size() == 6 &&
4210 ((ARMOperand*)Operands[4])->getReg() ==
4211 ((ARMOperand*)Operands[3])->getReg())
4212 RegOp = 5;
4213 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4214 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004215 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004216}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004217
Mihai Popaad18d3c2013-08-09 10:38:32 +00004218void ARMAsmParser::
4219cvtThumbBranches(MCInst &Inst,
4220 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4221 int CondOp = -1, ImmOp = -1;
4222 switch(Inst.getOpcode()) {
4223 case ARM::tB:
4224 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4225
4226 case ARM::t2B:
4227 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4228
4229 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4230 }
4231 // first decide whether or not the branch should be conditional
4232 // by looking at it's location relative to an IT block
4233 if(inITBlock()) {
4234 // inside an IT block we cannot have any conditional branches. any
4235 // such instructions needs to be converted to unconditional form
4236 switch(Inst.getOpcode()) {
4237 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4238 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4239 }
4240 } else {
4241 // outside IT blocks we can only have unconditional branches with AL
4242 // condition code or conditional branches with non-AL condition code
4243 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4244 switch(Inst.getOpcode()) {
4245 case ARM::tB:
4246 case ARM::tBcc:
4247 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4248 break;
4249 case ARM::t2B:
4250 case ARM::t2Bcc:
4251 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4252 break;
4253 }
4254 }
4255
4256 // now decide on encoding size based on branch target range
4257 switch(Inst.getOpcode()) {
4258 // classify tB as either t2B or t1B based on range of immediate operand
4259 case ARM::tB: {
4260 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4261 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4262 Inst.setOpcode(ARM::t2B);
4263 break;
4264 }
4265 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4266 case ARM::tBcc: {
4267 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4268 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4269 Inst.setOpcode(ARM::t2Bcc);
4270 break;
4271 }
4272 }
4273 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4274 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4275}
4276
Bill Wendlinge18980a2010-11-06 22:36:58 +00004277/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004278/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004279bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004280parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004281 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004282 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004283 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004284 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004285 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004286
Sean Callanan936b0d32010-01-19 21:44:56 +00004287 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004288 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004289 if (BaseRegNum == -1)
4290 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004291
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004292 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004293 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004294 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4295 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004296 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004297
Jim Grosbachd3595712011-08-03 23:50:40 +00004298 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004299 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004300 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004301
Jim Grosbachd3595712011-08-03 23:50:40 +00004302 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004303 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004304
Jim Grosbach40700e02011-09-19 18:42:21 +00004305 // If there's a pre-indexing writeback marker, '!', just add it as a token
4306 // operand. It's rather odd, but syntactically valid.
4307 if (Parser.getTok().is(AsmToken::Exclaim)) {
4308 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4309 Parser.Lex(); // Eat the '!'.
4310 }
4311
Jim Grosbachd3595712011-08-03 23:50:40 +00004312 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004313 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004314
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004315 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4316 "Lost colon or comma in memory operand?!");
4317 if (Tok.is(AsmToken::Comma)) {
4318 Parser.Lex(); // Eat the comma.
4319 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004320
Jim Grosbacha95ec992011-10-11 17:29:55 +00004321 // If we have a ':', it's an alignment specifier.
4322 if (Parser.getTok().is(AsmToken::Colon)) {
4323 Parser.Lex(); // Eat the ':'.
4324 E = Parser.getTok().getLoc();
4325
4326 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004327 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004328 return true;
4329
4330 // The expression has to be a constant. Memory references with relocations
4331 // don't come through here, as they use the <label> forms of the relevant
4332 // instructions.
4333 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4334 if (!CE)
4335 return Error (E, "constant expression expected");
4336
4337 unsigned Align = 0;
4338 switch (CE->getValue()) {
4339 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004340 return Error(E,
4341 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4342 case 16: Align = 2; break;
4343 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004344 case 64: Align = 8; break;
4345 case 128: Align = 16; break;
4346 case 256: Align = 32; break;
4347 }
4348
4349 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004350 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004351 return Error(Parser.getTok().getLoc(), "']' expected");
4352 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004353 Parser.Lex(); // Eat right bracket token.
4354
4355 // Don't worry about range checking the value here. That's handled by
4356 // the is*() predicates.
4357 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4358 ARM_AM::no_shift, 0, Align,
4359 false, S, E));
4360
4361 // If there's a pre-indexing writeback marker, '!', just add it as a token
4362 // operand.
4363 if (Parser.getTok().is(AsmToken::Exclaim)) {
4364 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4365 Parser.Lex(); // Eat the '!'.
4366 }
4367
4368 return false;
4369 }
4370
4371 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004372 // offset. Be friendly and also accept a plain integer (without a leading
4373 // hash) for gas compatibility.
4374 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004375 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004376 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004377 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004378 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004379 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004380
Owen Anderson967674d2011-08-29 19:36:44 +00004381 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004382 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004383 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004384 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004385
4386 // The expression has to be a constant. Memory references with relocations
4387 // don't come through here, as they use the <label> forms of the relevant
4388 // instructions.
4389 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4390 if (!CE)
4391 return Error (E, "constant expression expected");
4392
Owen Anderson967674d2011-08-29 19:36:44 +00004393 // If the constant was #-0, represent it as INT32_MIN.
4394 int32_t Val = CE->getValue();
4395 if (isNegative && Val == 0)
4396 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4397
Jim Grosbachd3595712011-08-03 23:50:40 +00004398 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004399 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004400 return Error(Parser.getTok().getLoc(), "']' expected");
4401 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004402 Parser.Lex(); // Eat right bracket token.
4403
4404 // Don't worry about range checking the value here. That's handled by
4405 // the is*() predicates.
4406 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004407 ARM_AM::no_shift, 0, 0,
4408 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004409
4410 // If there's a pre-indexing writeback marker, '!', just add it as a token
4411 // operand.
4412 if (Parser.getTok().is(AsmToken::Exclaim)) {
4413 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4414 Parser.Lex(); // Eat the '!'.
4415 }
4416
4417 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004418 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004419
4420 // The register offset is optionally preceded by a '+' or '-'
4421 bool isNegative = false;
4422 if (Parser.getTok().is(AsmToken::Minus)) {
4423 isNegative = true;
4424 Parser.Lex(); // Eat the '-'.
4425 } else if (Parser.getTok().is(AsmToken::Plus)) {
4426 // Nothing to do.
4427 Parser.Lex(); // Eat the '+'.
4428 }
4429
4430 E = Parser.getTok().getLoc();
4431 int OffsetRegNum = tryParseRegister();
4432 if (OffsetRegNum == -1)
4433 return Error(E, "register expected");
4434
4435 // If there's a shift operator, handle it.
4436 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004437 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004438 if (Parser.getTok().is(AsmToken::Comma)) {
4439 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004440 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004441 return true;
4442 }
4443
4444 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004445 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004446 return Error(Parser.getTok().getLoc(), "']' expected");
4447 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004448 Parser.Lex(); // Eat right bracket token.
4449
4450 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004451 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004452 S, E));
4453
Jim Grosbachc320c852011-08-05 21:28:30 +00004454 // If there's a pre-indexing writeback marker, '!', just add it as a token
4455 // operand.
4456 if (Parser.getTok().is(AsmToken::Exclaim)) {
4457 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4458 Parser.Lex(); // Eat the '!'.
4459 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004460
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004461 return false;
4462}
4463
Jim Grosbachd3595712011-08-03 23:50:40 +00004464/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004465/// ( lsl | lsr | asr | ror ) , # shift_amount
4466/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004467/// return true if it parses a shift otherwise it returns false.
4468bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4469 unsigned &Amount) {
4470 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004471 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004472 if (Tok.isNot(AsmToken::Identifier))
4473 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004474 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004475 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4476 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004477 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004478 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004479 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004480 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004481 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004482 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004483 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004484 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004485 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004486 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004487 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004488 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004489
Jim Grosbachd3595712011-08-03 23:50:40 +00004490 // rrx stands alone.
4491 Amount = 0;
4492 if (St != ARM_AM::rrx) {
4493 Loc = Parser.getTok().getLoc();
4494 // A '#' and a shift amount.
4495 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004496 if (HashTok.isNot(AsmToken::Hash) &&
4497 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004498 return Error(HashTok.getLoc(), "'#' expected");
4499 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004500
Jim Grosbachd3595712011-08-03 23:50:40 +00004501 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004502 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004503 return true;
4504 // Range check the immediate.
4505 // lsl, ror: 0 <= imm <= 31
4506 // lsr, asr: 0 <= imm <= 32
4507 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4508 if (!CE)
4509 return Error(Loc, "shift amount must be an immediate");
4510 int64_t Imm = CE->getValue();
4511 if (Imm < 0 ||
4512 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4513 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4514 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004515 // If <ShiftTy> #0, turn it into a no_shift.
4516 if (Imm == 0)
4517 St = ARM_AM::lsl;
4518 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4519 if (Imm == 32)
4520 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004521 Amount = Imm;
4522 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004523
4524 return false;
4525}
4526
Jim Grosbache7fbce72011-10-03 23:38:36 +00004527/// parseFPImm - A floating point immediate expression operand.
4528ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4529parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004530 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004531 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004532 // integer only.
4533 //
4534 // This routine still creates a generic Immediate operand, containing
4535 // a bitcast of the 64-bit floating point value. The various operands
4536 // that accept floats can check whether the value is valid for them
4537 // via the standard is*() predicates.
4538
Jim Grosbache7fbce72011-10-03 23:38:36 +00004539 SMLoc S = Parser.getTok().getLoc();
4540
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004541 if (Parser.getTok().isNot(AsmToken::Hash) &&
4542 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004543 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004544
4545 // Disambiguate the VMOV forms that can accept an FP immediate.
4546 // vmov.f32 <sreg>, #imm
4547 // vmov.f64 <dreg>, #imm
4548 // vmov.f32 <dreg>, #imm @ vector f32x2
4549 // vmov.f32 <qreg>, #imm @ vector f32x4
4550 //
4551 // There are also the NEON VMOV instructions which expect an
4552 // integer constant. Make sure we don't try to parse an FPImm
4553 // for these:
4554 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4555 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4556 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4557 TyOp->getToken() != ".f64"))
4558 return MatchOperand_NoMatch;
4559
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004560 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004561
4562 // Handle negation, as that still comes through as a separate token.
4563 bool isNegative = false;
4564 if (Parser.getTok().is(AsmToken::Minus)) {
4565 isNegative = true;
4566 Parser.Lex();
4567 }
4568 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004569 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004570 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004571 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004572 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4573 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004574 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004575 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004576 Operands.push_back(ARMOperand::CreateImm(
4577 MCConstantExpr::Create(IntVal, getContext()),
4578 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004579 return MatchOperand_Success;
4580 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004581 // Also handle plain integers. Instructions which allow floating point
4582 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004583 if (Tok.is(AsmToken::Integer)) {
4584 int64_t Val = Tok.getIntVal();
4585 Parser.Lex(); // Eat the token.
4586 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004587 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004588 return MatchOperand_ParseFail;
4589 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004590 double RealVal = ARM_AM::getFPImmFloat(Val);
4591 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4592 Operands.push_back(ARMOperand::CreateImm(
4593 MCConstantExpr::Create(Val, getContext()), S,
4594 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004595 return MatchOperand_Success;
4596 }
4597
Jim Grosbach235c8d22012-01-19 02:47:30 +00004598 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004599 return MatchOperand_ParseFail;
4600}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004601
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004602/// Parse a arm instruction operand. For now this parses the operand regardless
4603/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004604bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004605 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004606 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004607
4608 // Check if the current operand has a custom associated parser, if so, try to
4609 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004610 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4611 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004612 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004613 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4614 // there was a match, but an error occurred, in which case, just return that
4615 // the operand parsing failed.
4616 if (ResTy == MatchOperand_ParseFail)
4617 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004618
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004619 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004620 default:
4621 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004622 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004623 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004624 // If we've seen a branch mnemonic, the next operand must be a label. This
4625 // is true even if the label is a register name. So "br r1" means branch to
4626 // label "r1".
4627 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4628 if (!ExpectLabel) {
4629 if (!tryParseRegisterWithWriteBack(Operands))
4630 return false;
4631 int Res = tryParseShiftRegister(Operands);
4632 if (Res == 0) // success
4633 return false;
4634 else if (Res == -1) // irrecoverable error
4635 return true;
4636 // If this is VMRS, check for the apsr_nzcv operand.
4637 if (Mnemonic == "vmrs" &&
4638 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4639 S = Parser.getTok().getLoc();
4640 Parser.Lex();
4641 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4642 return false;
4643 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004644 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004645
4646 // Fall though for the Identifier case that is not a register or a
4647 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004648 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004649 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004650 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004651 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004652 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004653 // This was not a register so parse other operands that start with an
4654 // identifier (like labels) as expressions and create them as immediates.
4655 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004656 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004657 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004658 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004659 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004660 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4661 return false;
4662 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004663 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004664 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004665 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004666 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004667 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004668 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004669 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004670 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004671 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004672
4673 if (Parser.getTok().isNot(AsmToken::Colon)) {
4674 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4675 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004676 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004677 return true;
4678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4679 if (CE) {
4680 int32_t Val = CE->getValue();
4681 if (isNegative && Val == 0)
4682 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4683 }
4684 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4685 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004686
4687 // There can be a trailing '!' on operands that we want as a separate
4688 // '!' Token operand. Handle that here. For example, the compatibilty
4689 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4690 if (Parser.getTok().is(AsmToken::Exclaim)) {
4691 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4692 Parser.getTok().getLoc()));
4693 Parser.Lex(); // Eat exclaim token
4694 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004695 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004696 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004697 // w/ a ':' after the '#', it's just like a plain ':'.
4698 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004699 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004700 case AsmToken::Colon: {
4701 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004702 // FIXME: Check it's an expression prefix,
4703 // e.g. (FOO - :lower16:BAR) isn't legal.
4704 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004705 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004706 return true;
4707
Evan Cheng965b3c72011-01-13 07:58:56 +00004708 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004709 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004710 return true;
4711
Evan Cheng965b3c72011-01-13 07:58:56 +00004712 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004713 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004714 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004715 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004716 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004717 }
David Peixottoe407d092013-12-19 18:12:36 +00004718 case AsmToken::Equal: {
4719 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4720 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4721
4722 const MCSection *Section =
4723 getParser().getStreamer().getCurrentSection().first;
4724 assert(Section);
4725 Parser.Lex(); // Eat '='
4726 const MCExpr *SubExprVal;
4727 if (getParser().parseExpression(SubExprVal))
4728 return true;
4729 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4730
4731 const MCExpr *CPLoc =
4732 getOrCreateConstantPool(Section).addEntry(SubExprVal, getContext());
4733 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4734 return false;
4735 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004736 }
4737}
4738
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004739// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004740// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004741bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004742 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004743
4744 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004745 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004746 Parser.Lex(); // Eat ':'
4747
4748 if (getLexer().isNot(AsmToken::Identifier)) {
4749 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4750 return true;
4751 }
4752
4753 StringRef IDVal = Parser.getTok().getIdentifier();
4754 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004755 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004756 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004757 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004758 } else {
4759 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4760 return true;
4761 }
4762 Parser.Lex();
4763
4764 if (getLexer().isNot(AsmToken::Colon)) {
4765 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4766 return true;
4767 }
4768 Parser.Lex(); // Eat the last ':'
4769 return false;
4770}
4771
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004772/// \brief Given a mnemonic, split out possible predication code and carry
4773/// setting letters to form a canonical mnemonic and flags.
4774//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004775// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004776// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004777StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004778 unsigned &PredicationCode,
4779 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004780 unsigned &ProcessorIMod,
4781 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004782 PredicationCode = ARMCC::AL;
4783 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004784 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004785
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004786 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004787 //
4788 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004789 if ((Mnemonic == "movs" && isThumb()) ||
4790 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4791 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4792 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4793 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004794 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004795 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4796 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004797 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004798 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004799 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4800 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4801 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004802 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004803
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004804 // First, split out any predication code. Ignore mnemonics we know aren't
4805 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004806 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004807 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004808 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004809 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004810 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4811 .Case("eq", ARMCC::EQ)
4812 .Case("ne", ARMCC::NE)
4813 .Case("hs", ARMCC::HS)
4814 .Case("cs", ARMCC::HS)
4815 .Case("lo", ARMCC::LO)
4816 .Case("cc", ARMCC::LO)
4817 .Case("mi", ARMCC::MI)
4818 .Case("pl", ARMCC::PL)
4819 .Case("vs", ARMCC::VS)
4820 .Case("vc", ARMCC::VC)
4821 .Case("hi", ARMCC::HI)
4822 .Case("ls", ARMCC::LS)
4823 .Case("ge", ARMCC::GE)
4824 .Case("lt", ARMCC::LT)
4825 .Case("gt", ARMCC::GT)
4826 .Case("le", ARMCC::LE)
4827 .Case("al", ARMCC::AL)
4828 .Default(~0U);
4829 if (CC != ~0U) {
4830 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4831 PredicationCode = CC;
4832 }
Bill Wendling193961b2010-10-29 23:50:21 +00004833 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004834
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004835 // Next, determine if we have a carry setting bit. We explicitly ignore all
4836 // the instructions we know end in 's'.
4837 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004838 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004839 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4840 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4841 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004842 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004843 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004844 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004845 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004846 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004847 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004848 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4849 CarrySetting = true;
4850 }
4851
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004852 // The "cps" instruction can have a interrupt mode operand which is glued into
4853 // the mnemonic. Check if this is the case, split it and parse the imod op
4854 if (Mnemonic.startswith("cps")) {
4855 // Split out any imod code.
4856 unsigned IMod =
4857 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4858 .Case("ie", ARM_PROC::IE)
4859 .Case("id", ARM_PROC::ID)
4860 .Default(~0U);
4861 if (IMod != ~0U) {
4862 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4863 ProcessorIMod = IMod;
4864 }
4865 }
4866
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004867 // The "it" instruction has the condition mask on the end of the mnemonic.
4868 if (Mnemonic.startswith("it")) {
4869 ITMask = Mnemonic.slice(2, Mnemonic.size());
4870 Mnemonic = Mnemonic.slice(0, 2);
4871 }
4872
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004873 return Mnemonic;
4874}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004875
4876/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4877/// inclusion of carry set or predication code operands.
4878//
4879// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004880void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00004881getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4882 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004883 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4884 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004885 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004886 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004887 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004888 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004889 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004890 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004891 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004892 Mnemonic == "mla" || Mnemonic == "smlal" ||
4893 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004894 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004895 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004896 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004897
Tim Northover2c45a382013-06-26 16:52:40 +00004898 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4899 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00004900 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004901 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4902 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004903 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4904 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00004905 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4906 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4907 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00004908 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004909 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004910 } else if (!isThumb()) {
4911 // Some instructions are only predicable in Thumb mode
4912 CanAcceptPredicationCode
4913 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4914 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4915 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4916 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4917 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4918 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4919 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4920 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00004921 if (hasV6MOps())
4922 CanAcceptPredicationCode = Mnemonic != "movs";
4923 else
4924 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004925 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004926 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004927}
4928
Jim Grosbach7283da92011-08-16 21:12:37 +00004929bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4930 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004931 // FIXME: This is all horribly hacky. We really need a better way to deal
4932 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004933
4934 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4935 // another does not. Specifically, the MOVW instruction does not. So we
4936 // special case it here and remove the defaulted (non-setting) cc_out
4937 // operand if that's the instruction we're trying to match.
4938 //
4939 // We do this as post-processing of the explicit operands rather than just
4940 // conditionally adding the cc_out in the first place because we need
4941 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004942 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004943 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4944 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4945 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4946 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004947
4948 // Register-register 'add' for thumb does not have a cc_out operand
4949 // when there are only two register operands.
4950 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4951 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4952 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4953 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4954 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004955 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004956 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4957 // have to check the immediate range here since Thumb2 has a variant
4958 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004959 if (((isThumb() && Mnemonic == "add") ||
4960 (isThumbTwo() && Mnemonic == "sub")) &&
4961 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004962 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4963 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4964 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004965 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004966 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004967 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004968 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004969 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4970 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004971 // selecting via the generic "add" mnemonic, so to know that we
4972 // should remove the cc_out operand, we have to explicitly check that
4973 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004974 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4975 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004976 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4977 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4978 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4979 // Nest conditions rather than one big 'if' statement for readability.
4980 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004981 // If both registers are low, we're in an IT block, and the immediate is
4982 // in range, we should use encoding T1 instead, which has a cc_out.
4983 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004984 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004985 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4986 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4987 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004988 // Check against T3. If the second register is the PC, this is an
4989 // alternate form of ADR, which uses encoding T4, so check for that too.
4990 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4991 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4992 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004993
4994 // Otherwise, we use encoding T4, which does not have a cc_out
4995 // operand.
4996 return true;
4997 }
4998
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004999 // The thumb2 multiply instruction doesn't have a CCOut register, so
5000 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5001 // use the 16-bit encoding or not.
5002 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5003 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5004 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5005 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5006 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5007 // If the registers aren't low regs, the destination reg isn't the
5008 // same as one of the source regs, or the cc_out operand is zero
5009 // outside of an IT block, we have to use the 32-bit encoding, so
5010 // remove the cc_out operand.
5011 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5012 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00005013 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005014 !inITBlock() ||
5015 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5016 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5017 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5018 static_cast<ARMOperand*>(Operands[4])->getReg())))
5019 return true;
5020
Jim Grosbachefa7e952011-11-15 19:55:16 +00005021 // Also check the 'mul' syntax variant that doesn't specify an explicit
5022 // destination register.
5023 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5024 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5025 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5026 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5027 // If the registers aren't low regs or the cc_out operand is zero
5028 // outside of an IT block, we have to use the 32-bit encoding, so
5029 // remove the cc_out operand.
5030 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5031 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5032 !inITBlock()))
5033 return true;
5034
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005035
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005036
Jim Grosbach4b701af2011-08-24 21:42:27 +00005037 // Register-register 'add/sub' for thumb does not have a cc_out operand
5038 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5039 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5040 // right, this will result in better diagnostics (which operand is off)
5041 // anyway.
5042 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5043 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005044 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5045 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005046 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5047 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5048 (Operands.size() == 6 &&
5049 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005050 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005051
Jim Grosbach7283da92011-08-16 21:12:37 +00005052 return false;
5053}
5054
Joey Goulye8602552013-07-19 16:34:16 +00005055bool ARMAsmParser::shouldOmitPredicateOperand(
5056 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5057 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5058 unsigned RegIdx = 3;
5059 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5060 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5061 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5062 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5063 RegIdx = 4;
5064
5065 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5066 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5067 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5068 ARMMCRegisterClasses[ARM::QPRRegClassID]
5069 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5070 return true;
5071 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005072 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005073}
5074
Jim Grosbach12952fe2011-11-11 23:08:10 +00005075static bool isDataTypeToken(StringRef Tok) {
5076 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5077 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5078 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5079 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5080 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5081 Tok == ".f" || Tok == ".d";
5082}
5083
5084// FIXME: This bit should probably be handled via an explicit match class
5085// in the .td files that matches the suffix instead of having it be
5086// a literal string token the way it is now.
5087static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5088 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5089}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005090static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5091 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005092/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005093bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5094 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005095 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005096 // Apply mnemonic aliases before doing anything else, as the destination
5097 // mnemnonic may include suffices and we want to handle them normally.
5098 // The generic tblgen'erated code does this later, at the start of
5099 // MatchInstructionImpl(), but that's too late for aliases that include
5100 // any sort of suffix.
5101 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005102 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5103 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005104
Jim Grosbachab5830e2011-12-14 02:16:11 +00005105 // First check for the ARM-specific .req directive.
5106 if (Parser.getTok().is(AsmToken::Identifier) &&
5107 Parser.getTok().getIdentifier() == ".req") {
5108 parseDirectiveReq(Name, NameLoc);
5109 // We always return 'error' for this, as we're done with this
5110 // statement and don't need to match the 'instruction."
5111 return true;
5112 }
5113
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005114 // Create the leading tokens for the mnemonic, split by '.' characters.
5115 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005116 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005117
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005118 // Split out the predication code and carry setting flag from the mnemonic.
5119 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005120 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005121 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005122 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005123 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005124 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005125
Jim Grosbach1c171b12011-08-25 17:23:55 +00005126 // In Thumb1, only the branch (B) instruction can be predicated.
5127 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005128 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005129 return Error(NameLoc, "conditional execution not supported in Thumb1");
5130 }
5131
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005132 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5133
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005134 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5135 // is the mask as it will be for the IT encoding if the conditional
5136 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5137 // where the conditional bit0 is zero, the instruction post-processing
5138 // will adjust the mask accordingly.
5139 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005140 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5141 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005142 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005143 return Error(Loc, "too many conditions on IT instruction");
5144 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005145 unsigned Mask = 8;
5146 for (unsigned i = ITMask.size(); i != 0; --i) {
5147 char pos = ITMask[i - 1];
5148 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005149 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005150 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005151 }
5152 Mask >>= 1;
5153 if (ITMask[i - 1] == 't')
5154 Mask |= 8;
5155 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005156 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005157 }
5158
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005159 // FIXME: This is all a pretty gross hack. We should automatically handle
5160 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005161
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005162 // Next, add the CCOut and ConditionCode operands, if needed.
5163 //
5164 // For mnemonics which can ever incorporate a carry setting bit or predication
5165 // code, our matching model involves us always generating CCOut and
5166 // ConditionCode operands to match the mnemonic "as written" and then we let
5167 // the matcher deal with finding the right instruction or generating an
5168 // appropriate error.
5169 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005170 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005171
Jim Grosbach03a8a162011-07-14 22:04:21 +00005172 // If we had a carry-set on an instruction that can't do that, issue an
5173 // error.
5174 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005175 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005176 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005177 "' can not set flags, but 's' suffix specified");
5178 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005179 // If we had a predication code on an instruction that can't do that, issue an
5180 // error.
5181 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005182 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005183 return Error(NameLoc, "instruction '" + Mnemonic +
5184 "' is not predicable, but condition code specified");
5185 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005186
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005187 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005188 if (CanAcceptCarrySet) {
5189 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005190 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005191 Loc));
5192 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005193
5194 // Add the predication code operand, if necessary.
5195 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005196 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5197 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005198 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005199 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005200 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005201
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005202 // Add the processor imod operand, if necessary.
5203 if (ProcessorIMod) {
5204 Operands.push_back(ARMOperand::CreateImm(
5205 MCConstantExpr::Create(ProcessorIMod, getContext()),
5206 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005207 }
5208
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005209 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005210 while (Next != StringRef::npos) {
5211 Start = Next;
5212 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005213 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005214
Jim Grosbach12952fe2011-11-11 23:08:10 +00005215 // Some NEON instructions have an optional datatype suffix that is
5216 // completely ignored. Check for that.
5217 if (isDataTypeToken(ExtraToken) &&
5218 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5219 continue;
5220
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005221 // For for ARM mode generate an error if the .n qualifier is used.
5222 if (ExtraToken == ".n" && !isThumb()) {
5223 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5224 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5225 "arm mode");
5226 }
5227
5228 // The .n qualifier is always discarded as that is what the tables
5229 // and matcher expect. In ARM mode the .w qualifier has no effect,
5230 // so discard it to avoid errors that can be caused by the matcher.
5231 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005232 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5233 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5234 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005235 }
5236
5237 // Read the remaining operands.
5238 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005239 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005240 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005241 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005242 return true;
5243 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005244
5245 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005246 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005247
5248 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005249 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005250 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005251 return true;
5252 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005253 }
5254 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005255
Chris Lattnera2a9d162010-09-11 16:18:25 +00005256 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005257 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005258 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005259 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005260 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005261
Chris Lattner91689c12010-09-08 05:10:46 +00005262 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005263
Jim Grosbach7283da92011-08-16 21:12:37 +00005264 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5265 // do and don't have a cc_out optional-def operand. With some spot-checks
5266 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005267 // parse and adjust accordingly before actually matching. We shouldn't ever
5268 // try to remove a cc_out operand that was explicitly set on the the
5269 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5270 // table driven matcher doesn't fit well with the ARM instruction set.
5271 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005272 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5273 Operands.erase(Operands.begin() + 1);
5274 delete Op;
5275 }
5276
Joey Goulye8602552013-07-19 16:34:16 +00005277 // Some instructions have the same mnemonic, but don't always
5278 // have a predicate. Distinguish them here and delete the
5279 // predicate if needed.
5280 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5281 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5282 Operands.erase(Operands.begin() + 1);
5283 delete Op;
5284 }
5285
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005286 // ARM mode 'blx' need special handling, as the register operand version
5287 // is predicable, but the label operand version is not. So, we can't rely
5288 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005289 // a k_CondCode operand in the list. If we're trying to match the label
5290 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005291 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5292 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5293 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5294 Operands.erase(Operands.begin() + 1);
5295 delete Op;
5296 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005297
Weiming Zhao8f56f882012-11-16 21:55:34 +00005298 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5299 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5300 // a single GPRPair reg operand is used in the .td file to replace the two
5301 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5302 // expressed as a GPRPair, so we have to manually merge them.
5303 // FIXME: We would really like to be able to tablegen'erate this.
5304 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005305 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5306 Mnemonic == "stlexd")) {
5307 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005308 unsigned Idx = isLoad ? 2 : 3;
5309 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5310 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5311
5312 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5313 // Adjust only if Op1 and Op2 are GPRs.
5314 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5315 MRC.contains(Op2->getReg())) {
5316 unsigned Reg1 = Op1->getReg();
5317 unsigned Reg2 = Op2->getReg();
5318 unsigned Rt = MRI->getEncodingValue(Reg1);
5319 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5320
5321 // Rt2 must be Rt + 1 and Rt must be even.
5322 if (Rt + 1 != Rt2 || (Rt & 1)) {
5323 Error(Op2->getStartLoc(), isLoad ?
5324 "destination operands must be sequential" :
5325 "source operands must be sequential");
5326 return true;
5327 }
5328 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5329 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5330 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5331 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5332 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5333 delete Op1;
5334 delete Op2;
5335 }
5336 }
5337
Kevin Enderby78f95722013-07-31 21:05:30 +00005338 // FIXME: As said above, this is all a pretty gross hack. This instruction
5339 // does not fit with other "subs" and tblgen.
5340 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5341 // so the Mnemonic is the original name "subs" and delete the predicate
5342 // operand so it will match the table entry.
5343 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5344 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5345 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5346 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5347 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5348 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5349 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5350 Operands.erase(Operands.begin());
5351 delete Op0;
5352 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5353
5354 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5355 Operands.erase(Operands.begin() + 1);
5356 delete Op1;
5357 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005358 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005359}
5360
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005361// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005362
5363// return 'true' if register list contains non-low GPR registers,
5364// 'false' otherwise. If Reg is in the register list or is HiReg, set
5365// 'containsReg' to true.
5366static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5367 unsigned HiReg, bool &containsReg) {
5368 containsReg = false;
5369 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5370 unsigned OpReg = Inst.getOperand(i).getReg();
5371 if (OpReg == Reg)
5372 containsReg = true;
5373 // Anything other than a low register isn't legal here.
5374 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5375 return true;
5376 }
5377 return false;
5378}
5379
Jim Grosbacha31f2232011-09-07 18:05:34 +00005380// Check if the specified regisgter is in the register list of the inst,
5381// starting at the indicated operand number.
5382static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5383 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5384 unsigned OpReg = Inst.getOperand(i).getReg();
5385 if (OpReg == Reg)
5386 return true;
5387 }
5388 return false;
5389}
5390
Richard Barton8d519fe2013-09-05 14:14:19 +00005391// Return true if instruction has the interesting property of being
5392// allowed in IT blocks, but not being predicable.
5393static bool instIsBreakpoint(const MCInst &Inst) {
5394 return Inst.getOpcode() == ARM::tBKPT ||
5395 Inst.getOpcode() == ARM::BKPT ||
5396 Inst.getOpcode() == ARM::tHLT ||
5397 Inst.getOpcode() == ARM::HLT;
5398
5399}
5400
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005401// FIXME: We would really like to be able to tablegen'erate this.
5402bool ARMAsmParser::
5403validateInstruction(MCInst &Inst,
5404 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005405 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005406 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005407
Jim Grosbached16ec42011-08-29 22:24:09 +00005408 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005409 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005410 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005411 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005412 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005413 if (ITState.FirstCond)
5414 ITState.FirstCond = false;
5415 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005416 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005417 // The instruction must be predicable.
5418 if (!MCID.isPredicable())
5419 return Error(Loc, "instructions in IT block must be predicable");
5420 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005421 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005422 ARMCC::getOppositeCondition(ITState.Cond);
5423 if (Cond != ITCond) {
5424 // Find the condition code Operand to get its SMLoc information.
5425 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005426 for (unsigned I = 1; I < Operands.size(); ++I)
5427 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5428 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005429 return Error(CondLoc, "incorrect condition in IT block; got '" +
5430 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5431 "', but expected '" +
5432 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5433 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005434 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005435 } else if (isThumbTwo() && MCID.isPredicable() &&
5436 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005437 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5438 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005439 return Error(Loc, "predicated instructions must be in IT block");
5440
Tilmann Scheller255722b2013-09-30 16:11:48 +00005441 const unsigned Opcode = Inst.getOpcode();
5442 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005443 case ARM::LDRD:
5444 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005445 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005446 const unsigned RtReg = Inst.getOperand(0).getReg();
5447
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005448 // Rt can't be R14.
5449 if (RtReg == ARM::LR)
5450 return Error(Operands[3]->getStartLoc(),
5451 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005452
5453 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005454 // Rt must be even-numbered.
5455 if ((Rt & 1) == 1)
5456 return Error(Operands[3]->getStartLoc(),
5457 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005458
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005459 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005460 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005461 if (Rt2 != Rt + 1)
5462 return Error(Operands[3]->getStartLoc(),
5463 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005464
5465 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5466 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5467 // For addressing modes with writeback, the base register needs to be
5468 // different from the destination registers.
5469 if (Rn == Rt || Rn == Rt2)
5470 return Error(Operands[3]->getStartLoc(),
5471 "base register needs to be different from destination "
5472 "registers");
5473 }
5474
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005475 return false;
5476 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005477 case ARM::t2LDRDi8:
5478 case ARM::t2LDRD_PRE:
5479 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005480 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005481 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5482 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5483 if (Rt2 == Rt)
5484 return Error(Operands[3]->getStartLoc(),
5485 "destination operands can't be identical");
5486 return false;
5487 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005488 case ARM::STRD: {
5489 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005490 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5491 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005492 if (Rt2 != Rt + 1)
5493 return Error(Operands[3]->getStartLoc(),
5494 "source operands must be sequential");
5495 return false;
5496 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005497 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005498 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005499 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005500 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5501 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005502 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005503 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005504 "source operands must be sequential");
5505 return false;
5506 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005507 case ARM::SBFX:
5508 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005509 // Width must be in range [1, 32-lsb].
5510 unsigned LSB = Inst.getOperand(2).getImm();
5511 unsigned Widthm1 = Inst.getOperand(3).getImm();
5512 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005513 return Error(Operands[5]->getStartLoc(),
5514 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005515 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005516 }
Tim Northover08a86602013-10-22 19:00:39 +00005517 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005518 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005519 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005520 // most cases that are normally illegal for a Thumb1 LDM instruction.
5521 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005522 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005523 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005524 // in the register list.
5525 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005526 bool HasWritebackToken =
Jim Grosbach139acd22011-08-22 23:01:07 +00005527 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5528 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005529 bool ListContainsBase;
5530 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5531 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005532 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005533 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005534 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005535 return Error(Operands[2]->getStartLoc(),
5536 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005537 // If we should not have writeback, there must not be a '!'. This is
5538 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005539 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005540 return Error(Operands[3]->getStartLoc(),
5541 "writeback operator '!' not allowed when base register "
5542 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005543
5544 break;
5545 }
Tim Northover08a86602013-10-22 19:00:39 +00005546 case ARM::LDMIA_UPD:
5547 case ARM::LDMDB_UPD:
5548 case ARM::LDMIB_UPD:
5549 case ARM::LDMDA_UPD:
5550 // ARM variants loading and updating the same register are only officially
5551 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5552 if (!hasV7Ops())
5553 break;
5554 // Fallthrough
5555 case ARM::t2LDMIA_UPD:
5556 case ARM::t2LDMDB_UPD:
5557 case ARM::t2STMIA_UPD:
5558 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005559 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
Tim Northover741e6ef2013-10-24 09:37:18 +00005560 return Error(Operands.back()->getStartLoc(),
5561 "writeback register not allowed in register list");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005562 break;
5563 }
Tim Northover8eaf1542013-11-12 21:32:41 +00005564 case ARM::sysLDMIA_UPD:
5565 case ARM::sysLDMDA_UPD:
5566 case ARM::sysLDMDB_UPD:
5567 case ARM::sysLDMIB_UPD:
5568 if (!listContainsReg(Inst, 3, ARM::PC))
5569 return Error(Operands[4]->getStartLoc(),
5570 "writeback register only allowed on system LDM "
5571 "if PC in register-list");
5572 break;
5573 case ARM::sysSTMIA_UPD:
5574 case ARM::sysSTMDA_UPD:
5575 case ARM::sysSTMDB_UPD:
5576 case ARM::sysSTMIB_UPD:
5577 return Error(Operands[2]->getStartLoc(),
5578 "system STM cannot have writeback register");
5579 break;
Chad Rosier8513ffb2012-08-30 23:20:38 +00005580 case ARM::tMUL: {
5581 // The second source operand must be the same register as the destination
5582 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005583 //
5584 // In this case, we must directly check the parsed operands because the
5585 // cvtThumbMultiply() function is written in such a way that it guarantees
5586 // this first statement is always true for the new Inst. Essentially, the
5587 // destination is unconditionally copied into the second source operand
5588 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005589 if (Operands.size() == 6 &&
5590 (((ARMOperand*)Operands[3])->getReg() !=
5591 ((ARMOperand*)Operands[5])->getReg()) &&
5592 (((ARMOperand*)Operands[3])->getReg() !=
5593 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005594 return Error(Operands[3]->getStartLoc(),
5595 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005596 }
5597 break;
5598 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005599 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5600 // so only issue a diagnostic for thumb1. The instructions will be
5601 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005602 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005603 bool ListContainsBase;
5604 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005605 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005606 return Error(Operands[2]->getStartLoc(),
5607 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005608 break;
5609 }
5610 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005611 bool ListContainsBase;
5612 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005613 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005614 return Error(Operands[2]->getStartLoc(),
5615 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005616 break;
5617 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005618 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005619 bool ListContainsBase, InvalidLowList;
5620 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5621 0, ListContainsBase);
5622 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005623 return Error(Operands[4]->getStartLoc(),
5624 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005625
5626 // This would be converted to a 32-bit stm, but that's not valid if the
5627 // writeback register is in the list.
5628 if (InvalidLowList && ListContainsBase)
5629 return Error(Operands[4]->getStartLoc(),
5630 "writeback operator '!' not allowed when base register "
5631 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005632 break;
5633 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005634 case ARM::tADDrSP: {
5635 // If the non-SP source operand and the destination operand are not the
5636 // same, we need thumb2 (for the wide encoding), or we have an error.
5637 if (!isThumbTwo() &&
5638 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5639 return Error(Operands[4]->getStartLoc(),
5640 "source register must be the same as destination");
5641 }
5642 break;
5643 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005644 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005645 case ARM::tB:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005646 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5647 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005648 break;
5649 case ARM::t2B: {
5650 int op = (Operands[2]->isImm()) ? 2 : 3;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005651 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5652 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005653 break;
5654 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005655 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005656 case ARM::tBcc:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005657 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5658 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005659 break;
5660 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005661 int Op = (Operands[2]->isImm()) ? 2 : 3;
5662 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5663 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005664 break;
5665 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005666 }
5667
5668 return false;
5669}
5670
Jim Grosbach1a747242012-01-23 23:45:44 +00005671static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005672 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005673 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005674 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005675 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5676 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5677 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5678 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5679 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5680 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5681 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5682 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5683 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005684
5685 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005686 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5687 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5688 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5689 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5690 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005691
Jim Grosbach1e946a42012-01-24 00:43:12 +00005692 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5693 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5694 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5695 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5696 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005697
Jim Grosbach1e946a42012-01-24 00:43:12 +00005698 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5699 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5700 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5701 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5702 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005703
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005704 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005705 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5706 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5707 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5708 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5709 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5710 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5711 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5712 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5713 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5714 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5715 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5716 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5717 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5718 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5719 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005720
Jim Grosbach1a747242012-01-23 23:45:44 +00005721 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005722 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5723 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5724 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5725 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5726 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5727 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5728 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5729 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5730 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5731 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5732 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5733 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5734 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5735 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5736 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5737 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5738 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5739 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005740
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005741 // VST4LN
5742 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5743 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5744 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5745 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5746 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5747 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5748 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5749 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5750 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5751 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5752 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5753 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5754 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5755 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5756 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5757
Jim Grosbachda70eac2012-01-24 00:58:13 +00005758 // VST4
5759 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5760 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5761 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5762 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5763 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5764 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5765 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5766 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5767 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5768 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5769 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5770 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5771 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5772 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5773 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5774 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5775 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5776 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005777 }
5778}
5779
Jim Grosbach1a747242012-01-23 23:45:44 +00005780static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005781 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005782 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005783 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005784 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5785 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5786 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5787 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5788 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5789 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5790 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5791 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5792 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005793
5794 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005795 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5796 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5797 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5798 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5799 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5800 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5801 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5802 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5803 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5804 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5805 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5806 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5807 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5808 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5809 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005810
Jim Grosbachb78403c2012-01-24 23:47:04 +00005811 // VLD3DUP
5812 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5813 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5814 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5815 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5816 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5817 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5818 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5819 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5820 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5821 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5822 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5823 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5824 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5825 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5826 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5827 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5828 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5829 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5830
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005831 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005832 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5833 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5834 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5835 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5836 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5837 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5838 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5839 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5840 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5841 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5842 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5843 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5844 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5845 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5846 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005847
5848 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005849 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5850 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5851 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5852 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5853 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5854 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5855 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5856 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5857 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5858 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5859 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5860 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5861 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5862 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5863 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5864 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5865 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5866 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005867
Jim Grosbach14952a02012-01-24 18:37:25 +00005868 // VLD4LN
5869 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5870 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5871 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5872 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5873 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5874 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5875 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5876 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5877 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5878 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5879 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5880 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5881 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5882 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5883 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5884
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005885 // VLD4DUP
5886 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5887 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5888 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5889 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5890 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5891 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5892 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5893 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5894 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5895 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5896 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5897 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5898 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5899 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5900 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5901 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5902 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5903 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5904
Jim Grosbached561fc2012-01-24 00:43:17 +00005905 // VLD4
5906 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5907 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5908 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5909 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5910 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5911 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5912 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5913 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5914 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5915 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5916 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5917 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5918 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5919 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5920 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5921 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5922 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5923 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005924 }
5925}
5926
Jim Grosbachafad0532011-11-10 23:42:14 +00005927bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005928processInstruction(MCInst &Inst,
5929 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5930 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005931 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5932 case ARM::ADDri: {
5933 if (Inst.getOperand(1).getReg() != ARM::PC ||
5934 Inst.getOperand(5).getReg() != 0)
5935 return false;
5936 MCInst TmpInst;
5937 TmpInst.setOpcode(ARM::ADR);
5938 TmpInst.addOperand(Inst.getOperand(0));
5939 TmpInst.addOperand(Inst.getOperand(2));
5940 TmpInst.addOperand(Inst.getOperand(3));
5941 TmpInst.addOperand(Inst.getOperand(4));
5942 Inst = TmpInst;
5943 return true;
5944 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005945 // Aliases for alternate PC+imm syntax of LDR instructions.
5946 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005947 // Select the narrow version if the immediate will fit.
5948 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005949 Inst.getOperand(1).getImm() <= 0xff &&
5950 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5951 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005952 Inst.setOpcode(ARM::tLDRpci);
5953 else
5954 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005955 return true;
5956 case ARM::t2LDRBpcrel:
5957 Inst.setOpcode(ARM::t2LDRBpci);
5958 return true;
5959 case ARM::t2LDRHpcrel:
5960 Inst.setOpcode(ARM::t2LDRHpci);
5961 return true;
5962 case ARM::t2LDRSBpcrel:
5963 Inst.setOpcode(ARM::t2LDRSBpci);
5964 return true;
5965 case ARM::t2LDRSHpcrel:
5966 Inst.setOpcode(ARM::t2LDRSHpci);
5967 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005968 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005969 case ARM::VST1LNdWB_register_Asm_8:
5970 case ARM::VST1LNdWB_register_Asm_16:
5971 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005972 MCInst TmpInst;
5973 // Shuffle the operands around so the lane index operand is in the
5974 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005975 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005976 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005977 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5978 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5979 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5980 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5981 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5982 TmpInst.addOperand(Inst.getOperand(1)); // lane
5983 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5984 TmpInst.addOperand(Inst.getOperand(6));
5985 Inst = TmpInst;
5986 return true;
5987 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005988
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005989 case ARM::VST2LNdWB_register_Asm_8:
5990 case ARM::VST2LNdWB_register_Asm_16:
5991 case ARM::VST2LNdWB_register_Asm_32:
5992 case ARM::VST2LNqWB_register_Asm_16:
5993 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005994 MCInst TmpInst;
5995 // Shuffle the operands around so the lane index operand is in the
5996 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005997 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005998 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005999 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6000 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6001 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6002 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6003 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006004 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6005 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006006 TmpInst.addOperand(Inst.getOperand(1)); // lane
6007 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6008 TmpInst.addOperand(Inst.getOperand(6));
6009 Inst = TmpInst;
6010 return true;
6011 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006012
6013 case ARM::VST3LNdWB_register_Asm_8:
6014 case ARM::VST3LNdWB_register_Asm_16:
6015 case ARM::VST3LNdWB_register_Asm_32:
6016 case ARM::VST3LNqWB_register_Asm_16:
6017 case ARM::VST3LNqWB_register_Asm_32: {
6018 MCInst TmpInst;
6019 // Shuffle the operands around so the lane index operand is in the
6020 // right place.
6021 unsigned Spacing;
6022 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6023 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6024 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6025 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6026 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6027 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6028 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6029 Spacing));
6030 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6031 Spacing * 2));
6032 TmpInst.addOperand(Inst.getOperand(1)); // lane
6033 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6034 TmpInst.addOperand(Inst.getOperand(6));
6035 Inst = TmpInst;
6036 return true;
6037 }
6038
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006039 case ARM::VST4LNdWB_register_Asm_8:
6040 case ARM::VST4LNdWB_register_Asm_16:
6041 case ARM::VST4LNdWB_register_Asm_32:
6042 case ARM::VST4LNqWB_register_Asm_16:
6043 case ARM::VST4LNqWB_register_Asm_32: {
6044 MCInst TmpInst;
6045 // Shuffle the operands around so the lane index operand is in the
6046 // right place.
6047 unsigned Spacing;
6048 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6049 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6050 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6051 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6052 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6053 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6054 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6055 Spacing));
6056 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6057 Spacing * 2));
6058 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6059 Spacing * 3));
6060 TmpInst.addOperand(Inst.getOperand(1)); // lane
6061 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6062 TmpInst.addOperand(Inst.getOperand(6));
6063 Inst = TmpInst;
6064 return true;
6065 }
6066
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006067 case ARM::VST1LNdWB_fixed_Asm_8:
6068 case ARM::VST1LNdWB_fixed_Asm_16:
6069 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006070 MCInst TmpInst;
6071 // Shuffle the operands around so the lane index operand is in the
6072 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006073 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006074 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006075 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6076 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6077 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6078 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6079 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6080 TmpInst.addOperand(Inst.getOperand(1)); // lane
6081 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6082 TmpInst.addOperand(Inst.getOperand(5));
6083 Inst = TmpInst;
6084 return true;
6085 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006086
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006087 case ARM::VST2LNdWB_fixed_Asm_8:
6088 case ARM::VST2LNdWB_fixed_Asm_16:
6089 case ARM::VST2LNdWB_fixed_Asm_32:
6090 case ARM::VST2LNqWB_fixed_Asm_16:
6091 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006092 MCInst TmpInst;
6093 // Shuffle the operands around so the lane index operand is in the
6094 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006095 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006096 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006097 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6098 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6099 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6100 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6101 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006102 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6103 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006104 TmpInst.addOperand(Inst.getOperand(1)); // lane
6105 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6106 TmpInst.addOperand(Inst.getOperand(5));
6107 Inst = TmpInst;
6108 return true;
6109 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006110
6111 case ARM::VST3LNdWB_fixed_Asm_8:
6112 case ARM::VST3LNdWB_fixed_Asm_16:
6113 case ARM::VST3LNdWB_fixed_Asm_32:
6114 case ARM::VST3LNqWB_fixed_Asm_16:
6115 case ARM::VST3LNqWB_fixed_Asm_32: {
6116 MCInst TmpInst;
6117 // Shuffle the operands around so the lane index operand is in the
6118 // right place.
6119 unsigned Spacing;
6120 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6121 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6122 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6123 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6124 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6125 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6126 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6127 Spacing));
6128 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6129 Spacing * 2));
6130 TmpInst.addOperand(Inst.getOperand(1)); // lane
6131 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6132 TmpInst.addOperand(Inst.getOperand(5));
6133 Inst = TmpInst;
6134 return true;
6135 }
6136
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006137 case ARM::VST4LNdWB_fixed_Asm_8:
6138 case ARM::VST4LNdWB_fixed_Asm_16:
6139 case ARM::VST4LNdWB_fixed_Asm_32:
6140 case ARM::VST4LNqWB_fixed_Asm_16:
6141 case ARM::VST4LNqWB_fixed_Asm_32: {
6142 MCInst TmpInst;
6143 // Shuffle the operands around so the lane index operand is in the
6144 // right place.
6145 unsigned Spacing;
6146 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6147 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6148 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6149 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6150 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6151 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6152 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6153 Spacing));
6154 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6155 Spacing * 2));
6156 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6157 Spacing * 3));
6158 TmpInst.addOperand(Inst.getOperand(1)); // lane
6159 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6160 TmpInst.addOperand(Inst.getOperand(5));
6161 Inst = TmpInst;
6162 return true;
6163 }
6164
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006165 case ARM::VST1LNdAsm_8:
6166 case ARM::VST1LNdAsm_16:
6167 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006168 MCInst TmpInst;
6169 // Shuffle the operands around so the lane index operand is in the
6170 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006171 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006172 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006173 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6174 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6175 TmpInst.addOperand(Inst.getOperand(0)); // Vd
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 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006182
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006183 case ARM::VST2LNdAsm_8:
6184 case ARM::VST2LNdAsm_16:
6185 case ARM::VST2LNdAsm_32:
6186 case ARM::VST2LNqAsm_16:
6187 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006188 MCInst TmpInst;
6189 // Shuffle the operands around so the lane index operand is in the
6190 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006191 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006192 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006193 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6194 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6195 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006196 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6197 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006198 TmpInst.addOperand(Inst.getOperand(1)); // lane
6199 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6200 TmpInst.addOperand(Inst.getOperand(5));
6201 Inst = TmpInst;
6202 return true;
6203 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006204
6205 case ARM::VST3LNdAsm_8:
6206 case ARM::VST3LNdAsm_16:
6207 case ARM::VST3LNdAsm_32:
6208 case ARM::VST3LNqAsm_16:
6209 case ARM::VST3LNqAsm_32: {
6210 MCInst TmpInst;
6211 // Shuffle the operands around so the lane index operand is in the
6212 // right place.
6213 unsigned Spacing;
6214 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6215 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6216 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6217 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6219 Spacing));
6220 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6221 Spacing * 2));
6222 TmpInst.addOperand(Inst.getOperand(1)); // lane
6223 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6224 TmpInst.addOperand(Inst.getOperand(5));
6225 Inst = TmpInst;
6226 return true;
6227 }
6228
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006229 case ARM::VST4LNdAsm_8:
6230 case ARM::VST4LNdAsm_16:
6231 case ARM::VST4LNdAsm_32:
6232 case ARM::VST4LNqAsm_16:
6233 case ARM::VST4LNqAsm_32: {
6234 MCInst TmpInst;
6235 // Shuffle the operands around so the lane index operand is in the
6236 // right place.
6237 unsigned Spacing;
6238 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6239 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6240 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6241 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6242 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6243 Spacing));
6244 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6245 Spacing * 2));
6246 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6247 Spacing * 3));
6248 TmpInst.addOperand(Inst.getOperand(1)); // lane
6249 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6250 TmpInst.addOperand(Inst.getOperand(5));
6251 Inst = TmpInst;
6252 return true;
6253 }
6254
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006255 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006256 case ARM::VLD1LNdWB_register_Asm_8:
6257 case ARM::VLD1LNdWB_register_Asm_16:
6258 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006259 MCInst TmpInst;
6260 // Shuffle the operands around so the lane index operand is in the
6261 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006262 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006263 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006264 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6265 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6266 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6267 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6268 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6269 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6270 TmpInst.addOperand(Inst.getOperand(1)); // lane
6271 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6272 TmpInst.addOperand(Inst.getOperand(6));
6273 Inst = TmpInst;
6274 return true;
6275 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006276
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006277 case ARM::VLD2LNdWB_register_Asm_8:
6278 case ARM::VLD2LNdWB_register_Asm_16:
6279 case ARM::VLD2LNdWB_register_Asm_32:
6280 case ARM::VLD2LNqWB_register_Asm_16:
6281 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006282 MCInst TmpInst;
6283 // Shuffle the operands around so the lane index operand is in the
6284 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006285 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006286 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006287 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006288 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6289 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006290 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6291 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6292 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6293 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6294 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006295 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6296 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006297 TmpInst.addOperand(Inst.getOperand(1)); // lane
6298 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6299 TmpInst.addOperand(Inst.getOperand(6));
6300 Inst = TmpInst;
6301 return true;
6302 }
6303
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006304 case ARM::VLD3LNdWB_register_Asm_8:
6305 case ARM::VLD3LNdWB_register_Asm_16:
6306 case ARM::VLD3LNdWB_register_Asm_32:
6307 case ARM::VLD3LNqWB_register_Asm_16:
6308 case ARM::VLD3LNqWB_register_Asm_32: {
6309 MCInst TmpInst;
6310 // Shuffle the operands around so the lane index operand is in the
6311 // right place.
6312 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006313 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006314 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6315 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6316 Spacing));
6317 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006318 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006319 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6320 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6321 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6322 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6323 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6324 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6325 Spacing));
6326 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006327 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006328 TmpInst.addOperand(Inst.getOperand(1)); // lane
6329 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6330 TmpInst.addOperand(Inst.getOperand(6));
6331 Inst = TmpInst;
6332 return true;
6333 }
6334
Jim Grosbach14952a02012-01-24 18:37:25 +00006335 case ARM::VLD4LNdWB_register_Asm_8:
6336 case ARM::VLD4LNdWB_register_Asm_16:
6337 case ARM::VLD4LNdWB_register_Asm_32:
6338 case ARM::VLD4LNqWB_register_Asm_16:
6339 case ARM::VLD4LNqWB_register_Asm_32: {
6340 MCInst TmpInst;
6341 // Shuffle the operands around so the lane index operand is in the
6342 // right place.
6343 unsigned Spacing;
6344 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6345 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6346 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6347 Spacing));
6348 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6349 Spacing * 2));
6350 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6351 Spacing * 3));
6352 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6353 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6354 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6355 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6356 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6357 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6358 Spacing));
6359 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6360 Spacing * 2));
6361 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6362 Spacing * 3));
6363 TmpInst.addOperand(Inst.getOperand(1)); // lane
6364 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6365 TmpInst.addOperand(Inst.getOperand(6));
6366 Inst = TmpInst;
6367 return true;
6368 }
6369
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006370 case ARM::VLD1LNdWB_fixed_Asm_8:
6371 case ARM::VLD1LNdWB_fixed_Asm_16:
6372 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006373 MCInst TmpInst;
6374 // Shuffle the operands around so the lane index operand is in the
6375 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006376 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006377 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006378 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6379 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6380 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6381 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6382 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6383 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6384 TmpInst.addOperand(Inst.getOperand(1)); // lane
6385 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6386 TmpInst.addOperand(Inst.getOperand(5));
6387 Inst = TmpInst;
6388 return true;
6389 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006390
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006391 case ARM::VLD2LNdWB_fixed_Asm_8:
6392 case ARM::VLD2LNdWB_fixed_Asm_16:
6393 case ARM::VLD2LNdWB_fixed_Asm_32:
6394 case ARM::VLD2LNqWB_fixed_Asm_16:
6395 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006396 MCInst TmpInst;
6397 // Shuffle the operands around so the lane index operand is in the
6398 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006399 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006400 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006401 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6403 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006404 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6405 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6406 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6407 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6408 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006409 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6410 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006411 TmpInst.addOperand(Inst.getOperand(1)); // lane
6412 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6413 TmpInst.addOperand(Inst.getOperand(5));
6414 Inst = TmpInst;
6415 return true;
6416 }
6417
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006418 case ARM::VLD3LNdWB_fixed_Asm_8:
6419 case ARM::VLD3LNdWB_fixed_Asm_16:
6420 case ARM::VLD3LNdWB_fixed_Asm_32:
6421 case ARM::VLD3LNqWB_fixed_Asm_16:
6422 case ARM::VLD3LNqWB_fixed_Asm_32: {
6423 MCInst TmpInst;
6424 // Shuffle the operands around so the lane index operand is in the
6425 // right place.
6426 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006427 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006428 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6429 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6430 Spacing));
6431 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006432 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006433 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6434 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6435 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6436 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6437 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6438 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6439 Spacing));
6440 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006441 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006442 TmpInst.addOperand(Inst.getOperand(1)); // lane
6443 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6444 TmpInst.addOperand(Inst.getOperand(5));
6445 Inst = TmpInst;
6446 return true;
6447 }
6448
Jim Grosbach14952a02012-01-24 18:37:25 +00006449 case ARM::VLD4LNdWB_fixed_Asm_8:
6450 case ARM::VLD4LNdWB_fixed_Asm_16:
6451 case ARM::VLD4LNdWB_fixed_Asm_32:
6452 case ARM::VLD4LNqWB_fixed_Asm_16:
6453 case ARM::VLD4LNqWB_fixed_Asm_32: {
6454 MCInst TmpInst;
6455 // Shuffle the operands around so the lane index operand is in the
6456 // right place.
6457 unsigned Spacing;
6458 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6459 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6460 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6461 Spacing));
6462 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6463 Spacing * 2));
6464 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6465 Spacing * 3));
6466 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6467 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6468 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6469 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6470 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6472 Spacing));
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6474 Spacing * 2));
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 Spacing * 3));
6477 TmpInst.addOperand(Inst.getOperand(1)); // lane
6478 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6479 TmpInst.addOperand(Inst.getOperand(5));
6480 Inst = TmpInst;
6481 return true;
6482 }
6483
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006484 case ARM::VLD1LNdAsm_8:
6485 case ARM::VLD1LNdAsm_16:
6486 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006487 MCInst TmpInst;
6488 // Shuffle the operands around so the lane index operand is in the
6489 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006490 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006491 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006492 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6493 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6494 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6495 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6496 TmpInst.addOperand(Inst.getOperand(1)); // lane
6497 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6498 TmpInst.addOperand(Inst.getOperand(5));
6499 Inst = TmpInst;
6500 return true;
6501 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006502
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006503 case ARM::VLD2LNdAsm_8:
6504 case ARM::VLD2LNdAsm_16:
6505 case ARM::VLD2LNdAsm_32:
6506 case ARM::VLD2LNqAsm_16:
6507 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006508 MCInst TmpInst;
6509 // Shuffle the operands around so the lane index operand is in the
6510 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006511 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006512 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006513 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006514 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6515 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006516 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6517 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6518 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006519 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6520 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006521 TmpInst.addOperand(Inst.getOperand(1)); // lane
6522 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6523 TmpInst.addOperand(Inst.getOperand(5));
6524 Inst = TmpInst;
6525 return true;
6526 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006527
6528 case ARM::VLD3LNdAsm_8:
6529 case ARM::VLD3LNdAsm_16:
6530 case ARM::VLD3LNdAsm_32:
6531 case ARM::VLD3LNqAsm_16:
6532 case ARM::VLD3LNqAsm_32: {
6533 MCInst TmpInst;
6534 // Shuffle the operands around so the lane index operand is in the
6535 // right place.
6536 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006537 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006538 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6539 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6540 Spacing));
6541 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006542 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006543 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6544 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6545 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6547 Spacing));
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006549 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006550 TmpInst.addOperand(Inst.getOperand(1)); // lane
6551 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6552 TmpInst.addOperand(Inst.getOperand(5));
6553 Inst = TmpInst;
6554 return true;
6555 }
6556
Jim Grosbach14952a02012-01-24 18:37:25 +00006557 case ARM::VLD4LNdAsm_8:
6558 case ARM::VLD4LNdAsm_16:
6559 case ARM::VLD4LNdAsm_32:
6560 case ARM::VLD4LNqAsm_16:
6561 case ARM::VLD4LNqAsm_32: {
6562 MCInst TmpInst;
6563 // Shuffle the operands around so the lane index operand is in the
6564 // right place.
6565 unsigned Spacing;
6566 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6567 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6568 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6569 Spacing));
6570 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6571 Spacing * 2));
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6573 Spacing * 3));
6574 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6575 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6576 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6577 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6578 Spacing));
6579 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6580 Spacing * 2));
6581 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6582 Spacing * 3));
6583 TmpInst.addOperand(Inst.getOperand(1)); // lane
6584 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6585 TmpInst.addOperand(Inst.getOperand(5));
6586 Inst = TmpInst;
6587 return true;
6588 }
6589
Jim Grosbachb78403c2012-01-24 23:47:04 +00006590 // VLD3DUP single 3-element structure to all lanes instructions.
6591 case ARM::VLD3DUPdAsm_8:
6592 case ARM::VLD3DUPdAsm_16:
6593 case ARM::VLD3DUPdAsm_32:
6594 case ARM::VLD3DUPqAsm_8:
6595 case ARM::VLD3DUPqAsm_16:
6596 case ARM::VLD3DUPqAsm_32: {
6597 MCInst TmpInst;
6598 unsigned Spacing;
6599 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6600 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6601 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6602 Spacing));
6603 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6604 Spacing * 2));
6605 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6606 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6607 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6608 TmpInst.addOperand(Inst.getOperand(4));
6609 Inst = TmpInst;
6610 return true;
6611 }
6612
6613 case ARM::VLD3DUPdWB_fixed_Asm_8:
6614 case ARM::VLD3DUPdWB_fixed_Asm_16:
6615 case ARM::VLD3DUPdWB_fixed_Asm_32:
6616 case ARM::VLD3DUPqWB_fixed_Asm_8:
6617 case ARM::VLD3DUPqWB_fixed_Asm_16:
6618 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6619 MCInst TmpInst;
6620 unsigned Spacing;
6621 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6622 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6624 Spacing));
6625 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6626 Spacing * 2));
6627 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6628 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6629 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6630 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6631 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6632 TmpInst.addOperand(Inst.getOperand(4));
6633 Inst = TmpInst;
6634 return true;
6635 }
6636
6637 case ARM::VLD3DUPdWB_register_Asm_8:
6638 case ARM::VLD3DUPdWB_register_Asm_16:
6639 case ARM::VLD3DUPdWB_register_Asm_32:
6640 case ARM::VLD3DUPqWB_register_Asm_8:
6641 case ARM::VLD3DUPqWB_register_Asm_16:
6642 case ARM::VLD3DUPqWB_register_Asm_32: {
6643 MCInst TmpInst;
6644 unsigned Spacing;
6645 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6646 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6648 Spacing));
6649 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6650 Spacing * 2));
6651 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6652 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6653 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6654 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6655 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6656 TmpInst.addOperand(Inst.getOperand(5));
6657 Inst = TmpInst;
6658 return true;
6659 }
6660
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006661 // VLD3 multiple 3-element structure instructions.
6662 case ARM::VLD3dAsm_8:
6663 case ARM::VLD3dAsm_16:
6664 case ARM::VLD3dAsm_32:
6665 case ARM::VLD3qAsm_8:
6666 case ARM::VLD3qAsm_16:
6667 case ARM::VLD3qAsm_32: {
6668 MCInst TmpInst;
6669 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006670 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006671 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6672 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6673 Spacing));
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6675 Spacing * 2));
6676 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6677 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6678 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6679 TmpInst.addOperand(Inst.getOperand(4));
6680 Inst = TmpInst;
6681 return true;
6682 }
6683
6684 case ARM::VLD3dWB_fixed_Asm_8:
6685 case ARM::VLD3dWB_fixed_Asm_16:
6686 case ARM::VLD3dWB_fixed_Asm_32:
6687 case ARM::VLD3qWB_fixed_Asm_8:
6688 case ARM::VLD3qWB_fixed_Asm_16:
6689 case ARM::VLD3qWB_fixed_Asm_32: {
6690 MCInst TmpInst;
6691 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006692 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006693 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6694 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6695 Spacing));
6696 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6697 Spacing * 2));
6698 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6699 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6700 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6701 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6702 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6703 TmpInst.addOperand(Inst.getOperand(4));
6704 Inst = TmpInst;
6705 return true;
6706 }
6707
6708 case ARM::VLD3dWB_register_Asm_8:
6709 case ARM::VLD3dWB_register_Asm_16:
6710 case ARM::VLD3dWB_register_Asm_32:
6711 case ARM::VLD3qWB_register_Asm_8:
6712 case ARM::VLD3qWB_register_Asm_16:
6713 case ARM::VLD3qWB_register_Asm_32: {
6714 MCInst TmpInst;
6715 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006716 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006717 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6718 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6719 Spacing));
6720 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6721 Spacing * 2));
6722 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6723 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6724 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6725 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6726 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6727 TmpInst.addOperand(Inst.getOperand(5));
6728 Inst = TmpInst;
6729 return true;
6730 }
6731
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006732 // VLD4DUP single 3-element structure to all lanes instructions.
6733 case ARM::VLD4DUPdAsm_8:
6734 case ARM::VLD4DUPdAsm_16:
6735 case ARM::VLD4DUPdAsm_32:
6736 case ARM::VLD4DUPqAsm_8:
6737 case ARM::VLD4DUPqAsm_16:
6738 case ARM::VLD4DUPqAsm_32: {
6739 MCInst TmpInst;
6740 unsigned Spacing;
6741 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6742 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6743 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6744 Spacing));
6745 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6746 Spacing * 2));
6747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6748 Spacing * 3));
6749 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6750 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6751 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6752 TmpInst.addOperand(Inst.getOperand(4));
6753 Inst = TmpInst;
6754 return true;
6755 }
6756
6757 case ARM::VLD4DUPdWB_fixed_Asm_8:
6758 case ARM::VLD4DUPdWB_fixed_Asm_16:
6759 case ARM::VLD4DUPdWB_fixed_Asm_32:
6760 case ARM::VLD4DUPqWB_fixed_Asm_8:
6761 case ARM::VLD4DUPqWB_fixed_Asm_16:
6762 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6763 MCInst TmpInst;
6764 unsigned Spacing;
6765 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6766 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6767 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6768 Spacing));
6769 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6770 Spacing * 2));
6771 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6772 Spacing * 3));
6773 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6774 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6775 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6776 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6777 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6778 TmpInst.addOperand(Inst.getOperand(4));
6779 Inst = TmpInst;
6780 return true;
6781 }
6782
6783 case ARM::VLD4DUPdWB_register_Asm_8:
6784 case ARM::VLD4DUPdWB_register_Asm_16:
6785 case ARM::VLD4DUPdWB_register_Asm_32:
6786 case ARM::VLD4DUPqWB_register_Asm_8:
6787 case ARM::VLD4DUPqWB_register_Asm_16:
6788 case ARM::VLD4DUPqWB_register_Asm_32: {
6789 MCInst TmpInst;
6790 unsigned Spacing;
6791 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6792 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6793 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6794 Spacing));
6795 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6796 Spacing * 2));
6797 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6798 Spacing * 3));
6799 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6800 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6801 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6802 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6803 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6804 TmpInst.addOperand(Inst.getOperand(5));
6805 Inst = TmpInst;
6806 return true;
6807 }
6808
6809 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006810 case ARM::VLD4dAsm_8:
6811 case ARM::VLD4dAsm_16:
6812 case ARM::VLD4dAsm_32:
6813 case ARM::VLD4qAsm_8:
6814 case ARM::VLD4qAsm_16:
6815 case ARM::VLD4qAsm_32: {
6816 MCInst TmpInst;
6817 unsigned Spacing;
6818 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6819 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6820 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6821 Spacing));
6822 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6823 Spacing * 2));
6824 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6825 Spacing * 3));
6826 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6827 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6828 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6829 TmpInst.addOperand(Inst.getOperand(4));
6830 Inst = TmpInst;
6831 return true;
6832 }
6833
6834 case ARM::VLD4dWB_fixed_Asm_8:
6835 case ARM::VLD4dWB_fixed_Asm_16:
6836 case ARM::VLD4dWB_fixed_Asm_32:
6837 case ARM::VLD4qWB_fixed_Asm_8:
6838 case ARM::VLD4qWB_fixed_Asm_16:
6839 case ARM::VLD4qWB_fixed_Asm_32: {
6840 MCInst TmpInst;
6841 unsigned Spacing;
6842 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6843 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6844 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6845 Spacing));
6846 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6847 Spacing * 2));
6848 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6849 Spacing * 3));
6850 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6851 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6852 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6853 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6854 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6855 TmpInst.addOperand(Inst.getOperand(4));
6856 Inst = TmpInst;
6857 return true;
6858 }
6859
6860 case ARM::VLD4dWB_register_Asm_8:
6861 case ARM::VLD4dWB_register_Asm_16:
6862 case ARM::VLD4dWB_register_Asm_32:
6863 case ARM::VLD4qWB_register_Asm_8:
6864 case ARM::VLD4qWB_register_Asm_16:
6865 case ARM::VLD4qWB_register_Asm_32: {
6866 MCInst TmpInst;
6867 unsigned Spacing;
6868 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6869 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6870 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6871 Spacing));
6872 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6873 Spacing * 2));
6874 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6875 Spacing * 3));
6876 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6877 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6878 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6879 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6880 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6881 TmpInst.addOperand(Inst.getOperand(5));
6882 Inst = TmpInst;
6883 return true;
6884 }
6885
Jim Grosbach1a747242012-01-23 23:45:44 +00006886 // VST3 multiple 3-element structure instructions.
6887 case ARM::VST3dAsm_8:
6888 case ARM::VST3dAsm_16:
6889 case ARM::VST3dAsm_32:
6890 case ARM::VST3qAsm_8:
6891 case ARM::VST3qAsm_16:
6892 case ARM::VST3qAsm_32: {
6893 MCInst TmpInst;
6894 unsigned Spacing;
6895 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6896 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6897 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6898 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6899 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6900 Spacing));
6901 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6902 Spacing * 2));
6903 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6904 TmpInst.addOperand(Inst.getOperand(4));
6905 Inst = TmpInst;
6906 return true;
6907 }
6908
6909 case ARM::VST3dWB_fixed_Asm_8:
6910 case ARM::VST3dWB_fixed_Asm_16:
6911 case ARM::VST3dWB_fixed_Asm_32:
6912 case ARM::VST3qWB_fixed_Asm_8:
6913 case ARM::VST3qWB_fixed_Asm_16:
6914 case ARM::VST3qWB_fixed_Asm_32: {
6915 MCInst TmpInst;
6916 unsigned Spacing;
6917 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6918 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6919 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6920 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6921 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6922 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6923 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6924 Spacing));
6925 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6926 Spacing * 2));
6927 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6928 TmpInst.addOperand(Inst.getOperand(4));
6929 Inst = TmpInst;
6930 return true;
6931 }
6932
6933 case ARM::VST3dWB_register_Asm_8:
6934 case ARM::VST3dWB_register_Asm_16:
6935 case ARM::VST3dWB_register_Asm_32:
6936 case ARM::VST3qWB_register_Asm_8:
6937 case ARM::VST3qWB_register_Asm_16:
6938 case ARM::VST3qWB_register_Asm_32: {
6939 MCInst TmpInst;
6940 unsigned Spacing;
6941 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6942 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6943 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6944 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6945 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6946 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6947 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6948 Spacing));
6949 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6950 Spacing * 2));
6951 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6952 TmpInst.addOperand(Inst.getOperand(5));
6953 Inst = TmpInst;
6954 return true;
6955 }
6956
Jim Grosbachda70eac2012-01-24 00:58:13 +00006957 // VST4 multiple 3-element structure instructions.
6958 case ARM::VST4dAsm_8:
6959 case ARM::VST4dAsm_16:
6960 case ARM::VST4dAsm_32:
6961 case ARM::VST4qAsm_8:
6962 case ARM::VST4qAsm_16:
6963 case ARM::VST4qAsm_32: {
6964 MCInst TmpInst;
6965 unsigned Spacing;
6966 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6967 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6968 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6969 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6970 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6971 Spacing));
6972 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6973 Spacing * 2));
6974 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6975 Spacing * 3));
6976 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6977 TmpInst.addOperand(Inst.getOperand(4));
6978 Inst = TmpInst;
6979 return true;
6980 }
6981
6982 case ARM::VST4dWB_fixed_Asm_8:
6983 case ARM::VST4dWB_fixed_Asm_16:
6984 case ARM::VST4dWB_fixed_Asm_32:
6985 case ARM::VST4qWB_fixed_Asm_8:
6986 case ARM::VST4qWB_fixed_Asm_16:
6987 case ARM::VST4qWB_fixed_Asm_32: {
6988 MCInst TmpInst;
6989 unsigned Spacing;
6990 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6991 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6992 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6993 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6994 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6995 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6996 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6997 Spacing));
6998 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6999 Spacing * 2));
7000 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7001 Spacing * 3));
7002 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7003 TmpInst.addOperand(Inst.getOperand(4));
7004 Inst = TmpInst;
7005 return true;
7006 }
7007
7008 case ARM::VST4dWB_register_Asm_8:
7009 case ARM::VST4dWB_register_Asm_16:
7010 case ARM::VST4dWB_register_Asm_32:
7011 case ARM::VST4qWB_register_Asm_8:
7012 case ARM::VST4qWB_register_Asm_16:
7013 case ARM::VST4qWB_register_Asm_32: {
7014 MCInst TmpInst;
7015 unsigned Spacing;
7016 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7017 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7018 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7019 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7020 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7021 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7022 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7023 Spacing));
7024 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7025 Spacing * 2));
7026 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7027 Spacing * 3));
7028 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7029 TmpInst.addOperand(Inst.getOperand(5));
7030 Inst = TmpInst;
7031 return true;
7032 }
7033
Jim Grosbachad66de12012-04-11 00:15:16 +00007034 // Handle encoding choice for the shift-immediate instructions.
7035 case ARM::t2LSLri:
7036 case ARM::t2LSRri:
7037 case ARM::t2ASRri: {
7038 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7039 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7040 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7041 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7042 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7043 unsigned NewOpc;
7044 switch (Inst.getOpcode()) {
7045 default: llvm_unreachable("unexpected opcode");
7046 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7047 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7048 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7049 }
7050 // The Thumb1 operands aren't in the same order. Awesome, eh?
7051 MCInst TmpInst;
7052 TmpInst.setOpcode(NewOpc);
7053 TmpInst.addOperand(Inst.getOperand(0));
7054 TmpInst.addOperand(Inst.getOperand(5));
7055 TmpInst.addOperand(Inst.getOperand(1));
7056 TmpInst.addOperand(Inst.getOperand(2));
7057 TmpInst.addOperand(Inst.getOperand(3));
7058 TmpInst.addOperand(Inst.getOperand(4));
7059 Inst = TmpInst;
7060 return true;
7061 }
7062 return false;
7063 }
7064
Jim Grosbach485e5622011-12-13 22:45:11 +00007065 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007066 case ARM::t2MOVsr:
7067 case ARM::t2MOVSsr: {
7068 // Which instruction to expand to depends on the CCOut operand and
7069 // whether we're in an IT block if the register operands are low
7070 // registers.
7071 bool isNarrow = false;
7072 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7073 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7074 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7075 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7076 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7077 isNarrow = true;
7078 MCInst TmpInst;
7079 unsigned newOpc;
7080 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7081 default: llvm_unreachable("unexpected opcode!");
7082 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7083 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7084 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7085 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7086 }
7087 TmpInst.setOpcode(newOpc);
7088 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7089 if (isNarrow)
7090 TmpInst.addOperand(MCOperand::CreateReg(
7091 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7092 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7093 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7094 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7095 TmpInst.addOperand(Inst.getOperand(5));
7096 if (!isNarrow)
7097 TmpInst.addOperand(MCOperand::CreateReg(
7098 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7099 Inst = TmpInst;
7100 return true;
7101 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007102 case ARM::t2MOVsi:
7103 case ARM::t2MOVSsi: {
7104 // Which instruction to expand to depends on the CCOut operand and
7105 // whether we're in an IT block if the register operands are low
7106 // registers.
7107 bool isNarrow = false;
7108 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7109 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7110 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7111 isNarrow = true;
7112 MCInst TmpInst;
7113 unsigned newOpc;
7114 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7115 default: llvm_unreachable("unexpected opcode!");
7116 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7117 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7118 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7119 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007120 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007121 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007122 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7123 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007124 TmpInst.setOpcode(newOpc);
7125 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7126 if (isNarrow)
7127 TmpInst.addOperand(MCOperand::CreateReg(
7128 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7129 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007130 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007131 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007132 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7133 TmpInst.addOperand(Inst.getOperand(4));
7134 if (!isNarrow)
7135 TmpInst.addOperand(MCOperand::CreateReg(
7136 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7137 Inst = TmpInst;
7138 return true;
7139 }
7140 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007141 case ARM::ASRr:
7142 case ARM::LSRr:
7143 case ARM::LSLr:
7144 case ARM::RORr: {
7145 ARM_AM::ShiftOpc ShiftTy;
7146 switch(Inst.getOpcode()) {
7147 default: llvm_unreachable("unexpected opcode!");
7148 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7149 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7150 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7151 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7152 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007153 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7154 MCInst TmpInst;
7155 TmpInst.setOpcode(ARM::MOVsr);
7156 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7157 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7158 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7159 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7160 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7161 TmpInst.addOperand(Inst.getOperand(4));
7162 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7163 Inst = TmpInst;
7164 return true;
7165 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007166 case ARM::ASRi:
7167 case ARM::LSRi:
7168 case ARM::LSLi:
7169 case ARM::RORi: {
7170 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007171 switch(Inst.getOpcode()) {
7172 default: llvm_unreachable("unexpected opcode!");
7173 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7174 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7175 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7176 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7177 }
7178 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007179 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007180 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007181 // A shift by 32 should be encoded as 0 when permitted
7182 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7183 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007184 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007185 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007186 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007187 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7188 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007189 if (Opc == ARM::MOVsi)
7190 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007191 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7192 TmpInst.addOperand(Inst.getOperand(4));
7193 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7194 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007195 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007196 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007197 case ARM::RRXi: {
7198 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7199 MCInst TmpInst;
7200 TmpInst.setOpcode(ARM::MOVsi);
7201 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7202 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7203 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7204 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7205 TmpInst.addOperand(Inst.getOperand(3));
7206 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7207 Inst = TmpInst;
7208 return true;
7209 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007210 case ARM::t2LDMIA_UPD: {
7211 // If this is a load of a single register, then we should use
7212 // a post-indexed LDR instruction instead, per the ARM ARM.
7213 if (Inst.getNumOperands() != 5)
7214 return false;
7215 MCInst TmpInst;
7216 TmpInst.setOpcode(ARM::t2LDR_POST);
7217 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7218 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7219 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7220 TmpInst.addOperand(MCOperand::CreateImm(4));
7221 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7222 TmpInst.addOperand(Inst.getOperand(3));
7223 Inst = TmpInst;
7224 return true;
7225 }
7226 case ARM::t2STMDB_UPD: {
7227 // If this is a store of a single register, then we should use
7228 // a pre-indexed STR instruction instead, per the ARM ARM.
7229 if (Inst.getNumOperands() != 5)
7230 return false;
7231 MCInst TmpInst;
7232 TmpInst.setOpcode(ARM::t2STR_PRE);
7233 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7234 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7235 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7236 TmpInst.addOperand(MCOperand::CreateImm(-4));
7237 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7238 TmpInst.addOperand(Inst.getOperand(3));
7239 Inst = TmpInst;
7240 return true;
7241 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007242 case ARM::LDMIA_UPD:
7243 // If this is a load of a single register via a 'pop', then we should use
7244 // a post-indexed LDR instruction instead, per the ARM ARM.
7245 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7246 Inst.getNumOperands() == 5) {
7247 MCInst TmpInst;
7248 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7249 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7250 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7251 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7252 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7253 TmpInst.addOperand(MCOperand::CreateImm(4));
7254 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7255 TmpInst.addOperand(Inst.getOperand(3));
7256 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007257 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007258 }
7259 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007260 case ARM::STMDB_UPD:
7261 // If this is a store of a single register via a 'push', then we should use
7262 // a pre-indexed STR instruction instead, per the ARM ARM.
7263 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7264 Inst.getNumOperands() == 5) {
7265 MCInst TmpInst;
7266 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7267 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7268 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7269 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7270 TmpInst.addOperand(MCOperand::CreateImm(-4));
7271 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7272 TmpInst.addOperand(Inst.getOperand(3));
7273 Inst = TmpInst;
7274 }
7275 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007276 case ARM::t2ADDri12:
7277 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7278 // mnemonic was used (not "addw"), encoding T3 is preferred.
7279 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7280 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7281 break;
7282 Inst.setOpcode(ARM::t2ADDri);
7283 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7284 break;
7285 case ARM::t2SUBri12:
7286 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7287 // mnemonic was used (not "subw"), encoding T3 is preferred.
7288 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7289 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7290 break;
7291 Inst.setOpcode(ARM::t2SUBri);
7292 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7293 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007294 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007295 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007296 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7297 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7298 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007299 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007300 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007301 return true;
7302 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007303 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007304 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007305 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007306 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7307 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7308 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007309 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007310 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007311 return true;
7312 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007313 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007314 case ARM::t2ADDri:
7315 case ARM::t2SUBri: {
7316 // If the destination and first source operand are the same, and
7317 // the flags are compatible with the current IT status, use encoding T2
7318 // instead of T3. For compatibility with the system 'as'. Make sure the
7319 // wide encoding wasn't explicit.
7320 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007321 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007322 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7323 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7324 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7325 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7326 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7327 break;
7328 MCInst TmpInst;
7329 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7330 ARM::tADDi8 : ARM::tSUBi8);
7331 TmpInst.addOperand(Inst.getOperand(0));
7332 TmpInst.addOperand(Inst.getOperand(5));
7333 TmpInst.addOperand(Inst.getOperand(0));
7334 TmpInst.addOperand(Inst.getOperand(2));
7335 TmpInst.addOperand(Inst.getOperand(3));
7336 TmpInst.addOperand(Inst.getOperand(4));
7337 Inst = TmpInst;
7338 return true;
7339 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007340 case ARM::t2ADDrr: {
7341 // If the destination and first source operand are the same, and
7342 // there's no setting of the flags, use encoding T2 instead of T3.
7343 // Note that this is only for ADD, not SUB. This mirrors the system
7344 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7345 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7346 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007347 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7348 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007349 break;
7350 MCInst TmpInst;
7351 TmpInst.setOpcode(ARM::tADDhirr);
7352 TmpInst.addOperand(Inst.getOperand(0));
7353 TmpInst.addOperand(Inst.getOperand(0));
7354 TmpInst.addOperand(Inst.getOperand(2));
7355 TmpInst.addOperand(Inst.getOperand(3));
7356 TmpInst.addOperand(Inst.getOperand(4));
7357 Inst = TmpInst;
7358 return true;
7359 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007360 case ARM::tADDrSP: {
7361 // If the non-SP source operand and the destination operand are not the
7362 // same, we need to use the 32-bit encoding if it's available.
7363 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7364 Inst.setOpcode(ARM::t2ADDrr);
7365 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7366 return true;
7367 }
7368 break;
7369 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007370 case ARM::tB:
7371 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007372 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007373 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007374 return true;
7375 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007376 break;
7377 case ARM::t2B:
7378 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007379 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007380 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007381 return true;
7382 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007383 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007384 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007385 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007386 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007387 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007388 return true;
7389 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007390 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007391 case ARM::tBcc:
7392 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007393 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007394 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007395 return true;
7396 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007397 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007398 case ARM::tLDMIA: {
7399 // If the register list contains any high registers, or if the writeback
7400 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7401 // instead if we're in Thumb2. Otherwise, this should have generated
7402 // an error in validateInstruction().
7403 unsigned Rn = Inst.getOperand(0).getReg();
7404 bool hasWritebackToken =
7405 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7406 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7407 bool listContainsBase;
7408 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7409 (!listContainsBase && !hasWritebackToken) ||
7410 (listContainsBase && hasWritebackToken)) {
7411 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7412 assert (isThumbTwo());
7413 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7414 // If we're switching to the updating version, we need to insert
7415 // the writeback tied operand.
7416 if (hasWritebackToken)
7417 Inst.insert(Inst.begin(),
7418 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007419 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007420 }
7421 break;
7422 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007423 case ARM::tSTMIA_UPD: {
7424 // If the register list contains any high registers, we need to use
7425 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7426 // should have generated an error in validateInstruction().
7427 unsigned Rn = Inst.getOperand(0).getReg();
7428 bool listContainsBase;
7429 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7430 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7431 assert (isThumbTwo());
7432 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007433 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007434 }
7435 break;
7436 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007437 case ARM::tPOP: {
7438 bool listContainsBase;
7439 // If the register list contains any high registers, we need to use
7440 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7441 // should have generated an error in validateInstruction().
7442 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007443 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007444 assert (isThumbTwo());
7445 Inst.setOpcode(ARM::t2LDMIA_UPD);
7446 // Add the base register and writeback operands.
7447 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7448 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007449 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007450 }
7451 case ARM::tPUSH: {
7452 bool listContainsBase;
7453 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007454 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007455 assert (isThumbTwo());
7456 Inst.setOpcode(ARM::t2STMDB_UPD);
7457 // Add the base register and writeback operands.
7458 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7459 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007460 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007461 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007462 case ARM::t2MOVi: {
7463 // If we can use the 16-bit encoding and the user didn't explicitly
7464 // request the 32-bit variant, transform it here.
7465 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007466 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007467 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7468 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7469 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007470 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7471 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7472 // The operands aren't in the same order for tMOVi8...
7473 MCInst TmpInst;
7474 TmpInst.setOpcode(ARM::tMOVi8);
7475 TmpInst.addOperand(Inst.getOperand(0));
7476 TmpInst.addOperand(Inst.getOperand(4));
7477 TmpInst.addOperand(Inst.getOperand(1));
7478 TmpInst.addOperand(Inst.getOperand(2));
7479 TmpInst.addOperand(Inst.getOperand(3));
7480 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007481 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007482 }
7483 break;
7484 }
7485 case ARM::t2MOVr: {
7486 // If we can use the 16-bit encoding and the user didn't explicitly
7487 // request the 32-bit variant, transform it here.
7488 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7489 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7490 Inst.getOperand(2).getImm() == ARMCC::AL &&
7491 Inst.getOperand(4).getReg() == ARM::CPSR &&
7492 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7493 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7494 // The operands aren't the same for tMOV[S]r... (no cc_out)
7495 MCInst TmpInst;
7496 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7497 TmpInst.addOperand(Inst.getOperand(0));
7498 TmpInst.addOperand(Inst.getOperand(1));
7499 TmpInst.addOperand(Inst.getOperand(2));
7500 TmpInst.addOperand(Inst.getOperand(3));
7501 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007502 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007503 }
7504 break;
7505 }
Jim Grosbach82213192011-09-19 20:29:33 +00007506 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007507 case ARM::t2SXTB:
7508 case ARM::t2UXTH:
7509 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007510 // If we can use the 16-bit encoding and the user didn't explicitly
7511 // request the 32-bit variant, transform it here.
7512 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7513 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7514 Inst.getOperand(2).getImm() == 0 &&
7515 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7516 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007517 unsigned NewOpc;
7518 switch (Inst.getOpcode()) {
7519 default: llvm_unreachable("Illegal opcode!");
7520 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7521 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7522 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7523 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7524 }
Jim Grosbach82213192011-09-19 20:29:33 +00007525 // The operands aren't the same for thumb1 (no rotate operand).
7526 MCInst TmpInst;
7527 TmpInst.setOpcode(NewOpc);
7528 TmpInst.addOperand(Inst.getOperand(0));
7529 TmpInst.addOperand(Inst.getOperand(1));
7530 TmpInst.addOperand(Inst.getOperand(3));
7531 TmpInst.addOperand(Inst.getOperand(4));
7532 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007533 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007534 }
7535 break;
7536 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007537 case ARM::MOVsi: {
7538 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007539 // rrx shifts and asr/lsr of #32 is encoded as 0
7540 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7541 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007542 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7543 // Shifting by zero is accepted as a vanilla 'MOVr'
7544 MCInst TmpInst;
7545 TmpInst.setOpcode(ARM::MOVr);
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 TmpInst.addOperand(Inst.getOperand(5));
7551 Inst = TmpInst;
7552 return true;
7553 }
7554 return false;
7555 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007556 case ARM::ANDrsi:
7557 case ARM::ORRrsi:
7558 case ARM::EORrsi:
7559 case ARM::BICrsi:
7560 case ARM::SUBrsi:
7561 case ARM::ADDrsi: {
7562 unsigned newOpc;
7563 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7564 if (SOpc == ARM_AM::rrx) return false;
7565 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007566 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007567 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7568 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7569 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7570 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7571 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7572 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7573 }
7574 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007575 // The exception is for right shifts, where 0 == 32
7576 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7577 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007578 MCInst TmpInst;
7579 TmpInst.setOpcode(newOpc);
7580 TmpInst.addOperand(Inst.getOperand(0));
7581 TmpInst.addOperand(Inst.getOperand(1));
7582 TmpInst.addOperand(Inst.getOperand(2));
7583 TmpInst.addOperand(Inst.getOperand(4));
7584 TmpInst.addOperand(Inst.getOperand(5));
7585 TmpInst.addOperand(Inst.getOperand(6));
7586 Inst = TmpInst;
7587 return true;
7588 }
7589 return false;
7590 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007591 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007592 case ARM::t2IT: {
7593 // The mask bits for all but the first condition are represented as
7594 // the low bit of the condition code value implies 't'. We currently
7595 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007596 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007597 MCOperand &MO = Inst.getOperand(1);
7598 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007599 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007600 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007601 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007602 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007603 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007604 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007605 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007606
7607 // Set up the IT block state according to the IT instruction we just
7608 // matched.
7609 assert(!inITBlock() && "nested IT blocks?!");
7610 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7611 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7612 ITState.CurPosition = 0;
7613 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007614 break;
7615 }
Richard Bartona39625e2012-07-09 16:12:24 +00007616 case ARM::t2LSLrr:
7617 case ARM::t2LSRrr:
7618 case ARM::t2ASRrr:
7619 case ARM::t2SBCrr:
7620 case ARM::t2RORrr:
7621 case ARM::t2BICrr:
7622 {
Richard Bartond5660372012-07-09 16:14:28 +00007623 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007624 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7625 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7626 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007627 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7628 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007629 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7630 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7631 unsigned NewOpc;
7632 switch (Inst.getOpcode()) {
7633 default: llvm_unreachable("unexpected opcode");
7634 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7635 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7636 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7637 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7638 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7639 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7640 }
7641 MCInst TmpInst;
7642 TmpInst.setOpcode(NewOpc);
7643 TmpInst.addOperand(Inst.getOperand(0));
7644 TmpInst.addOperand(Inst.getOperand(5));
7645 TmpInst.addOperand(Inst.getOperand(1));
7646 TmpInst.addOperand(Inst.getOperand(2));
7647 TmpInst.addOperand(Inst.getOperand(3));
7648 TmpInst.addOperand(Inst.getOperand(4));
7649 Inst = TmpInst;
7650 return true;
7651 }
7652 return false;
7653 }
7654 case ARM::t2ANDrr:
7655 case ARM::t2EORrr:
7656 case ARM::t2ADCrr:
7657 case ARM::t2ORRrr:
7658 {
Richard Bartond5660372012-07-09 16:14:28 +00007659 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007660 // These instructions are special in that they are commutable, so shorter encodings
7661 // are available more often.
7662 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7663 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7664 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7665 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007666 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7667 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007668 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7669 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7670 unsigned NewOpc;
7671 switch (Inst.getOpcode()) {
7672 default: llvm_unreachable("unexpected opcode");
7673 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7674 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7675 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7676 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7677 }
7678 MCInst TmpInst;
7679 TmpInst.setOpcode(NewOpc);
7680 TmpInst.addOperand(Inst.getOperand(0));
7681 TmpInst.addOperand(Inst.getOperand(5));
7682 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7683 TmpInst.addOperand(Inst.getOperand(1));
7684 TmpInst.addOperand(Inst.getOperand(2));
7685 } else {
7686 TmpInst.addOperand(Inst.getOperand(2));
7687 TmpInst.addOperand(Inst.getOperand(1));
7688 }
7689 TmpInst.addOperand(Inst.getOperand(3));
7690 TmpInst.addOperand(Inst.getOperand(4));
7691 Inst = TmpInst;
7692 return true;
7693 }
7694 return false;
7695 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007696 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007697 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007698}
7699
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007700unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7701 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7702 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007703 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007704 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007705 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7706 assert(MCID.hasOptionalDef() &&
7707 "optionally flag setting instruction missing optional def operand");
7708 assert(MCID.NumOperands == Inst.getNumOperands() &&
7709 "operand count mismatch!");
7710 // Find the optional-def operand (cc_out).
7711 unsigned OpNo;
7712 for (OpNo = 0;
7713 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7714 ++OpNo)
7715 ;
7716 // If we're parsing Thumb1, reject it completely.
7717 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7718 return Match_MnemonicFail;
7719 // If we're parsing Thumb2, which form is legal depends on whether we're
7720 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007721 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7722 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007723 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007724 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7725 inITBlock())
7726 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007727 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007728 // Some high-register supporting Thumb1 encodings only allow both registers
7729 // to be from r0-r7 when in Thumb2.
7730 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7731 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7732 isARMLowRegister(Inst.getOperand(2).getReg()))
7733 return Match_RequiresThumb2;
7734 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007735 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007736 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7737 isARMLowRegister(Inst.getOperand(1).getReg()))
7738 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007739 return Match_Success;
7740}
7741
Jim Grosbach5117ef72012-04-24 22:40:08 +00007742static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007743bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007744MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007745 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007746 MCStreamer &Out, unsigned &ErrorInfo,
7747 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007748 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007749 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007750
Chad Rosier2f480a82012-10-12 22:53:36 +00007751 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007752 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007753 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007754 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007755 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007756 // Context sensitive operand constraints aren't handled by the matcher,
7757 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007758 if (validateInstruction(Inst, Operands)) {
7759 // Still progress the IT block, otherwise one wrong condition causes
7760 // nasty cascading errors.
7761 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007762 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007763 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007764
Amara Emerson52cfb6a2013-10-03 09:31:51 +00007765 { // processInstruction() updates inITBlock state, we need to save it away
7766 bool wasInITBlock = inITBlock();
7767
7768 // Some instructions need post-processing to, for example, tweak which
7769 // encoding is selected. Loop on it while changes happen so the
7770 // individual transformations can chain off each other. E.g.,
7771 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7772 while (processInstruction(Inst, Operands))
7773 ;
7774
7775 // Only after the instruction is fully processed, we can validate it
7776 if (wasInITBlock && hasV8Ops() && isThumb() &&
7777 !isV8EligibleForIT(&Inst, 2)) {
7778 Warning(IDLoc, "deprecated instruction in IT block");
7779 }
7780 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007781
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007782 // Only move forward at the very end so that everything in validate
7783 // and process gets a consistent answer about whether we're in an IT
7784 // block.
7785 forwardITPosition();
7786
Jim Grosbach82f76d12012-01-25 19:52:01 +00007787 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7788 // doesn't actually encode.
7789 if (Inst.getOpcode() == ARM::ITasm)
7790 return false;
7791
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007792 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007793 Out.EmitInstruction(Inst);
7794 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007795 case Match_MissingFeature: {
7796 assert(ErrorInfo && "Unknown missing feature!");
7797 // Special case the error message for the very common case where only
7798 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7799 std::string Msg = "instruction requires:";
7800 unsigned Mask = 1;
7801 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7802 if (ErrorInfo & Mask) {
7803 Msg += " ";
7804 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7805 }
7806 Mask <<= 1;
7807 }
7808 return Error(IDLoc, Msg);
7809 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007810 case Match_InvalidOperand: {
7811 SMLoc ErrorLoc = IDLoc;
7812 if (ErrorInfo != ~0U) {
7813 if (ErrorInfo >= Operands.size())
7814 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007815
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007816 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7817 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7818 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007819
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007820 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007821 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007822 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007823 return Error(IDLoc, "invalid instruction",
7824 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007825 case Match_RequiresNotITBlock:
7826 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007827 case Match_RequiresITBlock:
7828 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007829 case Match_RequiresV6:
7830 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7831 case Match_RequiresThumb2:
7832 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007833 case Match_ImmRange0_15: {
7834 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7835 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7836 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7837 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00007838 case Match_ImmRange0_239: {
7839 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7840 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7841 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7842 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007843 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007844
Eric Christopher91d7b902010-10-29 09:26:59 +00007845 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007846}
7847
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007848/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007849bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7850 StringRef IDVal = DirectiveID.getIdentifier();
7851 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007852 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007853 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007854 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007855 else if (IDVal == ".arm")
7856 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007857 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007858 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007859 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007860 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007861 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007862 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007863 else if (IDVal == ".unreq")
7864 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007865 else if (IDVal == ".arch")
7866 return parseDirectiveArch(DirectiveID.getLoc());
7867 else if (IDVal == ".eabi_attribute")
7868 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien8cbb80d2013-10-28 17:51:12 +00007869 else if (IDVal == ".cpu")
7870 return parseDirectiveCPU(DirectiveID.getLoc());
7871 else if (IDVal == ".fpu")
7872 return parseDirectiveFPU(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007873 else if (IDVal == ".fnstart")
7874 return parseDirectiveFnStart(DirectiveID.getLoc());
7875 else if (IDVal == ".fnend")
7876 return parseDirectiveFnEnd(DirectiveID.getLoc());
7877 else if (IDVal == ".cantunwind")
7878 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7879 else if (IDVal == ".personality")
7880 return parseDirectivePersonality(DirectiveID.getLoc());
7881 else if (IDVal == ".handlerdata")
7882 return parseDirectiveHandlerData(DirectiveID.getLoc());
7883 else if (IDVal == ".setfp")
7884 return parseDirectiveSetFP(DirectiveID.getLoc());
7885 else if (IDVal == ".pad")
7886 return parseDirectivePad(DirectiveID.getLoc());
7887 else if (IDVal == ".save")
7888 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7889 else if (IDVal == ".vsave")
7890 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00007891 else if (IDVal == ".inst")
7892 return parseDirectiveInst(DirectiveID.getLoc());
7893 else if (IDVal == ".inst.n")
7894 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7895 else if (IDVal == ".inst.w")
7896 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
Kevin Enderbyccab3172009-09-15 00:27:25 +00007897 return true;
7898}
7899
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007900/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007901/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007902bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007903 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7904 for (;;) {
7905 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007906 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007907 return true;
7908
Eric Christopherbf7bc492013-01-09 03:52:05 +00007909 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007910
7911 if (getLexer().is(AsmToken::EndOfStatement))
7912 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007913
Kevin Enderbyccab3172009-09-15 00:27:25 +00007914 // FIXME: Improve diagnostic.
7915 if (getLexer().isNot(AsmToken::Comma))
7916 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007917 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007918 }
7919 }
7920
Sean Callanana83fd7d2010-01-19 20:27:46 +00007921 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007922 return false;
7923}
7924
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007925/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007926/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007927bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007928 if (getLexer().isNot(AsmToken::EndOfStatement))
7929 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007930 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007931
Tim Northovera2292d02013-06-10 23:20:58 +00007932 if (!hasThumb())
7933 return Error(L, "target does not support Thumb mode");
7934
Jim Grosbach7f882392011-12-07 18:04:19 +00007935 if (!isThumb())
7936 SwitchMode();
7937 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7938 return false;
7939}
7940
7941/// parseDirectiveARM
7942/// ::= .arm
7943bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7944 if (getLexer().isNot(AsmToken::EndOfStatement))
7945 return Error(L, "unexpected token in directive");
7946 Parser.Lex();
7947
Tim Northovera2292d02013-06-10 23:20:58 +00007948 if (!hasARM())
7949 return Error(L, "target does not support ARM mode");
7950
Jim Grosbach7f882392011-12-07 18:04:19 +00007951 if (isThumb())
7952 SwitchMode();
7953 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007954 return false;
7955}
7956
Tim Northover1744d0a2013-10-25 12:49:50 +00007957void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
7958 if (NextSymbolIsThumb) {
7959 getParser().getStreamer().EmitThumbFunc(Symbol);
7960 NextSymbolIsThumb = false;
7961 }
7962}
7963
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007964/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007965/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007966bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007967 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7968 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007969
Jim Grosbach1152cc02011-12-21 22:30:16 +00007970 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007971 // ELF doesn't
7972 if (isMachO) {
7973 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007974 if (Tok.isNot(AsmToken::EndOfStatement)) {
7975 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7976 return Error(L, "unexpected token in .thumb_func directive");
Tim Northover1744d0a2013-10-25 12:49:50 +00007977 MCSymbol *Func =
7978 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
7979 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00007980 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00007981 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007982 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007983 }
7984
Jim Grosbach1152cc02011-12-21 22:30:16 +00007985 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007986 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007987
Tim Northover1744d0a2013-10-25 12:49:50 +00007988 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00007989
Kevin Enderby146dcf22009-10-15 20:48:48 +00007990 return false;
7991}
7992
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007993/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007994/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007995bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007996 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007997 if (Tok.isNot(AsmToken::Identifier))
7998 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007999 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00008000 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00008001 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00008002 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00008003 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00008004 else
8005 return Error(L, "unrecognized syntax mode in .syntax directive");
8006
8007 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00008008 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00008009 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008010
8011 // TODO tell the MC streamer the mode
8012 // getParser().getStreamer().Emit???();
8013 return false;
8014}
8015
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008016/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008017/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008018bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008019 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008020 if (Tok.isNot(AsmToken::Integer))
8021 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00008022 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00008023 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00008024 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00008025 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00008026 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008027 else
8028 return Error(L, "invalid operand to .code directive");
8029
8030 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00008031 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00008032 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008033
Evan Cheng284b4672011-07-08 22:36:29 +00008034 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00008035 if (!hasThumb())
8036 return Error(L, "target does not support Thumb mode");
8037
Jim Grosbachf471ac32011-09-06 18:46:23 +00008038 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008039 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008040 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008041 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00008042 if (!hasARM())
8043 return Error(L, "target does not support ARM mode");
8044
Jim Grosbachf471ac32011-09-06 18:46:23 +00008045 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008046 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008047 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008048 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008049
Kevin Enderby146dcf22009-10-15 20:48:48 +00008050 return false;
8051}
8052
Jim Grosbachab5830e2011-12-14 02:16:11 +00008053/// parseDirectiveReq
8054/// ::= name .req registername
8055bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8056 Parser.Lex(); // Eat the '.req' token.
8057 unsigned Reg;
8058 SMLoc SRegLoc, ERegLoc;
8059 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008060 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008061 return Error(SRegLoc, "register name expected");
8062 }
8063
8064 // Shouldn't be anything else.
8065 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008066 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008067 return Error(Parser.getTok().getLoc(),
8068 "unexpected input in .req directive.");
8069 }
8070
8071 Parser.Lex(); // Consume the EndOfStatement
8072
8073 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
8074 return Error(SRegLoc, "redefinition of '" + Name +
8075 "' does not match original.");
8076
8077 return false;
8078}
8079
8080/// parseDirectiveUneq
8081/// ::= .unreq registername
8082bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8083 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008084 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008085 return Error(L, "unexpected input in .unreq directive.");
8086 }
8087 RegisterReqs.erase(Parser.getTok().getIdentifier());
8088 Parser.Lex(); // Eat the identifier.
8089 return false;
8090}
8091
Jason W Kim135d2442011-12-20 17:38:12 +00008092/// parseDirectiveArch
8093/// ::= .arch token
8094bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008095 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8096
8097 unsigned ID = StringSwitch<unsigned>(Arch)
8098#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8099 .Case(NAME, ARM::ID)
8100#include "MCTargetDesc/ARMArchName.def"
8101 .Default(ARM::INVALID_ARCH);
8102
8103 if (ID == ARM::INVALID_ARCH)
8104 return Error(L, "Unknown arch name");
8105
8106 getTargetStreamer().emitArch(ID);
8107 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008108}
8109
8110/// parseDirectiveEabiAttr
8111/// ::= .eabi_attribute int, int
8112bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Logan Chien8cbb80d2013-10-28 17:51:12 +00008113 if (Parser.getTok().isNot(AsmToken::Integer))
8114 return Error(L, "integer expected");
8115 int64_t Tag = Parser.getTok().getIntVal();
8116 Parser.Lex(); // eat tag integer
8117
8118 if (Parser.getTok().isNot(AsmToken::Comma))
8119 return Error(L, "comma expected");
8120 Parser.Lex(); // skip comma
8121
8122 L = Parser.getTok().getLoc();
8123 if (Parser.getTok().isNot(AsmToken::Integer))
8124 return Error(L, "integer expected");
8125 int64_t Value = Parser.getTok().getIntVal();
8126 Parser.Lex(); // eat value integer
8127
8128 getTargetStreamer().emitAttribute(Tag, Value);
8129 return false;
8130}
8131
8132/// parseDirectiveCPU
8133/// ::= .cpu str
8134bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8135 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8136 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8137 return false;
8138}
8139
8140/// parseDirectiveFPU
8141/// ::= .fpu str
8142bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8143 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8144
8145 unsigned ID = StringSwitch<unsigned>(FPU)
8146#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8147#include "ARMFPUName.def"
8148 .Default(ARM::INVALID_FPU);
8149
8150 if (ID == ARM::INVALID_FPU)
8151 return Error(L, "Unknown FPU name");
8152
8153 getTargetStreamer().emitFPU(ID);
8154 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008155}
8156
Logan Chien4ea23b52013-05-10 16:17:24 +00008157/// parseDirectiveFnStart
8158/// ::= .fnstart
8159bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8160 if (FnStartLoc.isValid()) {
8161 Error(L, ".fnstart starts before the end of previous one");
8162 Error(FnStartLoc, "previous .fnstart starts here");
8163 return true;
8164 }
8165
8166 FnStartLoc = L;
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008167 getTargetStreamer().emitFnStart();
Logan Chien4ea23b52013-05-10 16:17:24 +00008168 return false;
8169}
8170
8171/// parseDirectiveFnEnd
8172/// ::= .fnend
8173bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8174 // Check the ordering of unwind directives
8175 if (!FnStartLoc.isValid())
8176 return Error(L, ".fnstart must precede .fnend directive");
8177
8178 // Reset the unwind directives parser state
8179 resetUnwindDirectiveParserState();
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008180 getTargetStreamer().emitFnEnd();
Logan Chien4ea23b52013-05-10 16:17:24 +00008181 return false;
8182}
8183
8184/// parseDirectiveCantUnwind
8185/// ::= .cantunwind
8186bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8187 // Check the ordering of unwind directives
8188 CantUnwindLoc = L;
8189 if (!FnStartLoc.isValid())
8190 return Error(L, ".fnstart must precede .cantunwind directive");
8191 if (HandlerDataLoc.isValid()) {
8192 Error(L, ".cantunwind can't be used with .handlerdata directive");
8193 Error(HandlerDataLoc, ".handlerdata was specified here");
8194 return true;
8195 }
8196 if (PersonalityLoc.isValid()) {
8197 Error(L, ".cantunwind can't be used with .personality directive");
8198 Error(PersonalityLoc, ".personality was specified here");
8199 return true;
8200 }
8201
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008202 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008203 return false;
8204}
8205
8206/// parseDirectivePersonality
8207/// ::= .personality name
8208bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8209 // Check the ordering of unwind directives
8210 PersonalityLoc = L;
8211 if (!FnStartLoc.isValid())
8212 return Error(L, ".fnstart must precede .personality directive");
8213 if (CantUnwindLoc.isValid()) {
8214 Error(L, ".personality can't be used with .cantunwind directive");
8215 Error(CantUnwindLoc, ".cantunwind was specified here");
8216 return true;
8217 }
8218 if (HandlerDataLoc.isValid()) {
8219 Error(L, ".personality must precede .handlerdata directive");
8220 Error(HandlerDataLoc, ".handlerdata was specified here");
8221 return true;
8222 }
8223
8224 // Parse the name of the personality routine
8225 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8226 Parser.eatToEndOfStatement();
8227 return Error(L, "unexpected input in .personality directive.");
8228 }
8229 StringRef Name(Parser.getTok().getIdentifier());
8230 Parser.Lex();
8231
8232 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008233 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008234 return false;
8235}
8236
8237/// parseDirectiveHandlerData
8238/// ::= .handlerdata
8239bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8240 // Check the ordering of unwind directives
8241 HandlerDataLoc = L;
8242 if (!FnStartLoc.isValid())
8243 return Error(L, ".fnstart must precede .personality directive");
8244 if (CantUnwindLoc.isValid()) {
8245 Error(L, ".handlerdata can't be used with .cantunwind directive");
8246 Error(CantUnwindLoc, ".cantunwind was specified here");
8247 return true;
8248 }
8249
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008250 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008251 return false;
8252}
8253
8254/// parseDirectiveSetFP
8255/// ::= .setfp fpreg, spreg [, offset]
8256bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8257 // Check the ordering of unwind directives
8258 if (!FnStartLoc.isValid())
8259 return Error(L, ".fnstart must precede .setfp directive");
8260 if (HandlerDataLoc.isValid())
8261 return Error(L, ".setfp must precede .handlerdata directive");
8262
8263 // Parse fpreg
8264 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8265 int NewFPReg = tryParseRegister();
8266 if (NewFPReg == -1)
8267 return Error(NewFPRegLoc, "frame pointer register expected");
8268
8269 // Consume comma
8270 if (!Parser.getTok().is(AsmToken::Comma))
8271 return Error(Parser.getTok().getLoc(), "comma expected");
8272 Parser.Lex(); // skip comma
8273
8274 // Parse spreg
8275 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8276 int NewSPReg = tryParseRegister();
8277 if (NewSPReg == -1)
8278 return Error(NewSPRegLoc, "stack pointer register expected");
8279
8280 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8281 return Error(NewSPRegLoc,
8282 "register should be either $sp or the latest fp register");
8283
8284 // Update the frame pointer register
8285 FPReg = NewFPReg;
8286
8287 // Parse offset
8288 int64_t Offset = 0;
8289 if (Parser.getTok().is(AsmToken::Comma)) {
8290 Parser.Lex(); // skip comma
8291
8292 if (Parser.getTok().isNot(AsmToken::Hash) &&
8293 Parser.getTok().isNot(AsmToken::Dollar)) {
8294 return Error(Parser.getTok().getLoc(), "'#' expected");
8295 }
8296 Parser.Lex(); // skip hash token.
8297
8298 const MCExpr *OffsetExpr;
8299 SMLoc ExLoc = Parser.getTok().getLoc();
8300 SMLoc EndLoc;
8301 if (getParser().parseExpression(OffsetExpr, EndLoc))
8302 return Error(ExLoc, "malformed setfp offset");
8303 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8304 if (!CE)
8305 return Error(ExLoc, "setfp offset must be an immediate");
8306
8307 Offset = CE->getValue();
8308 }
8309
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008310 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8311 static_cast<unsigned>(NewSPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008312 return false;
8313}
8314
8315/// parseDirective
8316/// ::= .pad offset
8317bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8318 // Check the ordering of unwind directives
8319 if (!FnStartLoc.isValid())
8320 return Error(L, ".fnstart must precede .pad directive");
8321 if (HandlerDataLoc.isValid())
8322 return Error(L, ".pad must precede .handlerdata directive");
8323
8324 // Parse the offset
8325 if (Parser.getTok().isNot(AsmToken::Hash) &&
8326 Parser.getTok().isNot(AsmToken::Dollar)) {
8327 return Error(Parser.getTok().getLoc(), "'#' expected");
8328 }
8329 Parser.Lex(); // skip hash token.
8330
8331 const MCExpr *OffsetExpr;
8332 SMLoc ExLoc = Parser.getTok().getLoc();
8333 SMLoc EndLoc;
8334 if (getParser().parseExpression(OffsetExpr, EndLoc))
8335 return Error(ExLoc, "malformed pad offset");
8336 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8337 if (!CE)
8338 return Error(ExLoc, "pad offset must be an immediate");
8339
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008340 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008341 return false;
8342}
8343
8344/// parseDirectiveRegSave
8345/// ::= .save { registers }
8346/// ::= .vsave { registers }
8347bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8348 // Check the ordering of unwind directives
8349 if (!FnStartLoc.isValid())
8350 return Error(L, ".fnstart must precede .save or .vsave directives");
8351 if (HandlerDataLoc.isValid())
8352 return Error(L, ".save or .vsave must precede .handlerdata directive");
8353
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008354 // RAII object to make sure parsed operands are deleted.
8355 struct CleanupObject {
8356 SmallVector<MCParsedAsmOperand *, 1> Operands;
8357 ~CleanupObject() {
8358 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8359 delete Operands[I];
8360 }
8361 } CO;
8362
Logan Chien4ea23b52013-05-10 16:17:24 +00008363 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008364 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008365 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008366 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008367 if (!IsVector && !Op->isRegList())
8368 return Error(L, ".save expects GPR registers");
8369 if (IsVector && !Op->isDPRRegList())
8370 return Error(L, ".vsave expects DPR registers");
8371
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008372 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008373 return false;
8374}
8375
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008376/// parseDirectiveInst
8377/// ::= .inst opcode [, ...]
8378/// ::= .inst.n opcode [, ...]
8379/// ::= .inst.w opcode [, ...]
8380bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8381 int Width;
8382
8383 if (isThumb()) {
8384 switch (Suffix) {
8385 case 'n':
8386 Width = 2;
8387 break;
8388 case 'w':
8389 Width = 4;
8390 break;
8391 default:
8392 Parser.eatToEndOfStatement();
8393 return Error(Loc, "cannot determine Thumb instruction size, "
8394 "use inst.n/inst.w instead");
8395 }
8396 } else {
8397 if (Suffix) {
8398 Parser.eatToEndOfStatement();
8399 return Error(Loc, "width suffixes are invalid in ARM mode");
8400 }
8401 Width = 4;
8402 }
8403
8404 if (getLexer().is(AsmToken::EndOfStatement)) {
8405 Parser.eatToEndOfStatement();
8406 return Error(Loc, "expected expression following directive");
8407 }
8408
8409 for (;;) {
8410 const MCExpr *Expr;
8411
8412 if (getParser().parseExpression(Expr))
8413 return Error(Loc, "expected expression");
8414
8415 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
8416 if (!Value)
8417 return Error(Loc, "expected constant expression");
8418
8419 switch (Width) {
8420 case 2:
8421 if (Value->getValue() > 0xffff)
8422 return Error(Loc, "inst.n operand is too big, use inst.w instead");
8423 break;
8424 case 4:
8425 if (Value->getValue() > 0xffffffff)
8426 return Error(Loc,
8427 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8428 break;
8429 default:
8430 llvm_unreachable("only supported widths are 2 and 4");
8431 }
8432
8433 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8434
8435 if (getLexer().is(AsmToken::EndOfStatement))
8436 break;
8437
8438 if (getLexer().isNot(AsmToken::Comma))
8439 return Error(Loc, "unexpected token in directive");
8440
8441 Parser.Lex();
8442 }
8443
8444 Parser.Lex();
8445 return false;
8446}
8447
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008448/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008449extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008450 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8451 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008452}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008453
Chris Lattner3e4582a2010-09-06 19:11:01 +00008454#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008455#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008456#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008457#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008458
8459// Define this matcher function after the auto-generated include so we
8460// have the match class enum definitions.
8461unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8462 unsigned Kind) {
8463 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8464 // If the kind is a token for a literal immediate, check if our asm
8465 // operand matches. This is for InstAliases which have a fixed-value
8466 // immediate in the syntax.
8467 if (Kind == MCK__35_0 && Op->isImm()) {
8468 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8469 if (!CE)
8470 return Match_InvalidOperand;
8471 if (CE->getValue() == 0)
8472 return Match_Success;
8473 }
8474 return Match_InvalidOperand;
8475}
David Peixottoe407d092013-12-19 18:12:36 +00008476
8477void ARMAsmParser::finishParse() {
8478 // Dump contents of assembler constant pools.
8479 MCStreamer &Streamer = getParser().getStreamer();
8480 for (ConstantPoolMapTy::iterator CPI = ConstantPools.begin(),
8481 CPE = ConstantPools.end();
8482 CPI != CPE; ++CPI) {
8483 const MCSection *Section = CPI->first;
8484 ConstantPool &CP = CPI->second;
8485
8486 // Dump assembler constant pools at the end of the section.
8487 Streamer.SwitchSection(Section);
8488 CP.emitEntries(Streamer);
8489 }
8490}