blob: e3215491fdf00ff17c1e18df193768eff150792a [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 "ARMFPUName.h"
Amara Emerson52cfb6a2013-10-03 09:31:51 +000011#include "ARMFeatures.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000012#include "MCTargetDesc/ARMAddressingModes.h"
Logan Chien439e8f92013-12-11 17:16:25 +000013#include "MCTargetDesc/ARMArchName.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "MCTargetDesc/ARMBaseInfo.h"
15#include "MCTargetDesc/ARMMCExpr.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000016#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000017#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000018#include "llvm/ADT/SmallVector.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000019#include "llvm/ADT/StringExtras.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000020#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000021#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000023#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/MC/MCContext.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000025#include "llvm/MC/MCDisassembler.h"
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +000026#include "llvm/MC/MCELF.h"
Jack Carter718da0b2013-01-30 02:24:33 +000027#include "llvm/MC/MCELFStreamer.h"
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +000028#include "llvm/MC/MCELFSymbolFlags.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"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000033#include "llvm/MC/MCObjectFileInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/MC/MCParser/MCAsmLexer.h"
35#include "llvm/MC/MCParser/MCAsmParser.h"
36#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
37#include "llvm/MC/MCRegisterInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000038#include "llvm/MC/MCSection.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000039#include "llvm/MC/MCStreamer.h"
40#include "llvm/MC/MCSubtargetInfo.h"
David Peixottoe407d092013-12-19 18:12:36 +000041#include "llvm/MC/MCSymbol.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000042#include "llvm/MC/MCTargetAsmParser.h"
Saleem Abdulrasool278a9f42014-01-19 08:25:27 +000043#include "llvm/Support/ARMBuildAttributes.h"
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000044#include "llvm/Support/ARMEHABI.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000045#include "llvm/Support/COFF.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000046#include "llvm/Support/Debug.h"
Jack Carter718da0b2013-01-30 02:24:33 +000047#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000048#include "llvm/Support/MathExtras.h"
49#include "llvm/Support/SourceMgr.h"
50#include "llvm/Support/TargetRegistry.h"
51#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000052
Kevin Enderbyccab3172009-09-15 00:27:25 +000053using namespace llvm;
54
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000055namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000056
57class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000058
Jim Grosbach04945c42011-12-02 00:35:16 +000059enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000060
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000061class UnwindContext {
62 MCAsmParser &Parser;
63
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000064 typedef SmallVector<SMLoc, 4> Locs;
65
66 Locs FnStartLocs;
67 Locs CantUnwindLocs;
68 Locs PersonalityLocs;
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000069 Locs PersonalityIndexLocs;
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000070 Locs HandlerDataLocs;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000071 int FPReg;
72
73public:
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +000074 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {}
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000075
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000076 bool hasFnStart() const { return !FnStartLocs.empty(); }
77 bool cantUnwind() const { return !CantUnwindLocs.empty(); }
78 bool hasHandlerData() const { return !HandlerDataLocs.empty(); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000079 bool hasPersonality() const {
80 return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty());
81 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000082
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000083 void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); }
84 void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); }
85 void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); }
86 void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000087 void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000088
89 void saveFPReg(int Reg) { FPReg = Reg; }
90 int getFPReg() const { return FPReg; }
91
92 void emitFnStartLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000093 for (Locs::const_iterator FI = FnStartLocs.begin(), FE = FnStartLocs.end();
94 FI != FE; ++FI)
95 Parser.Note(*FI, ".fnstart was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000096 }
97 void emitCantUnwindLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000098 for (Locs::const_iterator UI = CantUnwindLocs.begin(),
99 UE = CantUnwindLocs.end(); UI != UE; ++UI)
100 Parser.Note(*UI, ".cantunwind was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000101 }
102 void emitHandlerDataLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000103 for (Locs::const_iterator HI = HandlerDataLocs.begin(),
104 HE = HandlerDataLocs.end(); HI != HE; ++HI)
105 Parser.Note(*HI, ".handlerdata was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000106 }
107 void emitPersonalityLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000108 for (Locs::const_iterator PI = PersonalityLocs.begin(),
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000109 PE = PersonalityLocs.end(),
110 PII = PersonalityIndexLocs.begin(),
111 PIE = PersonalityIndexLocs.end();
112 PI != PE || PII != PIE;) {
113 if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer()))
114 Parser.Note(*PI++, ".personality was specified here");
115 else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer()))
116 Parser.Note(*PII++, ".personalityindex was specified here");
117 else
118 llvm_unreachable(".personality and .personalityindex cannot be "
119 "at the same location");
120 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000121 }
122
123 void reset() {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000124 FnStartLocs = Locs();
125 CantUnwindLocs = Locs();
126 PersonalityLocs = Locs();
127 HandlerDataLocs = Locs();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000128 PersonalityIndexLocs = Locs();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000129 FPReg = ARM::SP;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000130 }
131};
132
Evan Cheng11424442011-07-26 00:24:13 +0000133class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +0000134 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000135 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +0000136 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000137 const MCRegisterInfo *MRI;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000138 UnwindContext UC;
David Peixottoe407d092013-12-19 18:12:36 +0000139
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000140 ARMTargetStreamer &getTargetStreamer() {
Rafael Espindola4a1a3602014-01-14 01:21:46 +0000141 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000142 return static_cast<ARMTargetStreamer &>(TS);
143 }
144
Jim Grosbachab5830e2011-12-14 02:16:11 +0000145 // Map of register aliases registers via the .req directive.
146 StringMap<unsigned> RegisterReqs;
147
Tim Northover1744d0a2013-10-25 12:49:50 +0000148 bool NextSymbolIsThumb;
149
Jim Grosbached16ec42011-08-29 22:24:09 +0000150 struct {
151 ARMCC::CondCodes Cond; // Condition for IT block.
152 unsigned Mask:4; // Condition mask for instructions.
153 // Starting at first 1 (from lsb).
154 // '1' condition as indicated in IT.
155 // '0' inverse of condition (else).
156 // Count of instructions in IT block is
157 // 4 - trailingzeroes(mask)
158
159 bool FirstCond; // Explicit flag for when we're parsing the
160 // First instruction in the IT block. It's
161 // implied in the mask, so needs special
162 // handling.
163
164 unsigned CurPosition; // Current position in parsing of IT
165 // block. In range [0,3]. Initialized
166 // according to count of instructions in block.
167 // ~0U if no active IT block.
168 } ITState;
169 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000170 void forwardITPosition() {
171 if (!inITBlock()) return;
172 // Move to the next instruction in the IT block, if there is one. If not,
173 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000174 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000175 if (++ITState.CurPosition == 5 - TZ)
176 ITState.CurPosition = ~0U; // Done with the IT block after this.
177 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000178
179
Kevin Enderbyccab3172009-09-15 00:27:25 +0000180 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000181 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
182
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000183 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
184 return Parser.Note(L, Msg, Ranges);
185 }
Benjamin Kramer673824b2012-04-15 17:04:27 +0000186 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000187 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000188 return Parser.Warning(L, Msg, Ranges);
189 }
190 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000191 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000192 return Parser.Error(L, Msg, Ranges);
193 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000194
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000195 int tryParseRegister();
196 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000197 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000198 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000199 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000200 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
201 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000202 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
203 unsigned &ShiftAmount);
Saleem Abdulrasool38976512014-02-23 06:22:09 +0000204 bool parseLiteralValues(unsigned Size, SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000205 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000206 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000207 bool parseDirectiveThumbFunc(SMLoc L);
208 bool parseDirectiveCode(SMLoc L);
209 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000210 bool parseDirectiveReq(StringRef Name, SMLoc L);
211 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000212 bool parseDirectiveArch(SMLoc L);
213 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000214 bool parseDirectiveCPU(SMLoc L);
215 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000216 bool parseDirectiveFnStart(SMLoc L);
217 bool parseDirectiveFnEnd(SMLoc L);
218 bool parseDirectiveCantUnwind(SMLoc L);
219 bool parseDirectivePersonality(SMLoc L);
220 bool parseDirectiveHandlerData(SMLoc L);
221 bool parseDirectiveSetFP(SMLoc L);
222 bool parseDirectivePad(SMLoc L);
223 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000224 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
David Peixotto80c083a2013-12-19 18:26:07 +0000225 bool parseDirectiveLtorg(SMLoc L);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +0000226 bool parseDirectiveEven(SMLoc L);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000227 bool parseDirectivePersonalityIndex(SMLoc L);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000228 bool parseDirectiveUnwindRaw(SMLoc L);
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000229 bool parseDirectiveTLSDescSeq(SMLoc L);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000230 bool parseDirectiveMovSP(SMLoc L);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000231 bool parseDirectiveObjectArch(SMLoc L);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +0000232 bool parseDirectiveArchExtension(SMLoc L);
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +0000233 bool parseDirectiveAlign(SMLoc L);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +0000234 bool parseDirectiveThumbSet(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000235
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000236 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000237 bool &CarrySetting, unsigned &ProcessorIMod,
238 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000239 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
240 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000241 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000242
Evan Cheng4d1ca962011-07-08 01:53:10 +0000243 bool isThumb() const {
244 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000245 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000246 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000247 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000248 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000249 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000250 bool isThumbTwo() const {
251 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
252 }
Tim Northovera2292d02013-06-10 23:20:58 +0000253 bool hasThumb() const {
254 return STI.getFeatureBits() & ARM::HasV4TOps;
255 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000256 bool hasV6Ops() const {
257 return STI.getFeatureBits() & ARM::HasV6Ops;
258 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000259 bool hasV6MOps() const {
260 return STI.getFeatureBits() & ARM::HasV6MOps;
261 }
James Molloy21efa7d2011-09-28 14:21:38 +0000262 bool hasV7Ops() const {
263 return STI.getFeatureBits() & ARM::HasV7Ops;
264 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000265 bool hasV8Ops() const {
266 return STI.getFeatureBits() & ARM::HasV8Ops;
267 }
Tim Northovera2292d02013-06-10 23:20:58 +0000268 bool hasARM() const {
269 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
270 }
271
Evan Cheng284b4672011-07-08 22:36:29 +0000272 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000273 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
274 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000275 }
James Molloy21efa7d2011-09-28 14:21:38 +0000276 bool isMClass() const {
277 return STI.getFeatureBits() & ARM::FeatureMClass;
278 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000279
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000280 /// @name Auto-generated Match Functions
281 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000282
Chris Lattner3e4582a2010-09-06 19:11:01 +0000283#define GET_ASSEMBLER_HEADER
284#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000285
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000286 /// }
287
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000288 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000289 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000290 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000291 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000292 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000293 OperandMatchResultTy parseCoprocOptionOperand(
294 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000295 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000296 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000297 OperandMatchResultTy parseInstSyncBarrierOptOperand(
298 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000299 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000300 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000301 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000302 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000303 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
304 StringRef Op, int Low, int High);
305 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
306 return parsePKHImm(O, "lsl", 0, 31);
307 }
308 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
309 return parsePKHImm(O, "asr", 1, 32);
310 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000311 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000312 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000313 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000314 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000315 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000316 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000317 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000318 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000319 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
320 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000321
322 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000323 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000324 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000325 void cvtThumbBranches(MCInst &Inst,
326 const SmallVectorImpl<MCParsedAsmOperand*> &);
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +0000327
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000328 bool validateInstruction(MCInst &Inst,
329 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000330 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000331 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000332 bool shouldOmitCCOutOperand(StringRef Mnemonic,
333 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000334 bool shouldOmitPredicateOperand(StringRef Mnemonic,
335 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000336public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000337 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000338 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000339 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000340 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000341 Match_RequiresThumb2,
342#define GET_OPERAND_DIAGNOSTIC_TYPES
343#include "ARMGenAsmMatcher.inc"
344
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000345 };
346
Joey Gouly0e76fa72013-09-12 10:28:05 +0000347 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
348 const MCInstrInfo &MII)
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000349 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), UC(_Parser) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000350 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000351
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000352 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000353 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000354
Evan Cheng4d1ca962011-07-08 01:53:10 +0000355 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000356 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000357
358 // Not in an ITBlock to start with.
359 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000360
361 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000362 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000363
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000364 // Implementation of the MCTargetAsmParser interface:
Craig Topperca7e3e52014-03-10 03:19:03 +0000365 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
366 bool
367 ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
368 SMLoc NameLoc,
369 SmallVectorImpl<MCParsedAsmOperand*> &Operands) override;
370 bool ParseDirective(AsmToken DirectiveID) override;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000371
Craig Topperca7e3e52014-03-10 03:19:03 +0000372 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op,
373 unsigned Kind) override;
374 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000375
Chad Rosier49963552012-10-13 00:26:04 +0000376 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000377 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000378 MCStreamer &Out, unsigned &ErrorInfo,
Craig Topperca7e3e52014-03-10 03:19:03 +0000379 bool MatchingInlineAsm) override;
380 void onLabelParsed(MCSymbol *Symbol) override;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000381};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000382} // end anonymous namespace
383
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000384namespace {
385
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000386/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000387/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000388class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000389 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000390 k_CondCode,
391 k_CCOut,
392 k_ITCondMask,
393 k_CoprocNum,
394 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000395 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000396 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000397 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000398 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000399 k_Memory,
400 k_PostIndexRegister,
401 k_MSRMask,
402 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000403 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000404 k_Register,
405 k_RegisterList,
406 k_DPRRegisterList,
407 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000408 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000409 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000410 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000411 k_ShiftedRegister,
412 k_ShiftedImmediate,
413 k_ShifterImmediate,
414 k_RotateImmediate,
415 k_BitfieldDescriptor,
416 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000417 } Kind;
418
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000419 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000420 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000421
Eric Christopher8996c5d2013-03-15 00:42:55 +0000422 struct CCOp {
423 ARMCC::CondCodes Val;
424 };
425
426 struct CopOp {
427 unsigned Val;
428 };
429
430 struct CoprocOptionOp {
431 unsigned Val;
432 };
433
434 struct ITMaskOp {
435 unsigned Mask:4;
436 };
437
438 struct MBOptOp {
439 ARM_MB::MemBOpt Val;
440 };
441
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000442 struct ISBOptOp {
443 ARM_ISB::InstSyncBOpt Val;
444 };
445
Eric Christopher8996c5d2013-03-15 00:42:55 +0000446 struct IFlagsOp {
447 ARM_PROC::IFlags Val;
448 };
449
450 struct MMaskOp {
451 unsigned Val;
452 };
453
454 struct TokOp {
455 const char *Data;
456 unsigned Length;
457 };
458
459 struct RegOp {
460 unsigned RegNum;
461 };
462
463 // A vector register list is a sequential list of 1 to 4 registers.
464 struct VectorListOp {
465 unsigned RegNum;
466 unsigned Count;
467 unsigned LaneIndex;
468 bool isDoubleSpaced;
469 };
470
471 struct VectorIndexOp {
472 unsigned Val;
473 };
474
475 struct ImmOp {
476 const MCExpr *Val;
477 };
478
479 /// Combined record for all forms of ARM address expressions.
480 struct MemoryOp {
481 unsigned BaseRegNum;
482 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
483 // was specified.
484 const MCConstantExpr *OffsetImm; // Offset immediate value
485 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
486 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
487 unsigned ShiftImm; // shift for OffsetReg.
488 unsigned Alignment; // 0 = no alignment specified
489 // n = alignment in bytes (2, 4, 8, 16, or 32)
490 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
491 };
492
493 struct PostIdxRegOp {
494 unsigned RegNum;
495 bool isAdd;
496 ARM_AM::ShiftOpc ShiftTy;
497 unsigned ShiftImm;
498 };
499
500 struct ShifterImmOp {
501 bool isASR;
502 unsigned Imm;
503 };
504
505 struct RegShiftedRegOp {
506 ARM_AM::ShiftOpc ShiftTy;
507 unsigned SrcReg;
508 unsigned ShiftReg;
509 unsigned ShiftImm;
510 };
511
512 struct RegShiftedImmOp {
513 ARM_AM::ShiftOpc ShiftTy;
514 unsigned SrcReg;
515 unsigned ShiftImm;
516 };
517
518 struct RotImmOp {
519 unsigned Imm;
520 };
521
522 struct BitfieldOp {
523 unsigned LSB;
524 unsigned Width;
525 };
526
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000527 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000528 struct CCOp CC;
529 struct CopOp Cop;
530 struct CoprocOptionOp CoprocOption;
531 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000532 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000533 struct ITMaskOp ITMask;
534 struct IFlagsOp IFlags;
535 struct MMaskOp MMask;
536 struct TokOp Tok;
537 struct RegOp Reg;
538 struct VectorListOp VectorList;
539 struct VectorIndexOp VectorIndex;
540 struct ImmOp Imm;
541 struct MemoryOp Memory;
542 struct PostIdxRegOp PostIdxReg;
543 struct ShifterImmOp ShifterImm;
544 struct RegShiftedRegOp RegShiftedReg;
545 struct RegShiftedImmOp RegShiftedImm;
546 struct RotImmOp RotImm;
547 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000548 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000549
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000550 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
551public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000552 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
553 Kind = o.Kind;
554 StartLoc = o.StartLoc;
555 EndLoc = o.EndLoc;
556 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000557 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000558 CC = o.CC;
559 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000560 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000561 ITMask = o.ITMask;
562 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000563 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000564 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000565 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000566 case k_CCOut:
567 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000568 Reg = o.Reg;
569 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000570 case k_RegisterList:
571 case k_DPRRegisterList:
572 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000573 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000574 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000575 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000576 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000577 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000578 VectorList = o.VectorList;
579 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000580 case k_CoprocNum:
581 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000582 Cop = o.Cop;
583 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000584 case k_CoprocOption:
585 CoprocOption = o.CoprocOption;
586 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000587 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000588 Imm = o.Imm;
589 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000590 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000591 MBOpt = o.MBOpt;
592 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000593 case k_InstSyncBarrierOpt:
594 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000595 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000596 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000597 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000598 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000599 PostIdxReg = o.PostIdxReg;
600 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000601 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000602 MMask = o.MMask;
603 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000604 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000605 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000606 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000607 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000608 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000609 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000610 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000611 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000612 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000613 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000614 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000615 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000616 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000617 RotImm = o.RotImm;
618 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000619 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000620 Bitfield = o.Bitfield;
621 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000622 case k_VectorIndex:
623 VectorIndex = o.VectorIndex;
624 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000625 }
626 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000627
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000628 /// getStartLoc - Get the location of the first token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000629 SMLoc getStartLoc() const override { return StartLoc; }
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000630 /// getEndLoc - Get the location of the last token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000631 SMLoc getEndLoc() const override { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000632 /// getLocRange - Get the range between the first and last token of this
633 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000634 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
635
Daniel Dunbard8042b72010-08-11 06:36:53 +0000636 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000637 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000638 return CC.Val;
639 }
640
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000641 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000642 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000643 return Cop.Val;
644 }
645
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000646 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000647 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000648 return StringRef(Tok.Data, Tok.Length);
649 }
650
Craig Topperca7e3e52014-03-10 03:19:03 +0000651 unsigned getReg() const override {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000652 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000653 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000654 }
655
Bill Wendlingbed94652010-11-09 23:28:44 +0000656 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000657 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
658 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000659 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000660 }
661
Kevin Enderbyf5079942009-10-13 22:19:02 +0000662 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000663 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000664 return Imm.Val;
665 }
666
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000667 unsigned getVectorIndex() const {
668 assert(Kind == k_VectorIndex && "Invalid access!");
669 return VectorIndex.Val;
670 }
671
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000672 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000673 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000674 return MBOpt.Val;
675 }
676
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000677 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
678 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
679 return ISBOpt.Val;
680 }
681
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000682 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000683 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000684 return IFlags.Val;
685 }
686
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000687 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000688 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000689 return MMask.Val;
690 }
691
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000692 bool isCoprocNum() const { return Kind == k_CoprocNum; }
693 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000694 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000695 bool isCondCode() const { return Kind == k_CondCode; }
696 bool isCCOut() const { return Kind == k_CCOut; }
697 bool isITMask() const { return Kind == k_ITCondMask; }
698 bool isITCondCode() const { return Kind == k_CondCode; }
Craig Topperca7e3e52014-03-10 03:19:03 +0000699 bool isImm() const override { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000700 // checks whether this operand is an unsigned offset which fits is a field
701 // of specified width and scaled by a specific number of bits
702 template<unsigned width, unsigned scale>
703 bool isUnsignedOffset() const {
704 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000705 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000706 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
707 int64_t Val = CE->getValue();
708 int64_t Align = 1LL << scale;
709 int64_t Max = Align * ((1LL << width) - 1);
710 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
711 }
712 return false;
713 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000714 // checks whether this operand is an signed offset which fits is a field
715 // of specified width and scaled by a specific number of bits
716 template<unsigned width, unsigned scale>
717 bool isSignedOffset() const {
718 if (!isImm()) return false;
719 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
720 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
721 int64_t Val = CE->getValue();
722 int64_t Align = 1LL << scale;
723 int64_t Max = Align * ((1LL << (width-1)) - 1);
724 int64_t Min = -Align * (1LL << (width-1));
725 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
726 }
727 return false;
728 }
729
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000730 // checks whether this operand is a memory operand computed as an offset
731 // applied to PC. the offset may have 8 bits of magnitude and is represented
732 // with two bits of shift. textually it may be either [pc, #imm], #imm or
733 // relocable expression...
734 bool isThumbMemPC() const {
735 int64_t Val = 0;
736 if (isImm()) {
737 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
739 if (!CE) return false;
740 Val = CE->getValue();
741 }
742 else if (isMem()) {
743 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
744 if(Memory.BaseRegNum != ARM::PC) return false;
745 Val = Memory.OffsetImm->getValue();
746 }
747 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000748 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000749 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000750 bool isFPImm() const {
751 if (!isImm()) return false;
752 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
753 if (!CE) return false;
754 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
755 return Val != -1;
756 }
Jim Grosbachea231912011-12-22 22:19:05 +0000757 bool isFBits16() const {
758 if (!isImm()) return false;
759 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
760 if (!CE) return false;
761 int64_t Value = CE->getValue();
762 return Value >= 0 && Value <= 16;
763 }
764 bool isFBits32() const {
765 if (!isImm()) return false;
766 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
767 if (!CE) return false;
768 int64_t Value = CE->getValue();
769 return Value >= 1 && Value <= 32;
770 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000771 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000772 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000773 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
774 if (!CE) return false;
775 int64_t Value = CE->getValue();
776 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
777 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000778 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000779 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000780 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
781 if (!CE) return false;
782 int64_t Value = CE->getValue();
783 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
784 }
785 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000786 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
788 if (!CE) return false;
789 int64_t Value = CE->getValue();
790 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
791 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000792 bool isImm0_508s4Neg() 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 // explicitly exclude zero. we want that to use the normal 0_508 version.
798 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
799 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000800 bool isImm0_239() const {
801 if (!isImm()) return false;
802 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
803 if (!CE) return false;
804 int64_t Value = CE->getValue();
805 return Value >= 0 && Value < 240;
806 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000807 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000808 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000809 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
810 if (!CE) return false;
811 int64_t Value = CE->getValue();
812 return Value >= 0 && Value < 256;
813 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000814 bool isImm0_4095() const {
815 if (!isImm()) return false;
816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
817 if (!CE) return false;
818 int64_t Value = CE->getValue();
819 return Value >= 0 && Value < 4096;
820 }
821 bool isImm0_4095Neg() const {
822 if (!isImm()) return false;
823 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
824 if (!CE) return false;
825 int64_t Value = -CE->getValue();
826 return Value > 0 && Value < 4096;
827 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000828 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000829 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
831 if (!CE) return false;
832 int64_t Value = CE->getValue();
833 return Value >= 0 && Value < 2;
834 }
835 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000836 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
838 if (!CE) return false;
839 int64_t Value = CE->getValue();
840 return Value >= 0 && Value < 4;
841 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000842 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000843 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
847 return Value >= 0 && Value < 8;
848 }
849 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000850 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
852 if (!CE) return false;
853 int64_t Value = CE->getValue();
854 return Value >= 0 && Value < 16;
855 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000856 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000857 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000858 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
859 if (!CE) return false;
860 int64_t Value = CE->getValue();
861 return Value >= 0 && Value < 32;
862 }
Jim Grosbach00326402011-12-08 01:30:04 +0000863 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000864 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
866 if (!CE) return false;
867 int64_t Value = CE->getValue();
868 return Value >= 0 && Value < 64;
869 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000870 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000871 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000872 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
873 if (!CE) return false;
874 int64_t Value = CE->getValue();
875 return Value == 8;
876 }
877 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000878 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000879 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
880 if (!CE) return false;
881 int64_t Value = CE->getValue();
882 return Value == 16;
883 }
884 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000885 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000886 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
887 if (!CE) return false;
888 int64_t Value = CE->getValue();
889 return Value == 32;
890 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000891 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000892 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000893 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
894 if (!CE) return false;
895 int64_t Value = CE->getValue();
896 return Value > 0 && Value <= 8;
897 }
898 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000899 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
901 if (!CE) return false;
902 int64_t Value = CE->getValue();
903 return Value > 0 && Value <= 16;
904 }
905 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000906 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
908 if (!CE) return false;
909 int64_t Value = CE->getValue();
910 return Value > 0 && Value <= 32;
911 }
912 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000913 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
915 if (!CE) return false;
916 int64_t Value = CE->getValue();
917 return Value > 0 && Value <= 64;
918 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000919 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000920 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000921 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
922 if (!CE) return false;
923 int64_t Value = CE->getValue();
924 return Value > 0 && Value < 8;
925 }
926 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000927 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000928 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
929 if (!CE) return false;
930 int64_t Value = CE->getValue();
931 return Value > 0 && Value < 16;
932 }
933 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000934 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
936 if (!CE) return false;
937 int64_t Value = CE->getValue();
938 return Value > 0 && Value < 32;
939 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000940 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000941 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000942 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
943 if (!CE) return false;
944 int64_t Value = CE->getValue();
945 return Value > 0 && Value < 17;
946 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000947 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000948 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000949 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
950 if (!CE) return false;
951 int64_t Value = CE->getValue();
952 return Value > 0 && Value < 33;
953 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000954 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000955 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000956 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
957 if (!CE) return false;
958 int64_t Value = CE->getValue();
959 return Value >= 0 && Value < 33;
960 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000961 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000962 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000963 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
964 if (!CE) return false;
965 int64_t Value = CE->getValue();
966 return Value >= 0 && Value < 65536;
967 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000968 bool isImm256_65535Expr() const {
969 if (!isImm()) return false;
970 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
971 // If it's not a constant expression, it'll generate a fixup and be
972 // handled later.
973 if (!CE) return true;
974 int64_t Value = CE->getValue();
975 return Value >= 256 && Value < 65536;
976 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000977 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000978 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000979 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
980 // If it's not a constant expression, it'll generate a fixup and be
981 // handled later.
982 if (!CE) return true;
983 int64_t Value = CE->getValue();
984 return Value >= 0 && Value < 65536;
985 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000986 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000987 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000988 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
989 if (!CE) return false;
990 int64_t Value = CE->getValue();
991 return Value >= 0 && Value <= 0xffffff;
992 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000993 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000994 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000995 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
996 if (!CE) return false;
997 int64_t Value = CE->getValue();
998 return Value > 0 && Value < 33;
999 }
Jim Grosbach27c1e252011-07-21 17:23:04 +00001000 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001001 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1003 if (!CE) return false;
1004 int64_t Value = CE->getValue();
1005 return Value >= 0 && Value < 32;
1006 }
1007 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001008 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001009 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1010 if (!CE) return false;
1011 int64_t Value = CE->getValue();
1012 return Value > 0 && Value <= 32;
1013 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001014 bool isAdrLabel() const {
1015 // If we have an immediate that's not a constant, treat it as a label
1016 // reference needing a fixup. If it is a constant, but it can't fit
1017 // into shift immediate encoding, we reject it.
1018 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1019 else return (isARMSOImm() || isARMSOImmNeg());
1020 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001021 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001022 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001023 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1024 if (!CE) return false;
1025 int64_t Value = CE->getValue();
1026 return ARM_AM::getSOImmVal(Value) != -1;
1027 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001028 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001029 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001030 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1031 if (!CE) return false;
1032 int64_t Value = CE->getValue();
1033 return ARM_AM::getSOImmVal(~Value) != -1;
1034 }
Jim Grosbach30506252011-12-08 00:31:07 +00001035 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001036 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001037 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1038 if (!CE) return false;
1039 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001040 // Only use this when not representable as a plain so_imm.
1041 return ARM_AM::getSOImmVal(Value) == -1 &&
1042 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001043 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001044 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001045 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001046 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1047 if (!CE) return false;
1048 int64_t Value = CE->getValue();
1049 return ARM_AM::getT2SOImmVal(Value) != -1;
1050 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001051 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001052 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001053 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1054 if (!CE) return false;
1055 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001056 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1057 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001058 }
Jim Grosbach30506252011-12-08 00:31:07 +00001059 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001060 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001061 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1062 if (!CE) return false;
1063 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001064 // Only use this when not representable as a plain so_imm.
1065 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1066 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001067 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001068 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001069 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001070 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1071 if (!CE) return false;
1072 int64_t Value = CE->getValue();
1073 return Value == 1 || Value == 0;
1074 }
Craig Topperca7e3e52014-03-10 03:19:03 +00001075 bool isReg() const override { return Kind == k_Register; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001076 bool isRegList() const { return Kind == k_RegisterList; }
1077 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1078 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001079 bool isToken() const override { return Kind == k_Token; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001080 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001081 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001082 bool isMem() const override { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001083 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1084 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1085 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1086 bool isRotImm() const { return Kind == k_RotateImmediate; }
1087 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1088 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001089 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001090 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001091 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001092 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +00001093 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001094 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001095 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +00001096 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1097 (alignOK || Memory.Alignment == 0);
1098 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001099 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001100 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001101 return false;
1102 // Base register must be PC.
1103 if (Memory.BaseRegNum != ARM::PC)
1104 return false;
1105 // Immediate offset in range [-4095, 4095].
1106 if (!Memory.OffsetImm) return true;
1107 int64_t Val = Memory.OffsetImm->getValue();
1108 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1109 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001110 bool isAlignedMemory() const {
1111 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001112 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001113 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001114 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001115 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001116 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001117 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001118 if (!Memory.OffsetImm) return true;
1119 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001120 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001121 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001122 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001123 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001124 // Immediate offset in range [-4095, 4095].
1125 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1126 if (!CE) return false;
1127 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001128 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001129 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001130 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001131 // If we have an immediate that's not a constant, treat it as a label
1132 // reference needing a fixup. If it is a constant, it's something else
1133 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001134 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001135 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001136 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001137 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001138 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001139 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001140 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001141 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001142 if (!Memory.OffsetImm) return true;
1143 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001144 // The #-0 offset is encoded as INT32_MIN, and we have to check
1145 // for this too.
1146 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001147 }
1148 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001149 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001150 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001151 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001152 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1153 // Immediate offset in range [-255, 255].
1154 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1155 if (!CE) return false;
1156 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001157 // Special case, #-0 is INT32_MIN.
1158 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001159 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001160 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001161 // If we have an immediate that's not a constant, treat it as a label
1162 // reference needing a fixup. If it is a constant, it's something else
1163 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001164 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001165 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001166 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001167 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001168 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001169 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001170 if (!Memory.OffsetImm) return true;
1171 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001172 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001173 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001174 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001175 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001176 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001177 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001178 return false;
1179 return true;
1180 }
1181 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001182 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001183 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1184 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001185 return false;
1186 return true;
1187 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001188 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001189 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001190 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001191 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001192 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001193 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001194 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001195 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001196 return false;
1197 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001198 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001199 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001200 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001201 return false;
1202 return true;
1203 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001204 bool isMemThumbRR() const {
1205 // Thumb reg+reg addressing is simple. Just two registers, a base and
1206 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001207 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001208 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001209 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001210 return isARMLowRegister(Memory.BaseRegNum) &&
1211 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001212 }
1213 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001214 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001215 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001216 return false;
1217 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001218 if (!Memory.OffsetImm) return true;
1219 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001220 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1221 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001222 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001223 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001224 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001225 return false;
1226 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001227 if (!Memory.OffsetImm) return true;
1228 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001229 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1230 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001231 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001232 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001233 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001234 return false;
1235 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001236 if (!Memory.OffsetImm) return true;
1237 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001238 return Val >= 0 && Val <= 31;
1239 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001240 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001241 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001242 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001243 return false;
1244 // Immediate offset, 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 Grosbach23983d62011-08-19 18:13:48 +00001247 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001248 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001249 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001250 // If we have an immediate that's not a constant, treat it as a label
1251 // reference needing a fixup. If it is a constant, it's something else
1252 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001253 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001254 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001255 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001256 return false;
1257 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001258 if (!Memory.OffsetImm) return true;
1259 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001260 // Special case, #-0 is INT32_MIN.
1261 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001262 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001263 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001264 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001265 return false;
1266 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001267 if (!Memory.OffsetImm) return true;
1268 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001269 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1270 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001271 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001272 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001273 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001274 // Base reg of PC isn't allowed for these encodings.
1275 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001276 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001277 if (!Memory.OffsetImm) return true;
1278 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001279 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001280 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001281 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001282 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001283 return false;
1284 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001285 if (!Memory.OffsetImm) return true;
1286 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001287 return Val >= 0 && Val < 256;
1288 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001289 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001290 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001291 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001292 // Base reg of PC isn't allowed for these encodings.
1293 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001294 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001295 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001296 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001297 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001298 }
1299 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001300 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001301 return false;
1302 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001303 if (!Memory.OffsetImm) return true;
1304 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001305 return (Val >= 0 && Val < 4096);
1306 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001307 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001308 // If we have an immediate that's not a constant, treat it as a label
1309 // reference needing a fixup. If it is a constant, it's something else
1310 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001311 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001312 return true;
1313
Chad Rosier41099832012-09-11 23:02:35 +00001314 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001315 return false;
1316 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001317 if (!Memory.OffsetImm) return true;
1318 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001319 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001320 }
1321 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001322 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001323 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1324 if (!CE) return false;
1325 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001326 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001327 }
Jim Grosbach93981412011-10-11 21:55:36 +00001328 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001329 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001330 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1331 if (!CE) return false;
1332 int64_t Val = CE->getValue();
1333 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1334 (Val == INT32_MIN);
1335 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001336
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001337 bool isMSRMask() const { return Kind == k_MSRMask; }
1338 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001339
Jim Grosbach741cd732011-10-17 22:26:03 +00001340 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001341 bool isSingleSpacedVectorList() const {
1342 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1343 }
1344 bool isDoubleSpacedVectorList() const {
1345 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1346 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001347 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001348 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001349 return VectorList.Count == 1;
1350 }
1351
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001352 bool isVecListDPair() const {
1353 if (!isSingleSpacedVectorList()) return false;
1354 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1355 .contains(VectorList.RegNum));
1356 }
1357
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001358 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001359 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001360 return VectorList.Count == 3;
1361 }
1362
Jim Grosbach846bcff2011-10-21 20:35:01 +00001363 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001364 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001365 return VectorList.Count == 4;
1366 }
1367
Jim Grosbache5307f92012-03-05 21:43:40 +00001368 bool isVecListDPairSpaced() const {
Kevin Enderby56113982014-03-26 21:54:11 +00001369 if (Kind != k_VectorList) return false;
Kevin Enderby816ca272012-03-20 17:41:51 +00001370 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001371 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1372 .contains(VectorList.RegNum));
1373 }
1374
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001375 bool isVecListThreeQ() const {
1376 if (!isDoubleSpacedVectorList()) return false;
1377 return VectorList.Count == 3;
1378 }
1379
Jim Grosbach1e946a42012-01-24 00:43:12 +00001380 bool isVecListFourQ() const {
1381 if (!isDoubleSpacedVectorList()) return false;
1382 return VectorList.Count == 4;
1383 }
1384
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001385 bool isSingleSpacedVectorAllLanes() const {
1386 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1387 }
1388 bool isDoubleSpacedVectorAllLanes() const {
1389 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1390 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001391 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001392 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001393 return VectorList.Count == 1;
1394 }
1395
Jim Grosbach13a292c2012-03-06 22:01:44 +00001396 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001397 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001398 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1399 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001400 }
1401
Jim Grosbached428bc2012-03-06 23:10:38 +00001402 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001403 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001404 return VectorList.Count == 2;
1405 }
1406
Jim Grosbachb78403c2012-01-24 23:47:04 +00001407 bool isVecListThreeDAllLanes() const {
1408 if (!isSingleSpacedVectorAllLanes()) return false;
1409 return VectorList.Count == 3;
1410 }
1411
1412 bool isVecListThreeQAllLanes() const {
1413 if (!isDoubleSpacedVectorAllLanes()) return false;
1414 return VectorList.Count == 3;
1415 }
1416
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001417 bool isVecListFourDAllLanes() const {
1418 if (!isSingleSpacedVectorAllLanes()) return false;
1419 return VectorList.Count == 4;
1420 }
1421
1422 bool isVecListFourQAllLanes() const {
1423 if (!isDoubleSpacedVectorAllLanes()) return false;
1424 return VectorList.Count == 4;
1425 }
1426
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001427 bool isSingleSpacedVectorIndexed() const {
1428 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1429 }
1430 bool isDoubleSpacedVectorIndexed() const {
1431 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1432 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001433 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001434 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001435 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1436 }
1437
Jim Grosbachda511042011-12-14 23:35:06 +00001438 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001439 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001440 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1441 }
1442
1443 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001444 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001445 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1446 }
1447
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001448 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001449 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001450 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1451 }
1452
Jim Grosbachda511042011-12-14 23:35:06 +00001453 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001454 if (!isSingleSpacedVectorIndexed()) return false;
1455 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1456 }
1457
1458 bool isVecListTwoQWordIndexed() const {
1459 if (!isDoubleSpacedVectorIndexed()) return false;
1460 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1461 }
1462
1463 bool isVecListTwoQHWordIndexed() const {
1464 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001465 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1466 }
1467
1468 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001469 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001470 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1471 }
1472
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001473 bool isVecListThreeDByteIndexed() const {
1474 if (!isSingleSpacedVectorIndexed()) return false;
1475 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1476 }
1477
1478 bool isVecListThreeDHWordIndexed() const {
1479 if (!isSingleSpacedVectorIndexed()) return false;
1480 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1481 }
1482
1483 bool isVecListThreeQWordIndexed() const {
1484 if (!isDoubleSpacedVectorIndexed()) return false;
1485 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1486 }
1487
1488 bool isVecListThreeQHWordIndexed() const {
1489 if (!isDoubleSpacedVectorIndexed()) return false;
1490 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1491 }
1492
1493 bool isVecListThreeDWordIndexed() const {
1494 if (!isSingleSpacedVectorIndexed()) return false;
1495 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1496 }
1497
Jim Grosbach14952a02012-01-24 18:37:25 +00001498 bool isVecListFourDByteIndexed() const {
1499 if (!isSingleSpacedVectorIndexed()) return false;
1500 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1501 }
1502
1503 bool isVecListFourDHWordIndexed() const {
1504 if (!isSingleSpacedVectorIndexed()) return false;
1505 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1506 }
1507
1508 bool isVecListFourQWordIndexed() const {
1509 if (!isDoubleSpacedVectorIndexed()) return false;
1510 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1511 }
1512
1513 bool isVecListFourQHWordIndexed() const {
1514 if (!isDoubleSpacedVectorIndexed()) return false;
1515 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1516 }
1517
1518 bool isVecListFourDWordIndexed() const {
1519 if (!isSingleSpacedVectorIndexed()) return false;
1520 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1521 }
1522
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001523 bool isVectorIndex8() const {
1524 if (Kind != k_VectorIndex) return false;
1525 return VectorIndex.Val < 8;
1526 }
1527 bool isVectorIndex16() const {
1528 if (Kind != k_VectorIndex) return false;
1529 return VectorIndex.Val < 4;
1530 }
1531 bool isVectorIndex32() const {
1532 if (Kind != k_VectorIndex) return false;
1533 return VectorIndex.Val < 2;
1534 }
1535
Jim Grosbach741cd732011-10-17 22:26:03 +00001536 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001537 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001538 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1539 // Must be a constant.
1540 if (!CE) return false;
1541 int64_t Value = CE->getValue();
1542 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1543 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001544 return Value >= 0 && Value < 256;
1545 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001546
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001547 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001548 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +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 // i16 value in the range [0,255] or [0x0100, 0xff00]
1554 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1555 }
1556
Jim Grosbach8211c052011-10-18 00:22:00 +00001557 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001558 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001559 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1560 // Must be a constant.
1561 if (!CE) return false;
1562 int64_t Value = CE->getValue();
1563 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1564 return (Value >= 0 && Value < 256) ||
1565 (Value >= 0x0100 && Value <= 0xff00) ||
1566 (Value >= 0x010000 && Value <= 0xff0000) ||
1567 (Value >= 0x01000000 && Value <= 0xff000000);
1568 }
1569
1570 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001571 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001572 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1573 // Must be a constant.
1574 if (!CE) return false;
1575 int64_t Value = CE->getValue();
1576 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1577 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1578 return (Value >= 0 && Value < 256) ||
1579 (Value >= 0x0100 && Value <= 0xff00) ||
1580 (Value >= 0x010000 && Value <= 0xff0000) ||
1581 (Value >= 0x01000000 && Value <= 0xff000000) ||
1582 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1583 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1584 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001585 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001586 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1588 // Must be a constant.
1589 if (!CE) return false;
1590 int64_t Value = ~CE->getValue();
1591 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1592 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1593 return (Value >= 0 && Value < 256) ||
1594 (Value >= 0x0100 && Value <= 0xff00) ||
1595 (Value >= 0x010000 && Value <= 0xff0000) ||
1596 (Value >= 0x01000000 && Value <= 0xff000000) ||
1597 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1598 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1599 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001600
Jim Grosbache4454e02011-10-18 16:18:11 +00001601 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001602 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1604 // Must be a constant.
1605 if (!CE) return false;
1606 uint64_t Value = CE->getValue();
1607 // i64 value with each byte being either 0 or 0xff.
1608 for (unsigned i = 0; i < 8; ++i)
1609 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1610 return true;
1611 }
1612
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001613 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001614 // Add as immediates when possible. Null MCExpr = 0.
1615 if (Expr == 0)
1616 Inst.addOperand(MCOperand::CreateImm(0));
1617 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001618 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1619 else
1620 Inst.addOperand(MCOperand::CreateExpr(Expr));
1621 }
1622
Daniel Dunbard8042b72010-08-11 06:36:53 +00001623 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001624 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001625 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001626 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1627 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001628 }
1629
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001630 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1631 assert(N == 1 && "Invalid number of operands!");
1632 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1633 }
1634
Jim Grosbach48399582011-10-12 17:34:41 +00001635 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
1637 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1638 }
1639
1640 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1641 assert(N == 1 && "Invalid number of operands!");
1642 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1643 }
1644
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001645 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
1647 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1648 }
1649
1650 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1653 }
1654
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001655 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1656 assert(N == 1 && "Invalid number of operands!");
1657 Inst.addOperand(MCOperand::CreateReg(getReg()));
1658 }
1659
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001660 void addRegOperands(MCInst &Inst, unsigned N) const {
1661 assert(N == 1 && "Invalid number of operands!");
1662 Inst.addOperand(MCOperand::CreateReg(getReg()));
1663 }
1664
Jim Grosbachac798e12011-07-25 20:49:51 +00001665 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001666 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001667 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001668 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001669 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1670 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001671 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001672 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001673 }
1674
Jim Grosbachac798e12011-07-25 20:49:51 +00001675 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001676 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001677 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001678 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001679 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001680 // Shift of #32 is encoded as 0 where permitted
1681 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001682 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001683 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001684 }
1685
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001686 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001687 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001688 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1689 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001690 }
1691
Bill Wendling8d2aa032010-11-08 23:49:57 +00001692 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001693 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001694 const SmallVectorImpl<unsigned> &RegList = getRegList();
1695 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001696 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1697 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001698 }
1699
Bill Wendling9898ac92010-11-17 04:32:08 +00001700 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1701 addRegListOperands(Inst, N);
1702 }
1703
1704 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1705 addRegListOperands(Inst, N);
1706 }
1707
Jim Grosbach833b9d32011-07-27 20:15:40 +00001708 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1709 assert(N == 1 && "Invalid number of operands!");
1710 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1711 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1712 }
1713
Jim Grosbach864b6092011-07-28 21:34:26 +00001714 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1715 assert(N == 1 && "Invalid number of operands!");
1716 // Munge the lsb/width into a bitfield mask.
1717 unsigned lsb = Bitfield.LSB;
1718 unsigned width = Bitfield.Width;
1719 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1720 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1721 (32 - (lsb + width)));
1722 Inst.addOperand(MCOperand::CreateImm(Mask));
1723 }
1724
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001725 void addImmOperands(MCInst &Inst, unsigned N) const {
1726 assert(N == 1 && "Invalid number of operands!");
1727 addExpr(Inst, getImm());
1728 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001729
Jim Grosbachea231912011-12-22 22:19:05 +00001730 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1731 assert(N == 1 && "Invalid number of operands!");
1732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1733 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1734 }
1735
1736 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1737 assert(N == 1 && "Invalid number of operands!");
1738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1739 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1740 }
1741
Jim Grosbache7fbce72011-10-03 23:38:36 +00001742 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1743 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001744 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1745 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1746 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001747 }
1748
Jim Grosbach7db8d692011-09-08 22:07:06 +00001749 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1750 assert(N == 1 && "Invalid number of operands!");
1751 // FIXME: We really want to scale the value here, but the LDRD/STRD
1752 // instruction don't encode operands that way yet.
1753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1754 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1755 }
1756
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001757 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1758 assert(N == 1 && "Invalid number of operands!");
1759 // The immediate is scaled by four in the encoding and is stored
1760 // in the MCInst as such. Lop off the low two bits here.
1761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1762 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1763 }
1764
Jim Grosbach930f2f62012-04-05 20:57:13 +00001765 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1766 assert(N == 1 && "Invalid number of operands!");
1767 // The immediate is scaled by four in the encoding and is stored
1768 // in the MCInst as such. Lop off the low two bits here.
1769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1770 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1771 }
1772
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001773 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1774 assert(N == 1 && "Invalid number of operands!");
1775 // The immediate is scaled by four in the encoding and is stored
1776 // in the MCInst as such. Lop off the low two bits here.
1777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1778 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1779 }
1780
Jim Grosbach475c6db2011-07-25 23:09:14 +00001781 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1782 assert(N == 1 && "Invalid number of operands!");
1783 // The constant encodes as the immediate-1, and we store in the instruction
1784 // the bits as encoded, so subtract off one here.
1785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1786 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1787 }
1788
Jim Grosbach801e0a32011-07-22 23:16:18 +00001789 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1790 assert(N == 1 && "Invalid number of operands!");
1791 // The constant encodes as the immediate-1, and we store in the instruction
1792 // the bits as encoded, so subtract off one here.
1793 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1794 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1795 }
1796
Jim Grosbach46dd4132011-08-17 21:51:27 +00001797 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1798 assert(N == 1 && "Invalid number of operands!");
1799 // The constant encodes as the immediate, except for 32, which encodes as
1800 // zero.
1801 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1802 unsigned Imm = CE->getValue();
1803 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1804 }
1805
Jim Grosbach27c1e252011-07-21 17:23:04 +00001806 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1807 assert(N == 1 && "Invalid number of operands!");
1808 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1809 // the instruction as well.
1810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1811 int Val = CE->getValue();
1812 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1813 }
1814
Jim Grosbachb009a872011-10-28 22:36:30 +00001815 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1816 assert(N == 1 && "Invalid number of operands!");
1817 // The operand is actually a t2_so_imm, but we have its bitwise
1818 // negation in the assembly source, so twiddle it here.
1819 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1820 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1821 }
1822
Jim Grosbach30506252011-12-08 00:31:07 +00001823 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1824 assert(N == 1 && "Invalid number of operands!");
1825 // The operand is actually a t2_so_imm, but we have its
1826 // negation in the assembly source, so twiddle it here.
1827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1828 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1829 }
1830
Jim Grosbach930f2f62012-04-05 20:57:13 +00001831 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1832 assert(N == 1 && "Invalid number of operands!");
1833 // The operand is actually an imm0_4095, but we have its
1834 // negation in the assembly source, so twiddle it here.
1835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1836 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1837 }
1838
Mihai Popad36cbaa2013-07-03 09:21:44 +00001839 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1840 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1841 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1842 return;
1843 }
1844
1845 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1846 assert(SR && "Unknown value type!");
1847 Inst.addOperand(MCOperand::CreateExpr(SR));
1848 }
1849
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001850 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1851 assert(N == 1 && "Invalid number of operands!");
1852 if (isImm()) {
1853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1854 if (CE) {
1855 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1856 return;
1857 }
1858
1859 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1860 assert(SR && "Unknown value type!");
1861 Inst.addOperand(MCOperand::CreateExpr(SR));
1862 return;
1863 }
1864
1865 assert(isMem() && "Unknown value type!");
1866 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1867 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1868 }
1869
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001870 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1871 assert(N == 1 && "Invalid number of operands!");
1872 // The operand is actually a so_imm, but we have its bitwise
1873 // negation in the assembly source, so twiddle it here.
1874 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1875 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1876 }
1877
Jim Grosbach30506252011-12-08 00:31:07 +00001878 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1879 assert(N == 1 && "Invalid number of operands!");
1880 // The operand is actually a so_imm, but we have its
1881 // negation in the assembly source, so twiddle it here.
1882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1883 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1884 }
1885
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001886 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1887 assert(N == 1 && "Invalid number of operands!");
1888 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1889 }
1890
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001891 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1892 assert(N == 1 && "Invalid number of operands!");
1893 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1894 }
1895
Jim Grosbachd3595712011-08-03 23:50:40 +00001896 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1897 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001898 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001899 }
1900
Jim Grosbach94298a92012-01-18 22:46:46 +00001901 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1902 assert(N == 1 && "Invalid number of operands!");
1903 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001904 Inst.addOperand(MCOperand::CreateImm(Imm));
1905 }
1906
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001907 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1908 assert(N == 1 && "Invalid number of operands!");
1909 assert(isImm() && "Not an immediate!");
1910
1911 // If we have an immediate that's not a constant, treat it as a label
1912 // reference needing a fixup.
1913 if (!isa<MCConstantExpr>(getImm())) {
1914 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1915 return;
1916 }
1917
1918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1919 int Val = CE->getValue();
1920 Inst.addOperand(MCOperand::CreateImm(Val));
1921 }
1922
Jim Grosbacha95ec992011-10-11 17:29:55 +00001923 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1924 assert(N == 2 && "Invalid number of operands!");
1925 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1926 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1927 }
1928
Jim Grosbachd3595712011-08-03 23:50:40 +00001929 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1930 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001931 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1932 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001933 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1934 // Special case for #-0
1935 if (Val == INT32_MIN) Val = 0;
1936 if (Val < 0) Val = -Val;
1937 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1938 } else {
1939 // For register offset, we encode the shift type and negation flag
1940 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001941 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1942 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001943 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001944 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1945 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001946 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001947 }
1948
Jim Grosbachcd17c122011-08-04 23:01:30 +00001949 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1950 assert(N == 2 && "Invalid number of operands!");
1951 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1952 assert(CE && "non-constant AM2OffsetImm operand!");
1953 int32_t Val = CE->getValue();
1954 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::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1959 Inst.addOperand(MCOperand::CreateReg(0));
1960 Inst.addOperand(MCOperand::CreateImm(Val));
1961 }
1962
Jim Grosbach5b96b802011-08-10 20:29:19 +00001963 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1964 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001965 // If we have an immediate that's not a constant, treat it as a label
1966 // reference needing a fixup. If it is a constant, it's something else
1967 // and we reject it.
1968 if (isImm()) {
1969 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1970 Inst.addOperand(MCOperand::CreateReg(0));
1971 Inst.addOperand(MCOperand::CreateImm(0));
1972 return;
1973 }
1974
Jim Grosbach871dff72011-10-11 15:59:20 +00001975 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1976 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001977 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1978 // Special case for #-0
1979 if (Val == INT32_MIN) Val = 0;
1980 if (Val < 0) Val = -Val;
1981 Val = ARM_AM::getAM3Opc(AddSub, Val);
1982 } else {
1983 // For register offset, we encode the shift type and negation flag
1984 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001985 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001986 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001987 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1988 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001989 Inst.addOperand(MCOperand::CreateImm(Val));
1990 }
1991
1992 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1993 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001994 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001995 int32_t Val =
1996 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1997 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1998 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001999 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00002000 }
2001
2002 // Constant offset.
2003 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2004 int32_t Val = CE->getValue();
2005 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2006 // Special case for #-0
2007 if (Val == INT32_MIN) Val = 0;
2008 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002009 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002010 Inst.addOperand(MCOperand::CreateReg(0));
2011 Inst.addOperand(MCOperand::CreateImm(Val));
2012 }
2013
Jim Grosbachd3595712011-08-03 23:50:40 +00002014 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2015 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002016 // If we have an immediate that's not a constant, treat it as a label
2017 // reference needing a fixup. If it is a constant, it's something else
2018 // and we reject it.
2019 if (isImm()) {
2020 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2021 Inst.addOperand(MCOperand::CreateImm(0));
2022 return;
2023 }
2024
Jim Grosbachd3595712011-08-03 23:50:40 +00002025 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002026 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002027 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2028 // Special case for #-0
2029 if (Val == INT32_MIN) Val = 0;
2030 if (Val < 0) Val = -Val;
2031 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002032 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002033 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002034 }
2035
Jim Grosbach7db8d692011-09-08 22:07:06 +00002036 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2037 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002038 // If we have an immediate that's not a constant, treat it as a label
2039 // reference needing a fixup. If it is a constant, it's something else
2040 // and we reject it.
2041 if (isImm()) {
2042 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2043 Inst.addOperand(MCOperand::CreateImm(0));
2044 return;
2045 }
2046
Jim Grosbach871dff72011-10-11 15:59:20 +00002047 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2048 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002049 Inst.addOperand(MCOperand::CreateImm(Val));
2050 }
2051
Jim Grosbacha05627e2011-09-09 18:37:27 +00002052 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 2 && "Invalid number of operands!");
2054 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002055 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2056 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002057 Inst.addOperand(MCOperand::CreateImm(Val));
2058 }
2059
Jim Grosbachd3595712011-08-03 23:50:40 +00002060 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2061 assert(N == 2 && "Invalid number of operands!");
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 Grosbachd3595712011-08-03 23:50:40 +00002064 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002065 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002066
Jim Grosbach2392c532011-09-07 23:39:14 +00002067 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2068 addMemImm8OffsetOperands(Inst, N);
2069 }
2070
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002071 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002072 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002073 }
2074
2075 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2076 assert(N == 2 && "Invalid number of operands!");
2077 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002078 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002079 addExpr(Inst, getImm());
2080 Inst.addOperand(MCOperand::CreateImm(0));
2081 return;
2082 }
2083
2084 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002085 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2086 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002087 Inst.addOperand(MCOperand::CreateImm(Val));
2088 }
2089
Jim Grosbachd3595712011-08-03 23:50:40 +00002090 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2091 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002092 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002093 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002094 addExpr(Inst, getImm());
2095 Inst.addOperand(MCOperand::CreateImm(0));
2096 return;
2097 }
2098
2099 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002100 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2101 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002102 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002103 }
Bill Wendling811c9362010-11-30 07:44:32 +00002104
Jim Grosbach05541f42011-09-19 22:21:13 +00002105 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2106 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002107 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2108 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002109 }
2110
2111 void addMemTBHOperands(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 Grosbach05541f42011-09-19 22:21:13 +00002115 }
2116
Jim Grosbachd3595712011-08-03 23:50:40 +00002117 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2118 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002119 unsigned Val =
2120 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2121 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002122 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2123 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002124 Inst.addOperand(MCOperand::CreateImm(Val));
2125 }
2126
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002127 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2128 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002129 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2130 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2131 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002132 }
2133
Jim Grosbachd3595712011-08-03 23:50:40 +00002134 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2135 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002136 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2137 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002138 }
2139
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002140 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2141 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002142 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2143 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002144 Inst.addOperand(MCOperand::CreateImm(Val));
2145 }
2146
Jim Grosbach26d35872011-08-19 18:55:51 +00002147 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2148 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002149 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2150 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002151 Inst.addOperand(MCOperand::CreateImm(Val));
2152 }
2153
Jim Grosbacha32c7532011-08-19 18:49:59 +00002154 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2155 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002156 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2157 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002158 Inst.addOperand(MCOperand::CreateImm(Val));
2159 }
2160
Jim Grosbach23983d62011-08-19 18:13:48 +00002161 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2162 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002163 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2164 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002165 Inst.addOperand(MCOperand::CreateImm(Val));
2166 }
2167
Jim Grosbachd3595712011-08-03 23:50:40 +00002168 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2169 assert(N == 1 && "Invalid number of operands!");
2170 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2171 assert(CE && "non-constant post-idx-imm8 operand!");
2172 int Imm = CE->getValue();
2173 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002174 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002175 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2176 Inst.addOperand(MCOperand::CreateImm(Imm));
2177 }
2178
Jim Grosbach93981412011-10-11 21:55:36 +00002179 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2180 assert(N == 1 && "Invalid number of operands!");
2181 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2182 assert(CE && "non-constant post-idx-imm8s4 operand!");
2183 int Imm = CE->getValue();
2184 bool isAdd = Imm >= 0;
2185 if (Imm == INT32_MIN) Imm = 0;
2186 // Immediate is scaled by 4.
2187 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2188 Inst.addOperand(MCOperand::CreateImm(Imm));
2189 }
2190
Jim Grosbachd3595712011-08-03 23:50:40 +00002191 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2192 assert(N == 2 && "Invalid number of operands!");
2193 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002194 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2195 }
2196
2197 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2198 assert(N == 2 && "Invalid number of operands!");
2199 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2200 // The sign, shift type, and shift amount are encoded in a single operand
2201 // using the AM2 encoding helpers.
2202 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2203 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2204 PostIdxReg.ShiftTy);
2205 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002206 }
2207
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002208 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2209 assert(N == 1 && "Invalid number of operands!");
2210 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2211 }
2212
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002213 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2214 assert(N == 1 && "Invalid number of operands!");
2215 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2216 }
2217
Jim Grosbach182b6a02011-11-29 23:51:09 +00002218 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002219 assert(N == 1 && "Invalid number of operands!");
2220 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2221 }
2222
Jim Grosbach04945c42011-12-02 00:35:16 +00002223 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2224 assert(N == 2 && "Invalid number of operands!");
2225 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2226 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2227 }
2228
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002229 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2230 assert(N == 1 && "Invalid number of operands!");
2231 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2232 }
2233
2234 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2235 assert(N == 1 && "Invalid number of operands!");
2236 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2237 }
2238
2239 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2240 assert(N == 1 && "Invalid number of operands!");
2241 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2242 }
2243
Jim Grosbach741cd732011-10-17 22:26:03 +00002244 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2245 assert(N == 1 && "Invalid number of operands!");
2246 // The immediate encodes the type of constant as well as the value.
2247 // Mask in that this is an i8 splat.
2248 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2249 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2250 }
2251
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002252 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2253 assert(N == 1 && "Invalid number of operands!");
2254 // The immediate encodes the type of constant as well as the value.
2255 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2256 unsigned Value = CE->getValue();
2257 if (Value >= 256)
2258 Value = (Value >> 8) | 0xa00;
2259 else
2260 Value |= 0x800;
2261 Inst.addOperand(MCOperand::CreateImm(Value));
2262 }
2263
Jim Grosbach8211c052011-10-18 00:22:00 +00002264 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2265 assert(N == 1 && "Invalid number of operands!");
2266 // The immediate encodes the type of constant as well as the value.
2267 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2268 unsigned Value = CE->getValue();
2269 if (Value >= 256 && Value <= 0xff00)
2270 Value = (Value >> 8) | 0x200;
2271 else if (Value > 0xffff && Value <= 0xff0000)
2272 Value = (Value >> 16) | 0x400;
2273 else if (Value > 0xffffff)
2274 Value = (Value >> 24) | 0x600;
2275 Inst.addOperand(MCOperand::CreateImm(Value));
2276 }
2277
2278 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2279 assert(N == 1 && "Invalid number of operands!");
2280 // The immediate encodes the type of constant as well as the value.
2281 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2282 unsigned Value = CE->getValue();
2283 if (Value >= 256 && Value <= 0xffff)
2284 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2285 else if (Value > 0xffff && Value <= 0xffffff)
2286 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2287 else if (Value > 0xffffff)
2288 Value = (Value >> 24) | 0x600;
2289 Inst.addOperand(MCOperand::CreateImm(Value));
2290 }
2291
Jim Grosbach045b6c72011-12-19 23:51:07 +00002292 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2293 assert(N == 1 && "Invalid number of operands!");
2294 // The immediate encodes the type of constant as well as the value.
2295 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2296 unsigned Value = ~CE->getValue();
2297 if (Value >= 256 && Value <= 0xffff)
2298 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2299 else if (Value > 0xffff && Value <= 0xffffff)
2300 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2301 else if (Value > 0xffffff)
2302 Value = (Value >> 24) | 0x600;
2303 Inst.addOperand(MCOperand::CreateImm(Value));
2304 }
2305
Jim Grosbache4454e02011-10-18 16:18:11 +00002306 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2307 assert(N == 1 && "Invalid number of operands!");
2308 // The immediate encodes the type of constant as well as the value.
2309 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2310 uint64_t Value = CE->getValue();
2311 unsigned Imm = 0;
2312 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2313 Imm |= (Value & 1) << i;
2314 }
2315 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2316 }
2317
Craig Topperca7e3e52014-03-10 03:19:03 +00002318 void print(raw_ostream &OS) const override;
Daniel Dunbarebace222010-08-11 06:37:04 +00002319
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002320 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002321 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002322 Op->ITMask.Mask = Mask;
2323 Op->StartLoc = S;
2324 Op->EndLoc = S;
2325 return Op;
2326 }
2327
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002328 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002329 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002330 Op->CC.Val = CC;
2331 Op->StartLoc = S;
2332 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002333 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002334 }
2335
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002336 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002337 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002338 Op->Cop.Val = CopVal;
2339 Op->StartLoc = S;
2340 Op->EndLoc = S;
2341 return Op;
2342 }
2343
2344 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002345 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002346 Op->Cop.Val = CopVal;
2347 Op->StartLoc = S;
2348 Op->EndLoc = S;
2349 return Op;
2350 }
2351
Jim Grosbach48399582011-10-12 17:34:41 +00002352 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2353 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2354 Op->Cop.Val = Val;
2355 Op->StartLoc = S;
2356 Op->EndLoc = E;
2357 return Op;
2358 }
2359
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002360 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002361 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002362 Op->Reg.RegNum = RegNum;
2363 Op->StartLoc = S;
2364 Op->EndLoc = S;
2365 return Op;
2366 }
2367
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002368 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002369 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002370 Op->Tok.Data = Str.data();
2371 Op->Tok.Length = Str.size();
2372 Op->StartLoc = S;
2373 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002374 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002375 }
2376
Bill Wendling2063b842010-11-18 23:43:05 +00002377 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002378 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002379 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002380 Op->StartLoc = S;
2381 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002382 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002383 }
2384
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002385 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2386 unsigned SrcReg,
2387 unsigned ShiftReg,
2388 unsigned ShiftImm,
2389 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002390 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002391 Op->RegShiftedReg.ShiftTy = ShTy;
2392 Op->RegShiftedReg.SrcReg = SrcReg;
2393 Op->RegShiftedReg.ShiftReg = ShiftReg;
2394 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002395 Op->StartLoc = S;
2396 Op->EndLoc = E;
2397 return Op;
2398 }
2399
Owen Andersonb595ed02011-07-21 18:54:16 +00002400 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2401 unsigned SrcReg,
2402 unsigned ShiftImm,
2403 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002404 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002405 Op->RegShiftedImm.ShiftTy = ShTy;
2406 Op->RegShiftedImm.SrcReg = SrcReg;
2407 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002408 Op->StartLoc = S;
2409 Op->EndLoc = E;
2410 return Op;
2411 }
2412
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002413 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002414 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002415 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002416 Op->ShifterImm.isASR = isASR;
2417 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002418 Op->StartLoc = S;
2419 Op->EndLoc = E;
2420 return Op;
2421 }
2422
Jim Grosbach833b9d32011-07-27 20:15:40 +00002423 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002424 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002425 Op->RotImm.Imm = Imm;
2426 Op->StartLoc = S;
2427 Op->EndLoc = E;
2428 return Op;
2429 }
2430
Jim Grosbach864b6092011-07-28 21:34:26 +00002431 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2432 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002433 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002434 Op->Bitfield.LSB = LSB;
2435 Op->Bitfield.Width = Width;
2436 Op->StartLoc = S;
2437 Op->EndLoc = E;
2438 return Op;
2439 }
2440
Bill Wendling2cae3272010-11-09 22:44:22 +00002441 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002442 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002443 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002444 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002445 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002446
Chad Rosierfa705ee2013-07-01 20:49:23 +00002447 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002448 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002449 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002450 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002451 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002452
Chad Rosierfa705ee2013-07-01 20:49:23 +00002453 // Sort based on the register encoding values.
2454 array_pod_sort(Regs.begin(), Regs.end());
2455
Bill Wendling9898ac92010-11-17 04:32:08 +00002456 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002457 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002458 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002459 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002460 Op->StartLoc = StartLoc;
2461 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002462 return Op;
2463 }
2464
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002465 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002466 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002467 ARMOperand *Op = new ARMOperand(k_VectorList);
2468 Op->VectorList.RegNum = RegNum;
2469 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002470 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002471 Op->StartLoc = S;
2472 Op->EndLoc = E;
2473 return Op;
2474 }
2475
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002476 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002477 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002478 SMLoc S, SMLoc E) {
2479 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2480 Op->VectorList.RegNum = RegNum;
2481 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002482 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002483 Op->StartLoc = S;
2484 Op->EndLoc = E;
2485 return Op;
2486 }
2487
Jim Grosbach04945c42011-12-02 00:35:16 +00002488 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002489 unsigned Index,
2490 bool isDoubleSpaced,
2491 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002492 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2493 Op->VectorList.RegNum = RegNum;
2494 Op->VectorList.Count = Count;
2495 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002496 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002497 Op->StartLoc = S;
2498 Op->EndLoc = E;
2499 return Op;
2500 }
2501
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002502 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2503 MCContext &Ctx) {
2504 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2505 Op->VectorIndex.Val = Idx;
2506 Op->StartLoc = S;
2507 Op->EndLoc = E;
2508 return Op;
2509 }
2510
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002511 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002512 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002513 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002514 Op->StartLoc = S;
2515 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002516 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002517 }
2518
Jim Grosbachd3595712011-08-03 23:50:40 +00002519 static ARMOperand *CreateMem(unsigned BaseRegNum,
2520 const MCConstantExpr *OffsetImm,
2521 unsigned OffsetRegNum,
2522 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002523 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002524 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002525 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002526 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002527 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002528 Op->Memory.BaseRegNum = BaseRegNum;
2529 Op->Memory.OffsetImm = OffsetImm;
2530 Op->Memory.OffsetRegNum = OffsetRegNum;
2531 Op->Memory.ShiftType = ShiftType;
2532 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002533 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002534 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002535 Op->StartLoc = S;
2536 Op->EndLoc = E;
2537 return Op;
2538 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002539
Jim Grosbachc320c852011-08-05 21:28:30 +00002540 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2541 ARM_AM::ShiftOpc ShiftTy,
2542 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002543 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002544 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002545 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002546 Op->PostIdxReg.isAdd = isAdd;
2547 Op->PostIdxReg.ShiftTy = ShiftTy;
2548 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002549 Op->StartLoc = S;
2550 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002551 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002552 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002553
2554 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002555 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002556 Op->MBOpt.Val = Opt;
2557 Op->StartLoc = S;
2558 Op->EndLoc = S;
2559 return Op;
2560 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002561
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002562 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2563 SMLoc S) {
2564 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2565 Op->ISBOpt.Val = Opt;
2566 Op->StartLoc = S;
2567 Op->EndLoc = S;
2568 return Op;
2569 }
2570
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002571 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002572 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002573 Op->IFlags.Val = IFlags;
2574 Op->StartLoc = S;
2575 Op->EndLoc = S;
2576 return Op;
2577 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002578
2579 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002580 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002581 Op->MMask.Val = MMask;
2582 Op->StartLoc = S;
2583 Op->EndLoc = S;
2584 return Op;
2585 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002586};
2587
2588} // end anonymous namespace.
2589
Jim Grosbach602aa902011-07-13 15:34:57 +00002590void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002591 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002592 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002593 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002594 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002595 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002596 OS << "<ccout " << getReg() << ">";
2597 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002598 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002599 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002600 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2601 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2602 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002603 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2604 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2605 break;
2606 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002607 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002608 OS << "<coprocessor number: " << getCoproc() << ">";
2609 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002610 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002611 OS << "<coprocessor register: " << getCoproc() << ">";
2612 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002613 case k_CoprocOption:
2614 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2615 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002616 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002617 OS << "<mask: " << getMSRMask() << ">";
2618 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002619 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002620 getImm()->print(OS);
2621 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002622 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002623 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002624 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002625 case k_InstSyncBarrierOpt:
2626 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2627 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002628 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002629 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002630 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002631 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002632 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002633 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002634 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2635 << PostIdxReg.RegNum;
2636 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2637 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2638 << PostIdxReg.ShiftImm;
2639 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002640 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002641 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002642 OS << "<ARM_PROC::";
2643 unsigned IFlags = getProcIFlags();
2644 for (int i=2; i >= 0; --i)
2645 if (IFlags & (1 << i))
2646 OS << ARM_PROC::IFlagsToString(1 << i);
2647 OS << ">";
2648 break;
2649 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002650 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002651 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002652 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002653 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002654 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2655 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002656 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002657 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002658 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002659 << RegShiftedReg.SrcReg << " "
2660 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2661 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002662 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002663 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002664 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002665 << RegShiftedImm.SrcReg << " "
2666 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2667 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002668 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002669 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002670 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2671 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002672 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002673 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2674 << ", width: " << Bitfield.Width << ">";
2675 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002676 case k_RegisterList:
2677 case k_DPRRegisterList:
2678 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002679 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002680
Bill Wendlingbed94652010-11-09 23:28:44 +00002681 const SmallVectorImpl<unsigned> &RegList = getRegList();
2682 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002683 I = RegList.begin(), E = RegList.end(); I != E; ) {
2684 OS << *I;
2685 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002686 }
2687
2688 OS << ">";
2689 break;
2690 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002691 case k_VectorList:
2692 OS << "<vector_list " << VectorList.Count << " * "
2693 << VectorList.RegNum << ">";
2694 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002695 case k_VectorListAllLanes:
2696 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2697 << VectorList.RegNum << ">";
2698 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002699 case k_VectorListIndexed:
2700 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2701 << VectorList.Count << " * " << VectorList.RegNum << ">";
2702 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002703 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002704 OS << "'" << getToken() << "'";
2705 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002706 case k_VectorIndex:
2707 OS << "<vectorindex " << getVectorIndex() << ">";
2708 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002709 }
2710}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002711
2712/// @name Auto-generated Match Functions
2713/// {
2714
2715static unsigned MatchRegisterName(StringRef Name);
2716
2717/// }
2718
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002719bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2720 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002721 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002722 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002723 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002724
2725 return (RegNo == (unsigned)-1);
2726}
2727
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002728/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002729/// and if it is a register name the token is eaten and the register number is
2730/// returned. Otherwise return -1.
2731///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002732int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002733 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002734 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002735
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002736 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002737 unsigned RegNum = MatchRegisterName(lowerCase);
2738 if (!RegNum) {
2739 RegNum = StringSwitch<unsigned>(lowerCase)
2740 .Case("r13", ARM::SP)
2741 .Case("r14", ARM::LR)
2742 .Case("r15", ARM::PC)
2743 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002744 // Additional register name aliases for 'gas' compatibility.
2745 .Case("a1", ARM::R0)
2746 .Case("a2", ARM::R1)
2747 .Case("a3", ARM::R2)
2748 .Case("a4", ARM::R3)
2749 .Case("v1", ARM::R4)
2750 .Case("v2", ARM::R5)
2751 .Case("v3", ARM::R6)
2752 .Case("v4", ARM::R7)
2753 .Case("v5", ARM::R8)
2754 .Case("v6", ARM::R9)
2755 .Case("v7", ARM::R10)
2756 .Case("v8", ARM::R11)
2757 .Case("sb", ARM::R9)
2758 .Case("sl", ARM::R10)
2759 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002760 .Default(0);
2761 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002762 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002763 // Check for aliases registered via .req. Canonicalize to lower case.
2764 // That's more consistent since register names are case insensitive, and
2765 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2766 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002767 // If no match, return failure.
2768 if (Entry == RegisterReqs.end())
2769 return -1;
2770 Parser.Lex(); // Eat identifier token.
2771 return Entry->getValue();
2772 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002773
Chris Lattner44e5981c2010-10-30 04:09:10 +00002774 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002775
Chris Lattner44e5981c2010-10-30 04:09:10 +00002776 return RegNum;
2777}
Jim Grosbach99710a82010-11-01 16:44:21 +00002778
Jim Grosbachbb24c592011-07-13 18:49:30 +00002779// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2780// If a recoverable error occurs, return 1. If an irrecoverable error
2781// occurs, return -1. An irrecoverable error is one where tokens have been
2782// consumed in the process of trying to parse the shifter (i.e., when it is
2783// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002784int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002785 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2786 SMLoc S = Parser.getTok().getLoc();
2787 const AsmToken &Tok = Parser.getTok();
Kevin Enderby62873712014-02-17 21:45:27 +00002788 if (Tok.isNot(AsmToken::Identifier))
2789 return -1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002790
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002791 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002792 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002793 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002794 .Case("lsl", ARM_AM::lsl)
2795 .Case("lsr", ARM_AM::lsr)
2796 .Case("asr", ARM_AM::asr)
2797 .Case("ror", ARM_AM::ror)
2798 .Case("rrx", ARM_AM::rrx)
2799 .Default(ARM_AM::no_shift);
2800
2801 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002802 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002803
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002804 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002805
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002806 // The source register for the shift has already been added to the
2807 // operand list, so we need to pop it off and combine it into the shifted
2808 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002809 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002810 if (!PrevOp->isReg())
2811 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2812 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002813
2814 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002815 int64_t Imm = 0;
2816 int ShiftReg = 0;
2817 if (ShiftTy == ARM_AM::rrx) {
2818 // RRX Doesn't have an explicit shift amount. The encoder expects
2819 // the shift register to be the same as the source register. Seems odd,
2820 // but OK.
2821 ShiftReg = SrcReg;
2822 } else {
2823 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002824 if (Parser.getTok().is(AsmToken::Hash) ||
2825 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002826 Parser.Lex(); // Eat hash.
2827 SMLoc ImmLoc = Parser.getTok().getLoc();
2828 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002829 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002830 Error(ImmLoc, "invalid immediate shift value");
2831 return -1;
2832 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002833 // The expression must be evaluatable as an immediate.
2834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002835 if (!CE) {
2836 Error(ImmLoc, "invalid immediate shift value");
2837 return -1;
2838 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002839 // Range check the immediate.
2840 // lsl, ror: 0 <= imm <= 31
2841 // lsr, asr: 0 <= imm <= 32
2842 Imm = CE->getValue();
2843 if (Imm < 0 ||
2844 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2845 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002846 Error(ImmLoc, "immediate shift value out of range");
2847 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002848 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002849 // shift by zero is a nop. Always send it through as lsl.
2850 // ('as' compatibility)
2851 if (Imm == 0)
2852 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002853 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002854 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002855 EndLoc = Parser.getTok().getEndLoc();
2856 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002857 if (ShiftReg == -1) {
2858 Error (L, "expected immediate or register in shift operand");
2859 return -1;
2860 }
2861 } else {
2862 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002863 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002864 return -1;
2865 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002866 }
2867
Owen Andersonb595ed02011-07-21 18:54:16 +00002868 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2869 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002870 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002871 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002872 else
2873 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002874 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002875
Jim Grosbachbb24c592011-07-13 18:49:30 +00002876 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002877}
2878
2879
Bill Wendling2063b842010-11-18 23:43:05 +00002880/// Try to parse a register name. The token must be an Identifier when called.
2881/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2882/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002883///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002884/// TODO this is likely to change to allow different register types and or to
2885/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002886bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002887tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002888 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002889 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002890 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002891 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002892
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002893 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2894 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002895
Chris Lattner44e5981c2010-10-30 04:09:10 +00002896 const AsmToken &ExclaimTok = Parser.getTok();
2897 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002898 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2899 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002900 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002901 return false;
2902 }
2903
2904 // Also check for an index operand. This is only legal for vector registers,
2905 // but that'll get caught OK in operand matching, so we don't need to
2906 // explicitly filter everything else out here.
2907 if (Parser.getTok().is(AsmToken::LBrac)) {
2908 SMLoc SIdx = Parser.getTok().getLoc();
2909 Parser.Lex(); // Eat left bracket token.
2910
2911 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002912 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002913 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002914 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002915 if (!MCE)
2916 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002917
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002918 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002919 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002920
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002921 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002922 Parser.Lex(); // Eat right bracket token.
2923
2924 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2925 SIdx, E,
2926 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002927 }
2928
Bill Wendling2063b842010-11-18 23:43:05 +00002929 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002930}
2931
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002932/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2933/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2934/// "c5", ...
2935static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002936 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2937 // but efficient.
2938 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002939 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002940 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002941 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002942 return -1;
2943 switch (Name[1]) {
2944 default: return -1;
2945 case '0': return 0;
2946 case '1': return 1;
2947 case '2': return 2;
2948 case '3': return 3;
2949 case '4': return 4;
2950 case '5': return 5;
2951 case '6': return 6;
2952 case '7': return 7;
2953 case '8': return 8;
2954 case '9': return 9;
2955 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002956 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002957 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002958 return -1;
2959 switch (Name[2]) {
2960 default: return -1;
Artyom Skrobov86534432013-11-08 09:16:31 +00002961 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2962 case '0': return CoprocOp == 'p'? -1: 10;
2963 case '1': return CoprocOp == 'p'? -1: 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002964 case '2': return 12;
2965 case '3': return 13;
2966 case '4': return 14;
2967 case '5': return 15;
2968 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002969 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002970}
2971
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002972/// parseITCondCode - Try to parse a condition code for an IT instruction.
2973ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2974parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2975 SMLoc S = Parser.getTok().getLoc();
2976 const AsmToken &Tok = Parser.getTok();
2977 if (!Tok.is(AsmToken::Identifier))
2978 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002979 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002980 .Case("eq", ARMCC::EQ)
2981 .Case("ne", ARMCC::NE)
2982 .Case("hs", ARMCC::HS)
2983 .Case("cs", ARMCC::HS)
2984 .Case("lo", ARMCC::LO)
2985 .Case("cc", ARMCC::LO)
2986 .Case("mi", ARMCC::MI)
2987 .Case("pl", ARMCC::PL)
2988 .Case("vs", ARMCC::VS)
2989 .Case("vc", ARMCC::VC)
2990 .Case("hi", ARMCC::HI)
2991 .Case("ls", ARMCC::LS)
2992 .Case("ge", ARMCC::GE)
2993 .Case("lt", ARMCC::LT)
2994 .Case("gt", ARMCC::GT)
2995 .Case("le", ARMCC::LE)
2996 .Case("al", ARMCC::AL)
2997 .Default(~0U);
2998 if (CC == ~0U)
2999 return MatchOperand_NoMatch;
3000 Parser.Lex(); // Eat the token.
3001
3002 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3003
3004 return MatchOperand_Success;
3005}
3006
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003007/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003008/// token must be an Identifier when called, and if it is a coprocessor
3009/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003010ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003011parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003012 SMLoc S = Parser.getTok().getLoc();
3013 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003014 if (Tok.isNot(AsmToken::Identifier))
3015 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003016
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003017 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003018 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003019 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003020
3021 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003022 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003023 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003024}
3025
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003026/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003027/// token must be an Identifier when called, and if it is a coprocessor
3028/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003029ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003030parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003031 SMLoc S = Parser.getTok().getLoc();
3032 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003033 if (Tok.isNot(AsmToken::Identifier))
3034 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003035
3036 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3037 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003038 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003039
3040 Parser.Lex(); // Eat identifier token.
3041 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003042 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003043}
3044
Jim Grosbach48399582011-10-12 17:34:41 +00003045/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3046/// coproc_option : '{' imm0_255 '}'
3047ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3048parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3049 SMLoc S = Parser.getTok().getLoc();
3050
3051 // If this isn't a '{', this isn't a coprocessor immediate operand.
3052 if (Parser.getTok().isNot(AsmToken::LCurly))
3053 return MatchOperand_NoMatch;
3054 Parser.Lex(); // Eat the '{'
3055
3056 const MCExpr *Expr;
3057 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003058 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003059 Error(Loc, "illegal expression");
3060 return MatchOperand_ParseFail;
3061 }
3062 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3063 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3064 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3065 return MatchOperand_ParseFail;
3066 }
3067 int Val = CE->getValue();
3068
3069 // Check for and consume the closing '}'
3070 if (Parser.getTok().isNot(AsmToken::RCurly))
3071 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003072 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003073 Parser.Lex(); // Eat the '}'
3074
3075 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3076 return MatchOperand_Success;
3077}
3078
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003079// For register list parsing, we need to map from raw GPR register numbering
3080// to the enumeration values. The enumeration values aren't sorted by
3081// register number due to our using "sp", "lr" and "pc" as canonical names.
3082static unsigned getNextRegister(unsigned Reg) {
3083 // If this is a GPR, we need to do it manually, otherwise we can rely
3084 // on the sort ordering of the enumeration since the other reg-classes
3085 // are sane.
3086 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3087 return Reg + 1;
3088 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003089 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003090 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3091 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3092 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3093 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3094 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3095 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3096 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3097 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3098 }
3099}
3100
Jim Grosbach85a23432011-11-11 21:27:40 +00003101// Return the low-subreg of a given Q register.
3102static unsigned getDRegFromQReg(unsigned QReg) {
3103 switch (QReg) {
3104 default: llvm_unreachable("expected a Q register!");
3105 case ARM::Q0: return ARM::D0;
3106 case ARM::Q1: return ARM::D2;
3107 case ARM::Q2: return ARM::D4;
3108 case ARM::Q3: return ARM::D6;
3109 case ARM::Q4: return ARM::D8;
3110 case ARM::Q5: return ARM::D10;
3111 case ARM::Q6: return ARM::D12;
3112 case ARM::Q7: return ARM::D14;
3113 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003114 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003115 case ARM::Q10: return ARM::D20;
3116 case ARM::Q11: return ARM::D22;
3117 case ARM::Q12: return ARM::D24;
3118 case ARM::Q13: return ARM::D26;
3119 case ARM::Q14: return ARM::D28;
3120 case ARM::Q15: return ARM::D30;
3121 }
3122}
3123
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003124/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003125bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003126parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003127 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003128 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003129 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003130 Parser.Lex(); // Eat '{' token.
3131 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003132
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003133 // Check the first register in the list to see what register class
3134 // this is a list of.
3135 int Reg = tryParseRegister();
3136 if (Reg == -1)
3137 return Error(RegLoc, "register expected");
3138
Jim Grosbach85a23432011-11-11 21:27:40 +00003139 // The reglist instructions have at most 16 registers, so reserve
3140 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003141 int EReg = 0;
3142 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003143
3144 // Allow Q regs and just interpret them as the two D sub-registers.
3145 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3146 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003147 EReg = MRI->getEncodingValue(Reg);
3148 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003149 ++Reg;
3150 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003151 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003152 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3153 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3154 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3155 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3156 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3157 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3158 else
3159 return Error(RegLoc, "invalid register in register list");
3160
Jim Grosbach85a23432011-11-11 21:27:40 +00003161 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003162 EReg = MRI->getEncodingValue(Reg);
3163 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003164
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003165 // This starts immediately after the first register token in the list,
3166 // so we can see either a comma or a minus (range separator) as a legal
3167 // next token.
3168 while (Parser.getTok().is(AsmToken::Comma) ||
3169 Parser.getTok().is(AsmToken::Minus)) {
3170 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003171 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003172 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003173 int EndReg = tryParseRegister();
3174 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003175 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003176 // Allow Q regs and just interpret them as the two D sub-registers.
3177 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3178 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003179 // If the register is the same as the start reg, there's nothing
3180 // more to do.
3181 if (Reg == EndReg)
3182 continue;
3183 // The register must be in the same register class as the first.
3184 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003185 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003186 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003187 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003188 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003189
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003190 // Add all the registers in the range to the register list.
3191 while (Reg != EndReg) {
3192 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003193 EReg = MRI->getEncodingValue(Reg);
3194 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003195 }
3196 continue;
3197 }
3198 Parser.Lex(); // Eat the comma.
3199 RegLoc = Parser.getTok().getLoc();
3200 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003201 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003202 Reg = tryParseRegister();
3203 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003204 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003205 // Allow Q regs and just interpret them as the two D sub-registers.
3206 bool isQReg = false;
3207 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3208 Reg = getDRegFromQReg(Reg);
3209 isQReg = true;
3210 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003211 // The register must be in the same register class as the first.
3212 if (!RC->contains(Reg))
3213 return Error(RegLoc, "invalid register in register list");
3214 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003215 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003216 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3217 Warning(RegLoc, "register list not in ascending order");
3218 else
3219 return Error(RegLoc, "register list not in ascending order");
3220 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003221 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003222 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3223 ") in register list");
3224 continue;
3225 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003226 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003227 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3228 Reg != OldReg + 1)
3229 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003230 EReg = MRI->getEncodingValue(Reg);
3231 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3232 if (isQReg) {
3233 EReg = MRI->getEncodingValue(++Reg);
3234 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3235 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003236 }
3237
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003238 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003239 return Error(Parser.getTok().getLoc(), "'}' expected");
3240 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003241 Parser.Lex(); // Eat '}' token.
3242
Jim Grosbach18bf3632011-12-13 21:48:29 +00003243 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003244 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003245
3246 // The ARM system instruction variants for LDM/STM have a '^' token here.
3247 if (Parser.getTok().is(AsmToken::Caret)) {
3248 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3249 Parser.Lex(); // Eat '^' token.
3250 }
3251
Bill Wendling2063b842010-11-18 23:43:05 +00003252 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003253}
3254
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003255// Helper function to parse the lane index for vector lists.
3256ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003257parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003258 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003259 if (Parser.getTok().is(AsmToken::LBrac)) {
3260 Parser.Lex(); // Eat the '['.
3261 if (Parser.getTok().is(AsmToken::RBrac)) {
3262 // "Dn[]" is the 'all lanes' syntax.
3263 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003264 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003265 Parser.Lex(); // Eat the ']'.
3266 return MatchOperand_Success;
3267 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003268
3269 // There's an optional '#' token here. Normally there wouldn't be, but
3270 // inline assemble puts one in, and it's friendly to accept that.
3271 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003272 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003273
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003274 const MCExpr *LaneIndex;
3275 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003276 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003277 Error(Loc, "illegal expression");
3278 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003279 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003280 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3281 if (!CE) {
3282 Error(Loc, "lane index must be empty or an integer");
3283 return MatchOperand_ParseFail;
3284 }
3285 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3286 Error(Parser.getTok().getLoc(), "']' expected");
3287 return MatchOperand_ParseFail;
3288 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003289 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003290 Parser.Lex(); // Eat the ']'.
3291 int64_t Val = CE->getValue();
3292
3293 // FIXME: Make this range check context sensitive for .8, .16, .32.
3294 if (Val < 0 || Val > 7) {
3295 Error(Parser.getTok().getLoc(), "lane index out of range");
3296 return MatchOperand_ParseFail;
3297 }
3298 Index = Val;
3299 LaneKind = IndexedLane;
3300 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003301 }
3302 LaneKind = NoLanes;
3303 return MatchOperand_Success;
3304}
3305
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003306// parse a vector register list
3307ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3308parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003309 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003310 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003311 SMLoc S = Parser.getTok().getLoc();
3312 // As an extension (to match gas), support a plain D register or Q register
3313 // (without encosing curly braces) as a single or double entry list,
3314 // respectively.
3315 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003316 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003317 int Reg = tryParseRegister();
3318 if (Reg == -1)
3319 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003320 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003321 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003322 if (Res != MatchOperand_Success)
3323 return Res;
3324 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003325 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003326 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003327 break;
3328 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003329 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3330 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003331 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003332 case IndexedLane:
3333 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003334 LaneIndex,
3335 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003336 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003337 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003338 return MatchOperand_Success;
3339 }
3340 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3341 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003342 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003343 if (Res != MatchOperand_Success)
3344 return Res;
3345 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003346 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003347 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003348 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003349 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003350 break;
3351 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003352 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3353 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003354 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3355 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003356 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003357 case IndexedLane:
3358 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003359 LaneIndex,
3360 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003361 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003362 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003363 return MatchOperand_Success;
3364 }
3365 Error(S, "vector register expected");
3366 return MatchOperand_ParseFail;
3367 }
3368
3369 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003370 return MatchOperand_NoMatch;
3371
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003372 Parser.Lex(); // Eat '{' token.
3373 SMLoc RegLoc = Parser.getTok().getLoc();
3374
3375 int Reg = tryParseRegister();
3376 if (Reg == -1) {
3377 Error(RegLoc, "register expected");
3378 return MatchOperand_ParseFail;
3379 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003380 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003381 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003382 unsigned FirstReg = Reg;
3383 // The list is of D registers, but we also allow Q regs and just interpret
3384 // them as the two D sub-registers.
3385 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3386 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003387 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3388 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003389 ++Reg;
3390 ++Count;
3391 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003392
3393 SMLoc E;
3394 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003395 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003396
Jim Grosbache891fe82011-11-15 23:19:15 +00003397 while (Parser.getTok().is(AsmToken::Comma) ||
3398 Parser.getTok().is(AsmToken::Minus)) {
3399 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003400 if (!Spacing)
3401 Spacing = 1; // Register range implies a single spaced list.
3402 else if (Spacing == 2) {
3403 Error(Parser.getTok().getLoc(),
3404 "sequential registers in double spaced list");
3405 return MatchOperand_ParseFail;
3406 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003407 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003408 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003409 int EndReg = tryParseRegister();
3410 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003411 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003412 return MatchOperand_ParseFail;
3413 }
3414 // Allow Q regs and just interpret them as the two D sub-registers.
3415 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3416 EndReg = getDRegFromQReg(EndReg) + 1;
3417 // If the register is the same as the start reg, there's nothing
3418 // more to do.
3419 if (Reg == EndReg)
3420 continue;
3421 // The register must be in the same register class as the first.
3422 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003423 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003424 return MatchOperand_ParseFail;
3425 }
3426 // Ranges must go from low to high.
3427 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003428 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003429 return MatchOperand_ParseFail;
3430 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003431 // Parse the lane specifier if present.
3432 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003433 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003434 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3435 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003436 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003437 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003438 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003439 return MatchOperand_ParseFail;
3440 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003441
3442 // Add all the registers in the range to the register list.
3443 Count += EndReg - Reg;
3444 Reg = EndReg;
3445 continue;
3446 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003447 Parser.Lex(); // Eat the comma.
3448 RegLoc = Parser.getTok().getLoc();
3449 int OldReg = Reg;
3450 Reg = tryParseRegister();
3451 if (Reg == -1) {
3452 Error(RegLoc, "register expected");
3453 return MatchOperand_ParseFail;
3454 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003455 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003456 // It's OK to use the enumeration values directly here rather, as the
3457 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003458 //
3459 // The list is of D registers, but we also allow Q regs and just interpret
3460 // them as the two D sub-registers.
3461 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003462 if (!Spacing)
3463 Spacing = 1; // Register range implies a single spaced list.
3464 else if (Spacing == 2) {
3465 Error(RegLoc,
3466 "invalid register in double-spaced list (must be 'D' register')");
3467 return MatchOperand_ParseFail;
3468 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003469 Reg = getDRegFromQReg(Reg);
3470 if (Reg != OldReg + 1) {
3471 Error(RegLoc, "non-contiguous register range");
3472 return MatchOperand_ParseFail;
3473 }
3474 ++Reg;
3475 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003476 // Parse the lane specifier if present.
3477 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003478 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003479 SMLoc LaneLoc = Parser.getTok().getLoc();
3480 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3481 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) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003484 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003485 return MatchOperand_ParseFail;
3486 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003487 continue;
3488 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003489 // Normal D register.
3490 // Figure out the register spacing (single or double) of the list if
3491 // we don't know it already.
3492 if (!Spacing)
3493 Spacing = 1 + (Reg == OldReg + 2);
3494
3495 // Just check that it's contiguous and keep going.
3496 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003497 Error(RegLoc, "non-contiguous register range");
3498 return MatchOperand_ParseFail;
3499 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003500 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003501 // Parse the lane specifier if present.
3502 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003503 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003504 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003505 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003506 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003507 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003508 Error(EndLoc, "mismatched lane index in register list");
3509 return MatchOperand_ParseFail;
3510 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003511 }
3512
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003513 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003514 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003515 return MatchOperand_ParseFail;
3516 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003517 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003518 Parser.Lex(); // Eat '}' token.
3519
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003520 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003521 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003522 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003523 // composite register classes.
3524 if (Count == 2) {
3525 const MCRegisterClass *RC = (Spacing == 1) ?
3526 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3527 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3528 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3529 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003530
Jim Grosbach2f50e922011-12-15 21:44:33 +00003531 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3532 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003533 break;
3534 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003535 // Two-register operands have been converted to the
3536 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003537 if (Count == 2) {
3538 const MCRegisterClass *RC = (Spacing == 1) ?
3539 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3540 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003541 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3542 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003543 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003544 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003545 S, E));
3546 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003547 case IndexedLane:
3548 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003549 LaneIndex,
3550 (Spacing == 2),
3551 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003552 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003553 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003554 return MatchOperand_Success;
3555}
3556
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003557/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003558ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003559parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003560 SMLoc S = Parser.getTok().getLoc();
3561 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003562 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003563
Jiangning Liu288e1af2012-08-02 08:21:27 +00003564 if (Tok.is(AsmToken::Identifier)) {
3565 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003566
Jiangning Liu288e1af2012-08-02 08:21:27 +00003567 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3568 .Case("sy", ARM_MB::SY)
3569 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003570 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003571 .Case("sh", ARM_MB::ISH)
3572 .Case("ish", ARM_MB::ISH)
3573 .Case("shst", ARM_MB::ISHST)
3574 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003575 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003576 .Case("nsh", ARM_MB::NSH)
3577 .Case("un", ARM_MB::NSH)
3578 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003579 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003580 .Case("unst", ARM_MB::NSHST)
3581 .Case("osh", ARM_MB::OSH)
3582 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003583 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003584 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003585
Joey Gouly926d3f52013-09-05 15:35:24 +00003586 // ishld, oshld, nshld and ld are only available from ARMv8.
3587 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3588 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3589 Opt = ~0U;
3590
Jiangning Liu288e1af2012-08-02 08:21:27 +00003591 if (Opt == ~0U)
3592 return MatchOperand_NoMatch;
3593
3594 Parser.Lex(); // Eat identifier token.
3595 } else if (Tok.is(AsmToken::Hash) ||
3596 Tok.is(AsmToken::Dollar) ||
3597 Tok.is(AsmToken::Integer)) {
3598 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003599 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003600 SMLoc Loc = Parser.getTok().getLoc();
3601
3602 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003603 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003604 Error(Loc, "illegal expression");
3605 return MatchOperand_ParseFail;
3606 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003607
Jiangning Liu288e1af2012-08-02 08:21:27 +00003608 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3609 if (!CE) {
3610 Error(Loc, "constant expression expected");
3611 return MatchOperand_ParseFail;
3612 }
3613
3614 int Val = CE->getValue();
3615 if (Val & ~0xf) {
3616 Error(Loc, "immediate value out of range");
3617 return MatchOperand_ParseFail;
3618 }
3619
3620 Opt = ARM_MB::RESERVED_0 + Val;
3621 } else
3622 return MatchOperand_ParseFail;
3623
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003624 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003625 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003626}
3627
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003628/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3629ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3630parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3631 SMLoc S = Parser.getTok().getLoc();
3632 const AsmToken &Tok = Parser.getTok();
3633 unsigned Opt;
3634
3635 if (Tok.is(AsmToken::Identifier)) {
3636 StringRef OptStr = Tok.getString();
3637
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003638 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003639 Opt = ARM_ISB::SY;
3640 else
3641 return MatchOperand_NoMatch;
3642
3643 Parser.Lex(); // Eat identifier token.
3644 } else if (Tok.is(AsmToken::Hash) ||
3645 Tok.is(AsmToken::Dollar) ||
3646 Tok.is(AsmToken::Integer)) {
3647 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003648 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003649 SMLoc Loc = Parser.getTok().getLoc();
3650
3651 const MCExpr *ISBarrierID;
3652 if (getParser().parseExpression(ISBarrierID)) {
3653 Error(Loc, "illegal expression");
3654 return MatchOperand_ParseFail;
3655 }
3656
3657 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3658 if (!CE) {
3659 Error(Loc, "constant expression expected");
3660 return MatchOperand_ParseFail;
3661 }
3662
3663 int Val = CE->getValue();
3664 if (Val & ~0xf) {
3665 Error(Loc, "immediate value out of range");
3666 return MatchOperand_ParseFail;
3667 }
3668
3669 Opt = ARM_ISB::RESERVED_0 + Val;
3670 } else
3671 return MatchOperand_ParseFail;
3672
3673 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3674 (ARM_ISB::InstSyncBOpt)Opt, S));
3675 return MatchOperand_Success;
3676}
3677
3678
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003679/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003680ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003681parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003682 SMLoc S = Parser.getTok().getLoc();
3683 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003684 if (!Tok.is(AsmToken::Identifier))
3685 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003686 StringRef IFlagsStr = Tok.getString();
3687
Owen Anderson10c5b122011-10-05 17:16:40 +00003688 // An iflags string of "none" is interpreted to mean that none of the AIF
3689 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003690 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003691 if (IFlagsStr != "none") {
3692 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3693 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3694 .Case("a", ARM_PROC::A)
3695 .Case("i", ARM_PROC::I)
3696 .Case("f", ARM_PROC::F)
3697 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003698
Owen Anderson10c5b122011-10-05 17:16:40 +00003699 // If some specific iflag is already set, it means that some letter is
3700 // present more than once, this is not acceptable.
3701 if (Flag == ~0U || (IFlags & Flag))
3702 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003703
Owen Anderson10c5b122011-10-05 17:16:40 +00003704 IFlags |= Flag;
3705 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003706 }
3707
3708 Parser.Lex(); // Eat identifier token.
3709 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3710 return MatchOperand_Success;
3711}
3712
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003713/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003714ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003715parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003716 SMLoc S = Parser.getTok().getLoc();
3717 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003718 if (!Tok.is(AsmToken::Identifier))
3719 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003720 StringRef Mask = Tok.getString();
3721
James Molloy21efa7d2011-09-28 14:21:38 +00003722 if (isMClass()) {
3723 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003724 std::string Name = Mask.lower();
3725 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003726 // Note: in the documentation:
3727 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3728 // for MSR APSR_nzcvq.
3729 // but we do make it an alias here. This is so to get the "mask encoding"
3730 // bits correct on MSR APSR writes.
3731 //
3732 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3733 // should really only be allowed when writing a special register. Note
3734 // they get dropped in the MRS instruction reading a special register as
3735 // the SYSm field is only 8 bits.
3736 //
3737 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3738 // includes the DSP extension but that is not checked.
3739 .Case("apsr", 0x800)
3740 .Case("apsr_nzcvq", 0x800)
3741 .Case("apsr_g", 0x400)
3742 .Case("apsr_nzcvqg", 0xc00)
3743 .Case("iapsr", 0x801)
3744 .Case("iapsr_nzcvq", 0x801)
3745 .Case("iapsr_g", 0x401)
3746 .Case("iapsr_nzcvqg", 0xc01)
3747 .Case("eapsr", 0x802)
3748 .Case("eapsr_nzcvq", 0x802)
3749 .Case("eapsr_g", 0x402)
3750 .Case("eapsr_nzcvqg", 0xc02)
3751 .Case("xpsr", 0x803)
3752 .Case("xpsr_nzcvq", 0x803)
3753 .Case("xpsr_g", 0x403)
3754 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003755 .Case("ipsr", 0x805)
3756 .Case("epsr", 0x806)
3757 .Case("iepsr", 0x807)
3758 .Case("msp", 0x808)
3759 .Case("psp", 0x809)
3760 .Case("primask", 0x810)
3761 .Case("basepri", 0x811)
3762 .Case("basepri_max", 0x812)
3763 .Case("faultmask", 0x813)
3764 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003765 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003766
James Molloy21efa7d2011-09-28 14:21:38 +00003767 if (FlagsVal == ~0U)
3768 return MatchOperand_NoMatch;
3769
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003770 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003771 // basepri, basepri_max and faultmask only valid for V7m.
3772 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003773
James Molloy21efa7d2011-09-28 14:21:38 +00003774 Parser.Lex(); // Eat identifier token.
3775 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3776 return MatchOperand_Success;
3777 }
3778
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003779 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3780 size_t Start = 0, Next = Mask.find('_');
3781 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003782 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003783 if (Next != StringRef::npos)
3784 Flags = Mask.slice(Next+1, Mask.size());
3785
3786 // FlagsVal contains the complete mask:
3787 // 3-0: Mask
3788 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3789 unsigned FlagsVal = 0;
3790
3791 if (SpecReg == "apsr") {
3792 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003793 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003794 .Case("g", 0x4) // same as CPSR_s
3795 .Case("nzcvqg", 0xc) // same as CPSR_fs
3796 .Default(~0U);
3797
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003798 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003799 if (!Flags.empty())
3800 return MatchOperand_NoMatch;
3801 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003802 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003803 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003804 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003805 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3806 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003807 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003808 for (int i = 0, e = Flags.size(); i != e; ++i) {
3809 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3810 .Case("c", 1)
3811 .Case("x", 2)
3812 .Case("s", 4)
3813 .Case("f", 8)
3814 .Default(~0U);
3815
3816 // If some specific flag is already set, it means that some letter is
3817 // present more than once, this is not acceptable.
3818 if (FlagsVal == ~0U || (FlagsVal & Flag))
3819 return MatchOperand_NoMatch;
3820 FlagsVal |= Flag;
3821 }
3822 } else // No match for special register.
3823 return MatchOperand_NoMatch;
3824
Owen Anderson03a173e2011-10-21 18:43:28 +00003825 // Special register without flags is NOT equivalent to "fc" flags.
3826 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3827 // two lines would enable gas compatibility at the expense of breaking
3828 // round-tripping.
3829 //
3830 // if (!FlagsVal)
3831 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003832
3833 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3834 if (SpecReg == "spsr")
3835 FlagsVal |= 16;
3836
3837 Parser.Lex(); // Eat identifier token.
3838 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3839 return MatchOperand_Success;
3840}
3841
Jim Grosbach27c1e252011-07-21 17:23:04 +00003842ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3843parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3844 int Low, int High) {
3845 const AsmToken &Tok = Parser.getTok();
3846 if (Tok.isNot(AsmToken::Identifier)) {
3847 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3848 return MatchOperand_ParseFail;
3849 }
3850 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003851 std::string LowerOp = Op.lower();
3852 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003853 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3854 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3855 return MatchOperand_ParseFail;
3856 }
3857 Parser.Lex(); // Eat shift type token.
3858
3859 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003860 if (Parser.getTok().isNot(AsmToken::Hash) &&
3861 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003862 Error(Parser.getTok().getLoc(), "'#' expected");
3863 return MatchOperand_ParseFail;
3864 }
3865 Parser.Lex(); // Eat hash token.
3866
3867 const MCExpr *ShiftAmount;
3868 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003869 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003870 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003871 Error(Loc, "illegal expression");
3872 return MatchOperand_ParseFail;
3873 }
3874 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3875 if (!CE) {
3876 Error(Loc, "constant expression expected");
3877 return MatchOperand_ParseFail;
3878 }
3879 int Val = CE->getValue();
3880 if (Val < Low || Val > High) {
3881 Error(Loc, "immediate value out of range");
3882 return MatchOperand_ParseFail;
3883 }
3884
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003885 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003886
3887 return MatchOperand_Success;
3888}
3889
Jim Grosbach0a547702011-07-22 17:44:50 +00003890ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3891parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3892 const AsmToken &Tok = Parser.getTok();
3893 SMLoc S = Tok.getLoc();
3894 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003895 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003896 return MatchOperand_ParseFail;
3897 }
Tim Northover4d141442013-05-31 15:58:45 +00003898 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003899 .Case("be", 1)
3900 .Case("le", 0)
3901 .Default(-1);
3902 Parser.Lex(); // Eat the token.
3903
3904 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003905 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003906 return MatchOperand_ParseFail;
3907 }
3908 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3909 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003910 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003911 return MatchOperand_Success;
3912}
3913
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003914/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3915/// instructions. Legal values are:
3916/// lsl #n 'n' in [0,31]
3917/// asr #n 'n' in [1,32]
3918/// n == 32 encoded as n == 0.
3919ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3920parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3921 const AsmToken &Tok = Parser.getTok();
3922 SMLoc S = Tok.getLoc();
3923 if (Tok.isNot(AsmToken::Identifier)) {
3924 Error(S, "shift operator 'asr' or 'lsl' expected");
3925 return MatchOperand_ParseFail;
3926 }
3927 StringRef ShiftName = Tok.getString();
3928 bool isASR;
3929 if (ShiftName == "lsl" || ShiftName == "LSL")
3930 isASR = false;
3931 else if (ShiftName == "asr" || ShiftName == "ASR")
3932 isASR = true;
3933 else {
3934 Error(S, "shift operator 'asr' or 'lsl' expected");
3935 return MatchOperand_ParseFail;
3936 }
3937 Parser.Lex(); // Eat the operator.
3938
3939 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003940 if (Parser.getTok().isNot(AsmToken::Hash) &&
3941 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003942 Error(Parser.getTok().getLoc(), "'#' expected");
3943 return MatchOperand_ParseFail;
3944 }
3945 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003946 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003947
3948 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003949 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003950 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003951 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003952 return MatchOperand_ParseFail;
3953 }
3954 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3955 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003956 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003957 return MatchOperand_ParseFail;
3958 }
3959
3960 int64_t Val = CE->getValue();
3961 if (isASR) {
3962 // Shift amount must be in [1,32]
3963 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003964 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003965 return MatchOperand_ParseFail;
3966 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003967 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3968 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003969 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003970 return MatchOperand_ParseFail;
3971 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003972 if (Val == 32) Val = 0;
3973 } else {
3974 // Shift amount must be in [1,32]
3975 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003976 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003977 return MatchOperand_ParseFail;
3978 }
3979 }
3980
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003981 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003982
3983 return MatchOperand_Success;
3984}
3985
Jim Grosbach833b9d32011-07-27 20:15:40 +00003986/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3987/// of instructions. Legal values are:
3988/// ror #n 'n' in {0, 8, 16, 24}
3989ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3990parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3991 const AsmToken &Tok = Parser.getTok();
3992 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003993 if (Tok.isNot(AsmToken::Identifier))
3994 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003995 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003996 if (ShiftName != "ror" && ShiftName != "ROR")
3997 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003998 Parser.Lex(); // Eat the operator.
3999
4000 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004001 if (Parser.getTok().isNot(AsmToken::Hash) &&
4002 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004003 Error(Parser.getTok().getLoc(), "'#' expected");
4004 return MatchOperand_ParseFail;
4005 }
4006 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004007 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004008
4009 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004010 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004011 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004012 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004013 return MatchOperand_ParseFail;
4014 }
4015 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4016 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004017 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004018 return MatchOperand_ParseFail;
4019 }
4020
4021 int64_t Val = CE->getValue();
4022 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4023 // normally, zero is represented in asm by omitting the rotate operand
4024 // entirely.
4025 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004026 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004027 return MatchOperand_ParseFail;
4028 }
4029
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004030 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004031
4032 return MatchOperand_Success;
4033}
4034
Jim Grosbach864b6092011-07-28 21:34:26 +00004035ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4036parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4037 SMLoc S = Parser.getTok().getLoc();
4038 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004039 if (Parser.getTok().isNot(AsmToken::Hash) &&
4040 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004041 Error(Parser.getTok().getLoc(), "'#' expected");
4042 return MatchOperand_ParseFail;
4043 }
4044 Parser.Lex(); // Eat hash token.
4045
4046 const MCExpr *LSBExpr;
4047 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004048 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004049 Error(E, "malformed immediate expression");
4050 return MatchOperand_ParseFail;
4051 }
4052 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4053 if (!CE) {
4054 Error(E, "'lsb' operand must be an immediate");
4055 return MatchOperand_ParseFail;
4056 }
4057
4058 int64_t LSB = CE->getValue();
4059 // The LSB must be in the range [0,31]
4060 if (LSB < 0 || LSB > 31) {
4061 Error(E, "'lsb' operand must be in the range [0,31]");
4062 return MatchOperand_ParseFail;
4063 }
4064 E = Parser.getTok().getLoc();
4065
4066 // Expect another immediate operand.
4067 if (Parser.getTok().isNot(AsmToken::Comma)) {
4068 Error(Parser.getTok().getLoc(), "too few operands");
4069 return MatchOperand_ParseFail;
4070 }
4071 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004072 if (Parser.getTok().isNot(AsmToken::Hash) &&
4073 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004074 Error(Parser.getTok().getLoc(), "'#' expected");
4075 return MatchOperand_ParseFail;
4076 }
4077 Parser.Lex(); // Eat hash token.
4078
4079 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004080 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004081 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004082 Error(E, "malformed immediate expression");
4083 return MatchOperand_ParseFail;
4084 }
4085 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4086 if (!CE) {
4087 Error(E, "'width' operand must be an immediate");
4088 return MatchOperand_ParseFail;
4089 }
4090
4091 int64_t Width = CE->getValue();
4092 // The LSB must be in the range [1,32-lsb]
4093 if (Width < 1 || Width > 32 - LSB) {
4094 Error(E, "'width' operand must be in the range [1,32-lsb]");
4095 return MatchOperand_ParseFail;
4096 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004097
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004098 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004099
4100 return MatchOperand_Success;
4101}
4102
Jim Grosbachd3595712011-08-03 23:50:40 +00004103ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4104parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4105 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004106 // postidx_reg := '+' register {, shift}
4107 // | '-' register {, shift}
4108 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004109
4110 // This method must return MatchOperand_NoMatch without consuming any tokens
4111 // in the case where there is no match, as other alternatives take other
4112 // parse methods.
4113 AsmToken Tok = Parser.getTok();
4114 SMLoc S = Tok.getLoc();
4115 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004116 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004117 if (Tok.is(AsmToken::Plus)) {
4118 Parser.Lex(); // Eat the '+' token.
4119 haveEaten = true;
4120 } else if (Tok.is(AsmToken::Minus)) {
4121 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004122 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004123 haveEaten = true;
4124 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004125
4126 SMLoc E = Parser.getTok().getEndLoc();
4127 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004128 if (Reg == -1) {
4129 if (!haveEaten)
4130 return MatchOperand_NoMatch;
4131 Error(Parser.getTok().getLoc(), "register expected");
4132 return MatchOperand_ParseFail;
4133 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004134
Jim Grosbachc320c852011-08-05 21:28:30 +00004135 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4136 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004137 if (Parser.getTok().is(AsmToken::Comma)) {
4138 Parser.Lex(); // Eat the ','.
4139 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4140 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004141
4142 // FIXME: Only approximates end...may include intervening whitespace.
4143 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004144 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004145
4146 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4147 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004148
4149 return MatchOperand_Success;
4150}
4151
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004152ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4153parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4154 // Check for a post-index addressing register operand. Specifically:
4155 // am3offset := '+' register
4156 // | '-' register
4157 // | register
4158 // | # imm
4159 // | # + imm
4160 // | # - imm
4161
4162 // This method must return MatchOperand_NoMatch without consuming any tokens
4163 // in the case where there is no match, as other alternatives take other
4164 // parse methods.
4165 AsmToken Tok = Parser.getTok();
4166 SMLoc S = Tok.getLoc();
4167
4168 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004169 if (Parser.getTok().is(AsmToken::Hash) ||
4170 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004171 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004172 // Explicitly look for a '-', as we need to encode negative zero
4173 // differently.
4174 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4175 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004176 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004177 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004178 return MatchOperand_ParseFail;
4179 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4180 if (!CE) {
4181 Error(S, "constant expression expected");
4182 return MatchOperand_ParseFail;
4183 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004184 // Negative zero is encoded as the flag value INT32_MIN.
4185 int32_t Val = CE->getValue();
4186 if (isNegative && Val == 0)
4187 Val = INT32_MIN;
4188
4189 Operands.push_back(
4190 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4191
4192 return MatchOperand_Success;
4193 }
4194
4195
4196 bool haveEaten = false;
4197 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004198 if (Tok.is(AsmToken::Plus)) {
4199 Parser.Lex(); // Eat the '+' token.
4200 haveEaten = true;
4201 } else if (Tok.is(AsmToken::Minus)) {
4202 Parser.Lex(); // Eat the '-' token.
4203 isAdd = false;
4204 haveEaten = true;
4205 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004206
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004207 Tok = Parser.getTok();
4208 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004209 if (Reg == -1) {
4210 if (!haveEaten)
4211 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004212 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004213 return MatchOperand_ParseFail;
4214 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004215
4216 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004217 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004218
4219 return MatchOperand_Success;
4220}
4221
Tim Northovereb5e4d52013-07-22 09:06:12 +00004222/// Convert parsed operands to MCInst. Needed here because this instruction
4223/// only has two register operands, but multiplication is commutative so
4224/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004225void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004226cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004227 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004228 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4229 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004230 // If we have a three-operand form, make sure to set Rn to be the operand
4231 // that isn't the same as Rd.
4232 unsigned RegOp = 4;
4233 if (Operands.size() == 6 &&
4234 ((ARMOperand*)Operands[4])->getReg() ==
4235 ((ARMOperand*)Operands[3])->getReg())
4236 RegOp = 5;
4237 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4238 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004239 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004240}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004241
Mihai Popaad18d3c2013-08-09 10:38:32 +00004242void ARMAsmParser::
4243cvtThumbBranches(MCInst &Inst,
4244 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4245 int CondOp = -1, ImmOp = -1;
4246 switch(Inst.getOpcode()) {
4247 case ARM::tB:
4248 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4249
4250 case ARM::t2B:
4251 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4252
4253 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4254 }
4255 // first decide whether or not the branch should be conditional
4256 // by looking at it's location relative to an IT block
4257 if(inITBlock()) {
4258 // inside an IT block we cannot have any conditional branches. any
4259 // such instructions needs to be converted to unconditional form
4260 switch(Inst.getOpcode()) {
4261 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4262 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4263 }
4264 } else {
4265 // outside IT blocks we can only have unconditional branches with AL
4266 // condition code or conditional branches with non-AL condition code
4267 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4268 switch(Inst.getOpcode()) {
4269 case ARM::tB:
4270 case ARM::tBcc:
4271 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4272 break;
4273 case ARM::t2B:
4274 case ARM::t2Bcc:
4275 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4276 break;
4277 }
4278 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004279
Mihai Popaad18d3c2013-08-09 10:38:32 +00004280 // now decide on encoding size based on branch target range
4281 switch(Inst.getOpcode()) {
4282 // classify tB as either t2B or t1B based on range of immediate operand
4283 case ARM::tB: {
4284 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4285 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4286 Inst.setOpcode(ARM::t2B);
4287 break;
4288 }
4289 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4290 case ARM::tBcc: {
4291 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4292 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4293 Inst.setOpcode(ARM::t2Bcc);
4294 break;
4295 }
4296 }
4297 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4298 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4299}
4300
Bill Wendlinge18980a2010-11-06 22:36:58 +00004301/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004302/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004303bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004304parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004305 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004306 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004307 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004308 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004309 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004310
Sean Callanan936b0d32010-01-19 21:44:56 +00004311 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004312 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004313 if (BaseRegNum == -1)
4314 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004315
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004316 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004317 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004318 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4319 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004320 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004321
Jim Grosbachd3595712011-08-03 23:50:40 +00004322 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004323 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004324 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004325
Jim Grosbachd3595712011-08-03 23:50:40 +00004326 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004327 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004328
Jim Grosbach40700e02011-09-19 18:42:21 +00004329 // If there's a pre-indexing writeback marker, '!', just add it as a token
4330 // operand. It's rather odd, but syntactically valid.
4331 if (Parser.getTok().is(AsmToken::Exclaim)) {
4332 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4333 Parser.Lex(); // Eat the '!'.
4334 }
4335
Jim Grosbachd3595712011-08-03 23:50:40 +00004336 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004337 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004338
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004339 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4340 "Lost colon or comma in memory operand?!");
4341 if (Tok.is(AsmToken::Comma)) {
4342 Parser.Lex(); // Eat the comma.
4343 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004344
Jim Grosbacha95ec992011-10-11 17:29:55 +00004345 // If we have a ':', it's an alignment specifier.
4346 if (Parser.getTok().is(AsmToken::Colon)) {
4347 Parser.Lex(); // Eat the ':'.
4348 E = Parser.getTok().getLoc();
4349
4350 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004351 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004352 return true;
4353
4354 // The expression has to be a constant. Memory references with relocations
4355 // don't come through here, as they use the <label> forms of the relevant
4356 // instructions.
4357 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4358 if (!CE)
4359 return Error (E, "constant expression expected");
4360
4361 unsigned Align = 0;
4362 switch (CE->getValue()) {
4363 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004364 return Error(E,
4365 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4366 case 16: Align = 2; break;
4367 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004368 case 64: Align = 8; break;
4369 case 128: Align = 16; break;
4370 case 256: Align = 32; break;
4371 }
4372
4373 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004374 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004375 return Error(Parser.getTok().getLoc(), "']' expected");
4376 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004377 Parser.Lex(); // Eat right bracket token.
4378
4379 // Don't worry about range checking the value here. That's handled by
4380 // the is*() predicates.
4381 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4382 ARM_AM::no_shift, 0, Align,
4383 false, S, E));
4384
4385 // If there's a pre-indexing writeback marker, '!', just add it as a token
4386 // operand.
4387 if (Parser.getTok().is(AsmToken::Exclaim)) {
4388 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4389 Parser.Lex(); // Eat the '!'.
4390 }
4391
4392 return false;
4393 }
4394
4395 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004396 // offset. Be friendly and also accept a plain integer (without a leading
4397 // hash) for gas compatibility.
4398 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004399 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004400 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004401 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004402 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004403 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004404
Owen Anderson967674d2011-08-29 19:36:44 +00004405 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004406 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004407 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004408 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004409
4410 // The expression has to be a constant. Memory references with relocations
4411 // don't come through here, as they use the <label> forms of the relevant
4412 // instructions.
4413 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4414 if (!CE)
4415 return Error (E, "constant expression expected");
4416
Owen Anderson967674d2011-08-29 19:36:44 +00004417 // If the constant was #-0, represent it as INT32_MIN.
4418 int32_t Val = CE->getValue();
4419 if (isNegative && Val == 0)
4420 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4421
Jim Grosbachd3595712011-08-03 23:50:40 +00004422 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004423 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004424 return Error(Parser.getTok().getLoc(), "']' expected");
4425 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004426 Parser.Lex(); // Eat right bracket token.
4427
4428 // Don't worry about range checking the value here. That's handled by
4429 // the is*() predicates.
4430 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004431 ARM_AM::no_shift, 0, 0,
4432 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004433
4434 // If there's a pre-indexing writeback marker, '!', just add it as a token
4435 // operand.
4436 if (Parser.getTok().is(AsmToken::Exclaim)) {
4437 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4438 Parser.Lex(); // Eat the '!'.
4439 }
4440
4441 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004442 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004443
4444 // The register offset is optionally preceded by a '+' or '-'
4445 bool isNegative = false;
4446 if (Parser.getTok().is(AsmToken::Minus)) {
4447 isNegative = true;
4448 Parser.Lex(); // Eat the '-'.
4449 } else if (Parser.getTok().is(AsmToken::Plus)) {
4450 // Nothing to do.
4451 Parser.Lex(); // Eat the '+'.
4452 }
4453
4454 E = Parser.getTok().getLoc();
4455 int OffsetRegNum = tryParseRegister();
4456 if (OffsetRegNum == -1)
4457 return Error(E, "register expected");
4458
4459 // If there's a shift operator, handle it.
4460 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004461 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004462 if (Parser.getTok().is(AsmToken::Comma)) {
4463 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004464 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004465 return true;
4466 }
4467
4468 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004469 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004470 return Error(Parser.getTok().getLoc(), "']' expected");
4471 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004472 Parser.Lex(); // Eat right bracket token.
4473
4474 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004475 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004476 S, E));
4477
Jim Grosbachc320c852011-08-05 21:28:30 +00004478 // If there's a pre-indexing writeback marker, '!', just add it as a token
4479 // operand.
4480 if (Parser.getTok().is(AsmToken::Exclaim)) {
4481 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4482 Parser.Lex(); // Eat the '!'.
4483 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004484
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004485 return false;
4486}
4487
Jim Grosbachd3595712011-08-03 23:50:40 +00004488/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004489/// ( lsl | lsr | asr | ror ) , # shift_amount
4490/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004491/// return true if it parses a shift otherwise it returns false.
4492bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4493 unsigned &Amount) {
4494 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004495 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004496 if (Tok.isNot(AsmToken::Identifier))
4497 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004498 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004499 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4500 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004501 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004502 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004503 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004504 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004505 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004506 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004507 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004508 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004509 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004510 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004511 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004512 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004513
Jim Grosbachd3595712011-08-03 23:50:40 +00004514 // rrx stands alone.
4515 Amount = 0;
4516 if (St != ARM_AM::rrx) {
4517 Loc = Parser.getTok().getLoc();
4518 // A '#' and a shift amount.
4519 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004520 if (HashTok.isNot(AsmToken::Hash) &&
4521 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004522 return Error(HashTok.getLoc(), "'#' expected");
4523 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004524
Jim Grosbachd3595712011-08-03 23:50:40 +00004525 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004526 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004527 return true;
4528 // Range check the immediate.
4529 // lsl, ror: 0 <= imm <= 31
4530 // lsr, asr: 0 <= imm <= 32
4531 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4532 if (!CE)
4533 return Error(Loc, "shift amount must be an immediate");
4534 int64_t Imm = CE->getValue();
4535 if (Imm < 0 ||
4536 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4537 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4538 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004539 // If <ShiftTy> #0, turn it into a no_shift.
4540 if (Imm == 0)
4541 St = ARM_AM::lsl;
4542 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4543 if (Imm == 32)
4544 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004545 Amount = Imm;
4546 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004547
4548 return false;
4549}
4550
Jim Grosbache7fbce72011-10-03 23:38:36 +00004551/// parseFPImm - A floating point immediate expression operand.
4552ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4553parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004554 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004555 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004556 // integer only.
4557 //
4558 // This routine still creates a generic Immediate operand, containing
4559 // a bitcast of the 64-bit floating point value. The various operands
4560 // that accept floats can check whether the value is valid for them
4561 // via the standard is*() predicates.
4562
Jim Grosbache7fbce72011-10-03 23:38:36 +00004563 SMLoc S = Parser.getTok().getLoc();
4564
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004565 if (Parser.getTok().isNot(AsmToken::Hash) &&
4566 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004567 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004568
4569 // Disambiguate the VMOV forms that can accept an FP immediate.
4570 // vmov.f32 <sreg>, #imm
4571 // vmov.f64 <dreg>, #imm
4572 // vmov.f32 <dreg>, #imm @ vector f32x2
4573 // vmov.f32 <qreg>, #imm @ vector f32x4
4574 //
4575 // There are also the NEON VMOV instructions which expect an
4576 // integer constant. Make sure we don't try to parse an FPImm
4577 // for these:
4578 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4579 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
David Peixottoa872e0e2014-01-07 18:19:23 +00004580 bool isVmovf = TyOp->isToken() && (TyOp->getToken() == ".f32" ||
4581 TyOp->getToken() == ".f64");
4582 ARMOperand *Mnemonic = static_cast<ARMOperand*>(Operands[0]);
4583 bool isFconst = Mnemonic->isToken() && (Mnemonic->getToken() == "fconstd" ||
4584 Mnemonic->getToken() == "fconsts");
4585 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00004586 return MatchOperand_NoMatch;
4587
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004588 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004589
4590 // Handle negation, as that still comes through as a separate token.
4591 bool isNegative = false;
4592 if (Parser.getTok().is(AsmToken::Minus)) {
4593 isNegative = true;
4594 Parser.Lex();
4595 }
4596 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004597 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00004598 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004599 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004600 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4601 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004602 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004603 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004604 Operands.push_back(ARMOperand::CreateImm(
4605 MCConstantExpr::Create(IntVal, getContext()),
4606 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004607 return MatchOperand_Success;
4608 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004609 // Also handle plain integers. Instructions which allow floating point
4610 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00004611 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00004612 int64_t Val = Tok.getIntVal();
4613 Parser.Lex(); // Eat the token.
4614 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004615 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004616 return MatchOperand_ParseFail;
4617 }
David Peixottoa872e0e2014-01-07 18:19:23 +00004618 float RealVal = ARM_AM::getFPImmFloat(Val);
4619 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
4620
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004621 Operands.push_back(ARMOperand::CreateImm(
4622 MCConstantExpr::Create(Val, getContext()), S,
4623 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004624 return MatchOperand_Success;
4625 }
4626
Jim Grosbach235c8d22012-01-19 02:47:30 +00004627 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004628 return MatchOperand_ParseFail;
4629}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004630
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004631/// Parse a arm instruction operand. For now this parses the operand regardless
4632/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004633bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004634 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004635 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004636
4637 // Check if the current operand has a custom associated parser, if so, try to
4638 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004639 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4640 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004641 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004642 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4643 // there was a match, but an error occurred, in which case, just return that
4644 // the operand parsing failed.
4645 if (ResTy == MatchOperand_ParseFail)
4646 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004647
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004648 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004649 default:
4650 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004651 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004652 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004653 // If we've seen a branch mnemonic, the next operand must be a label. This
4654 // is true even if the label is a register name. So "br r1" means branch to
4655 // label "r1".
4656 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4657 if (!ExpectLabel) {
4658 if (!tryParseRegisterWithWriteBack(Operands))
4659 return false;
4660 int Res = tryParseShiftRegister(Operands);
4661 if (Res == 0) // success
4662 return false;
4663 else if (Res == -1) // irrecoverable error
4664 return true;
4665 // If this is VMRS, check for the apsr_nzcv operand.
4666 if (Mnemonic == "vmrs" &&
4667 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4668 S = Parser.getTok().getLoc();
4669 Parser.Lex();
4670 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4671 return false;
4672 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004673 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004674
4675 // Fall though for the Identifier case that is not a register or a
4676 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004677 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004678 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004679 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004680 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004681 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004682 // This was not a register so parse other operands that start with an
4683 // identifier (like labels) as expressions and create them as immediates.
4684 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004685 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004686 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004687 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004688 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004689 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4690 return false;
4691 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004692 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004693 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004694 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004695 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004696 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004697 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004698 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004699 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004700 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004701
4702 if (Parser.getTok().isNot(AsmToken::Colon)) {
4703 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4704 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004705 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004706 return true;
4707 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4708 if (CE) {
4709 int32_t Val = CE->getValue();
4710 if (isNegative && Val == 0)
4711 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4712 }
4713 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4714 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004715
4716 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00004717 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00004718 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4719 if (Parser.getTok().is(AsmToken::Exclaim)) {
4720 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4721 Parser.getTok().getLoc()));
4722 Parser.Lex(); // Eat exclaim token
4723 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004724 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004725 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004726 // w/ a ':' after the '#', it's just like a plain ':'.
4727 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004728 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004729 case AsmToken::Colon: {
4730 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004731 // FIXME: Check it's an expression prefix,
4732 // e.g. (FOO - :lower16:BAR) isn't legal.
4733 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004734 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004735 return true;
4736
Evan Cheng965b3c72011-01-13 07:58:56 +00004737 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004738 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004739 return true;
4740
Evan Cheng965b3c72011-01-13 07:58:56 +00004741 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004742 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004743 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004744 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004745 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004746 }
David Peixottoe407d092013-12-19 18:12:36 +00004747 case AsmToken::Equal: {
4748 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4749 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4750
David Peixottoe407d092013-12-19 18:12:36 +00004751 Parser.Lex(); // Eat '='
4752 const MCExpr *SubExprVal;
4753 if (getParser().parseExpression(SubExprVal))
4754 return true;
4755 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4756
David Peixottob9b73622014-02-04 17:22:40 +00004757 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00004758 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4759 return false;
4760 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004761 }
4762}
4763
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004764// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004765// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004766bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004767 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004768
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00004769 // consume an optional '#' (GNU compatibility)
4770 if (getLexer().is(AsmToken::Hash))
4771 Parser.Lex();
4772
Jason W Kim1f7bc072011-01-11 23:53:41 +00004773 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004774 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004775 Parser.Lex(); // Eat ':'
4776
4777 if (getLexer().isNot(AsmToken::Identifier)) {
4778 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4779 return true;
4780 }
4781
4782 StringRef IDVal = Parser.getTok().getIdentifier();
4783 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004784 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004785 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004786 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004787 } else {
4788 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4789 return true;
4790 }
4791 Parser.Lex();
4792
4793 if (getLexer().isNot(AsmToken::Colon)) {
4794 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4795 return true;
4796 }
4797 Parser.Lex(); // Eat the last ':'
4798 return false;
4799}
4800
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004801/// \brief Given a mnemonic, split out possible predication code and carry
4802/// setting letters to form a canonical mnemonic and flags.
4803//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004804// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004805// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004806StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004807 unsigned &PredicationCode,
4808 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004809 unsigned &ProcessorIMod,
4810 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004811 PredicationCode = ARMCC::AL;
4812 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004813 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004814
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004815 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004816 //
4817 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004818 if ((Mnemonic == "movs" && isThumb()) ||
4819 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4820 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4821 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4822 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004823 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004824 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4825 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004826 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004827 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004828 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4829 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4830 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004831 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004832
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004833 // First, split out any predication code. Ignore mnemonics we know aren't
4834 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004835 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004836 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004837 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004838 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004839 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4840 .Case("eq", ARMCC::EQ)
4841 .Case("ne", ARMCC::NE)
4842 .Case("hs", ARMCC::HS)
4843 .Case("cs", ARMCC::HS)
4844 .Case("lo", ARMCC::LO)
4845 .Case("cc", ARMCC::LO)
4846 .Case("mi", ARMCC::MI)
4847 .Case("pl", ARMCC::PL)
4848 .Case("vs", ARMCC::VS)
4849 .Case("vc", ARMCC::VC)
4850 .Case("hi", ARMCC::HI)
4851 .Case("ls", ARMCC::LS)
4852 .Case("ge", ARMCC::GE)
4853 .Case("lt", ARMCC::LT)
4854 .Case("gt", ARMCC::GT)
4855 .Case("le", ARMCC::LE)
4856 .Case("al", ARMCC::AL)
4857 .Default(~0U);
4858 if (CC != ~0U) {
4859 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4860 PredicationCode = CC;
4861 }
Bill Wendling193961b2010-10-29 23:50:21 +00004862 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004863
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004864 // Next, determine if we have a carry setting bit. We explicitly ignore all
4865 // the instructions we know end in 's'.
4866 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004867 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004868 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4869 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4870 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004871 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004872 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004873 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004874 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00004875 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004876 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004877 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4878 CarrySetting = true;
4879 }
4880
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004881 // The "cps" instruction can have a interrupt mode operand which is glued into
4882 // the mnemonic. Check if this is the case, split it and parse the imod op
4883 if (Mnemonic.startswith("cps")) {
4884 // Split out any imod code.
4885 unsigned IMod =
4886 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4887 .Case("ie", ARM_PROC::IE)
4888 .Case("id", ARM_PROC::ID)
4889 .Default(~0U);
4890 if (IMod != ~0U) {
4891 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4892 ProcessorIMod = IMod;
4893 }
4894 }
4895
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004896 // The "it" instruction has the condition mask on the end of the mnemonic.
4897 if (Mnemonic.startswith("it")) {
4898 ITMask = Mnemonic.slice(2, Mnemonic.size());
4899 Mnemonic = Mnemonic.slice(0, 2);
4900 }
4901
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004902 return Mnemonic;
4903}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004904
4905/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4906/// inclusion of carry set or predication code operands.
4907//
4908// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004909void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00004910getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4911 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004912 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4913 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004914 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004915 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004916 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004917 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004918 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004919 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004920 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004921 Mnemonic == "mla" || Mnemonic == "smlal" ||
4922 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004923 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004924 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004925 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004926
Tim Northover2c45a382013-06-26 16:52:40 +00004927 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4928 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00004929 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004930 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4931 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004932 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4933 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00004934 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4935 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4936 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00004937 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004938 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004939 } else if (!isThumb()) {
4940 // Some instructions are only predicable in Thumb mode
4941 CanAcceptPredicationCode
4942 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4943 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4944 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4945 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4946 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4947 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4948 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4949 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00004950 if (hasV6MOps())
4951 CanAcceptPredicationCode = Mnemonic != "movs";
4952 else
4953 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004954 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004955 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004956}
4957
Jim Grosbach7283da92011-08-16 21:12:37 +00004958bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4959 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004960 // FIXME: This is all horribly hacky. We really need a better way to deal
4961 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004962
4963 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4964 // another does not. Specifically, the MOVW instruction does not. So we
4965 // special case it here and remove the defaulted (non-setting) cc_out
4966 // operand if that's the instruction we're trying to match.
4967 //
4968 // We do this as post-processing of the explicit operands rather than just
4969 // conditionally adding the cc_out in the first place because we need
4970 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004971 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004972 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4973 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4974 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4975 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004976
4977 // Register-register 'add' for thumb does not have a cc_out operand
4978 // when there are only two register operands.
4979 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4980 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4981 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4982 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4983 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004984 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004985 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4986 // have to check the immediate range here since Thumb2 has a variant
4987 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004988 if (((isThumb() && Mnemonic == "add") ||
4989 (isThumbTwo() && Mnemonic == "sub")) &&
4990 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004991 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4992 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4993 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004994 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004995 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004996 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004997 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004998 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4999 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005000 // selecting via the generic "add" mnemonic, so to know that we
5001 // should remove the cc_out operand, we have to explicitly check that
5002 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005003 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5004 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005005 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5006 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5007 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5008 // Nest conditions rather than one big 'if' statement for readability.
5009 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005010 // If both registers are low, we're in an IT block, and the immediate is
5011 // in range, we should use encoding T1 instead, which has a cc_out.
5012 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005013 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005014 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5015 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5016 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005017 // Check against T3. If the second register is the PC, this is an
5018 // alternate form of ADR, which uses encoding T4, so check for that too.
5019 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5020 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5021 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005022
5023 // Otherwise, we use encoding T4, which does not have a cc_out
5024 // operand.
5025 return true;
5026 }
5027
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005028 // The thumb2 multiply instruction doesn't have a CCOut register, so
5029 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5030 // use the 16-bit encoding or not.
5031 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5032 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5033 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5034 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5035 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5036 // If the registers aren't low regs, the destination reg isn't the
5037 // same as one of the source regs, or the cc_out operand is zero
5038 // outside of an IT block, we have to use the 32-bit encoding, so
5039 // remove the cc_out operand.
5040 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5041 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00005042 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005043 !inITBlock() ||
5044 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5045 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5046 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5047 static_cast<ARMOperand*>(Operands[4])->getReg())))
5048 return true;
5049
Jim Grosbachefa7e952011-11-15 19:55:16 +00005050 // Also check the 'mul' syntax variant that doesn't specify an explicit
5051 // destination register.
5052 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5053 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5054 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5055 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5056 // If the registers aren't low regs or the cc_out operand is zero
5057 // outside of an IT block, we have to use the 32-bit encoding, so
5058 // remove the cc_out operand.
5059 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5060 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5061 !inITBlock()))
5062 return true;
5063
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005064
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005065
Jim Grosbach4b701af2011-08-24 21:42:27 +00005066 // Register-register 'add/sub' for thumb does not have a cc_out operand
5067 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5068 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5069 // right, this will result in better diagnostics (which operand is off)
5070 // anyway.
5071 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5072 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005073 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5074 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005075 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5076 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5077 (Operands.size() == 6 &&
5078 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005079 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005080
Jim Grosbach7283da92011-08-16 21:12:37 +00005081 return false;
5082}
5083
Joey Goulye8602552013-07-19 16:34:16 +00005084bool ARMAsmParser::shouldOmitPredicateOperand(
5085 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5086 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5087 unsigned RegIdx = 3;
5088 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5089 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5090 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5091 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5092 RegIdx = 4;
5093
5094 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5095 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5096 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5097 ARMMCRegisterClasses[ARM::QPRRegClassID]
5098 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5099 return true;
5100 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005101 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005102}
5103
Jim Grosbach12952fe2011-11-11 23:08:10 +00005104static bool isDataTypeToken(StringRef Tok) {
5105 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5106 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5107 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5108 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5109 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5110 Tok == ".f" || Tok == ".d";
5111}
5112
5113// FIXME: This bit should probably be handled via an explicit match class
5114// in the .td files that matches the suffix instead of having it be
5115// a literal string token the way it is now.
5116static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5117 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5118}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005119static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5120 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005121
5122static bool RequiresVFPRegListValidation(StringRef Inst,
5123 bool &AcceptSinglePrecisionOnly,
5124 bool &AcceptDoublePrecisionOnly) {
5125 if (Inst.size() < 7)
5126 return false;
5127
5128 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5129 StringRef AddressingMode = Inst.substr(4, 2);
5130 if (AddressingMode == "ia" || AddressingMode == "db" ||
5131 AddressingMode == "ea" || AddressingMode == "fd") {
5132 AcceptSinglePrecisionOnly = Inst[6] == 's';
5133 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5134 return true;
5135 }
5136 }
5137
5138 return false;
5139}
5140
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005141/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005142bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5143 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005144 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005145 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005146 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005147 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005148 bool AcceptDoublePrecisionOnly;
5149 RequireVFPRegisterListCheck =
5150 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5151 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005152
Jim Grosbach8be2f652011-12-09 23:34:09 +00005153 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005154 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005155 // The generic tblgen'erated code does this later, at the start of
5156 // MatchInstructionImpl(), but that's too late for aliases that include
5157 // any sort of suffix.
5158 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005159 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5160 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005161
Jim Grosbachab5830e2011-12-14 02:16:11 +00005162 // First check for the ARM-specific .req directive.
5163 if (Parser.getTok().is(AsmToken::Identifier) &&
5164 Parser.getTok().getIdentifier() == ".req") {
5165 parseDirectiveReq(Name, NameLoc);
5166 // We always return 'error' for this, as we're done with this
5167 // statement and don't need to match the 'instruction."
5168 return true;
5169 }
5170
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005171 // Create the leading tokens for the mnemonic, split by '.' characters.
5172 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005173 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005174
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005175 // Split out the predication code and carry setting flag from the mnemonic.
5176 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005177 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005178 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005179 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005180 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005181 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005182
Jim Grosbach1c171b12011-08-25 17:23:55 +00005183 // In Thumb1, only the branch (B) instruction can be predicated.
5184 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005185 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005186 return Error(NameLoc, "conditional execution not supported in Thumb1");
5187 }
5188
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005189 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5190
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005191 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5192 // is the mask as it will be for the IT encoding if the conditional
5193 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5194 // where the conditional bit0 is zero, the instruction post-processing
5195 // will adjust the mask accordingly.
5196 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005197 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5198 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005199 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005200 return Error(Loc, "too many conditions on IT instruction");
5201 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005202 unsigned Mask = 8;
5203 for (unsigned i = ITMask.size(); i != 0; --i) {
5204 char pos = ITMask[i - 1];
5205 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005206 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005207 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005208 }
5209 Mask >>= 1;
5210 if (ITMask[i - 1] == 't')
5211 Mask |= 8;
5212 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005213 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005214 }
5215
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005216 // FIXME: This is all a pretty gross hack. We should automatically handle
5217 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005218
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005219 // Next, add the CCOut and ConditionCode operands, if needed.
5220 //
5221 // For mnemonics which can ever incorporate a carry setting bit or predication
5222 // code, our matching model involves us always generating CCOut and
5223 // ConditionCode operands to match the mnemonic "as written" and then we let
5224 // the matcher deal with finding the right instruction or generating an
5225 // appropriate error.
5226 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005227 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005228
Jim Grosbach03a8a162011-07-14 22:04:21 +00005229 // If we had a carry-set on an instruction that can't do that, issue an
5230 // error.
5231 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005232 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005233 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005234 "' can not set flags, but 's' suffix specified");
5235 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005236 // If we had a predication code on an instruction that can't do that, issue an
5237 // error.
5238 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005239 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005240 return Error(NameLoc, "instruction '" + Mnemonic +
5241 "' is not predicable, but condition code specified");
5242 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005243
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005244 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005245 if (CanAcceptCarrySet) {
5246 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005247 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005248 Loc));
5249 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005250
5251 // Add the predication code operand, if necessary.
5252 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005253 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5254 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005255 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005256 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005257 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005258
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005259 // Add the processor imod operand, if necessary.
5260 if (ProcessorIMod) {
5261 Operands.push_back(ARMOperand::CreateImm(
5262 MCConstantExpr::Create(ProcessorIMod, getContext()),
5263 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005264 }
5265
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005266 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005267 while (Next != StringRef::npos) {
5268 Start = Next;
5269 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005270 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005271
Jim Grosbach12952fe2011-11-11 23:08:10 +00005272 // Some NEON instructions have an optional datatype suffix that is
5273 // completely ignored. Check for that.
5274 if (isDataTypeToken(ExtraToken) &&
5275 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5276 continue;
5277
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005278 // For for ARM mode generate an error if the .n qualifier is used.
5279 if (ExtraToken == ".n" && !isThumb()) {
5280 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005281 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005282 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5283 "arm mode");
5284 }
5285
5286 // The .n qualifier is always discarded as that is what the tables
5287 // and matcher expect. In ARM mode the .w qualifier has no effect,
5288 // so discard it to avoid errors that can be caused by the matcher.
5289 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005290 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5291 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5292 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005293 }
5294
5295 // Read the remaining operands.
5296 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005297 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005298 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005299 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005300 return true;
5301 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005302
5303 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005304 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005305
5306 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005307 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005308 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005309 return true;
5310 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005311 }
5312 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005313
Chris Lattnera2a9d162010-09-11 16:18:25 +00005314 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005315 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005316 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005317 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005318 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005319
Chris Lattner91689c12010-09-08 05:10:46 +00005320 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005321
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005322 if (RequireVFPRegisterListCheck) {
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005323 ARMOperand *Op = static_cast<ARMOperand*>(Operands.back());
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005324 if (AcceptSinglePrecisionOnly && !Op->isSPRRegList())
5325 return Error(Op->getStartLoc(),
5326 "VFP/Neon single precision register expected");
5327 if (AcceptDoublePrecisionOnly && !Op->isDPRRegList())
5328 return Error(Op->getStartLoc(),
5329 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005330 }
5331
Jim Grosbach7283da92011-08-16 21:12:37 +00005332 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5333 // do and don't have a cc_out optional-def operand. With some spot-checks
5334 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005335 // parse and adjust accordingly before actually matching. We shouldn't ever
5336 // try to remove a cc_out operand that was explicitly set on the the
5337 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5338 // table driven matcher doesn't fit well with the ARM instruction set.
5339 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005340 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5341 Operands.erase(Operands.begin() + 1);
5342 delete Op;
5343 }
5344
Joey Goulye8602552013-07-19 16:34:16 +00005345 // Some instructions have the same mnemonic, but don't always
5346 // have a predicate. Distinguish them here and delete the
5347 // predicate if needed.
5348 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5349 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5350 Operands.erase(Operands.begin() + 1);
5351 delete Op;
5352 }
5353
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005354 // ARM mode 'blx' need special handling, as the register operand version
5355 // is predicable, but the label operand version is not. So, we can't rely
5356 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005357 // a k_CondCode operand in the list. If we're trying to match the label
5358 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005359 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5360 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5361 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5362 Operands.erase(Operands.begin() + 1);
5363 delete Op;
5364 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005365
Weiming Zhao8f56f882012-11-16 21:55:34 +00005366 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5367 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5368 // a single GPRPair reg operand is used in the .td file to replace the two
5369 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5370 // expressed as a GPRPair, so we have to manually merge them.
5371 // FIXME: We would really like to be able to tablegen'erate this.
5372 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005373 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5374 Mnemonic == "stlexd")) {
5375 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005376 unsigned Idx = isLoad ? 2 : 3;
5377 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5378 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5379
5380 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5381 // Adjust only if Op1 and Op2 are GPRs.
5382 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5383 MRC.contains(Op2->getReg())) {
5384 unsigned Reg1 = Op1->getReg();
5385 unsigned Reg2 = Op2->getReg();
5386 unsigned Rt = MRI->getEncodingValue(Reg1);
5387 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5388
5389 // Rt2 must be Rt + 1 and Rt must be even.
5390 if (Rt + 1 != Rt2 || (Rt & 1)) {
5391 Error(Op2->getStartLoc(), isLoad ?
5392 "destination operands must be sequential" :
5393 "source operands must be sequential");
5394 return true;
5395 }
5396 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5397 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5398 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5399 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5400 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5401 delete Op1;
5402 delete Op2;
5403 }
5404 }
5405
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005406 // GNU Assembler extension (compatibility)
5407 if ((Mnemonic == "ldrd" || Mnemonic == "strd") && !isThumb() &&
5408 Operands.size() == 4) {
5409 ARMOperand *Op = static_cast<ARMOperand *>(Operands[2]);
5410 assert(Op->isReg() && "expected register argument");
5411 assert(MRI->getMatchingSuperReg(Op->getReg(), ARM::gsub_0,
5412 &MRI->getRegClass(ARM::GPRPairRegClassID))
5413 && "expected register pair");
5414 Operands.insert(Operands.begin() + 3,
5415 ARMOperand::CreateReg(Op->getReg() + 1, Op->getStartLoc(),
5416 Op->getEndLoc()));
5417 }
5418
Kevin Enderby78f95722013-07-31 21:05:30 +00005419 // FIXME: As said above, this is all a pretty gross hack. This instruction
5420 // does not fit with other "subs" and tblgen.
5421 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5422 // so the Mnemonic is the original name "subs" and delete the predicate
5423 // operand so it will match the table entry.
5424 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5425 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5426 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5427 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5428 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5429 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5430 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5431 Operands.erase(Operands.begin());
5432 delete Op0;
5433 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5434
5435 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5436 Operands.erase(Operands.begin() + 1);
5437 delete Op1;
5438 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005439 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005440}
5441
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005442// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005443
5444// return 'true' if register list contains non-low GPR registers,
5445// 'false' otherwise. If Reg is in the register list or is HiReg, set
5446// 'containsReg' to true.
5447static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5448 unsigned HiReg, bool &containsReg) {
5449 containsReg = false;
5450 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5451 unsigned OpReg = Inst.getOperand(i).getReg();
5452 if (OpReg == Reg)
5453 containsReg = true;
5454 // Anything other than a low register isn't legal here.
5455 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5456 return true;
5457 }
5458 return false;
5459}
5460
Jim Grosbacha31f2232011-09-07 18:05:34 +00005461// Check if the specified regisgter is in the register list of the inst,
5462// starting at the indicated operand number.
5463static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5464 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5465 unsigned OpReg = Inst.getOperand(i).getReg();
5466 if (OpReg == Reg)
5467 return true;
5468 }
5469 return false;
5470}
5471
Richard Barton8d519fe2013-09-05 14:14:19 +00005472// Return true if instruction has the interesting property of being
5473// allowed in IT blocks, but not being predicable.
5474static bool instIsBreakpoint(const MCInst &Inst) {
5475 return Inst.getOpcode() == ARM::tBKPT ||
5476 Inst.getOpcode() == ARM::BKPT ||
5477 Inst.getOpcode() == ARM::tHLT ||
5478 Inst.getOpcode() == ARM::HLT;
5479
5480}
5481
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005482// FIXME: We would really like to be able to tablegen'erate this.
5483bool ARMAsmParser::
5484validateInstruction(MCInst &Inst,
5485 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005486 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005487 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005488
Jim Grosbached16ec42011-08-29 22:24:09 +00005489 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005490 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005491 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005492 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005493 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005494 if (ITState.FirstCond)
5495 ITState.FirstCond = false;
5496 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005497 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005498 // The instruction must be predicable.
5499 if (!MCID.isPredicable())
5500 return Error(Loc, "instructions in IT block must be predicable");
5501 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005502 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005503 ARMCC::getOppositeCondition(ITState.Cond);
5504 if (Cond != ITCond) {
5505 // Find the condition code Operand to get its SMLoc information.
5506 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005507 for (unsigned I = 1; I < Operands.size(); ++I)
5508 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5509 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005510 return Error(CondLoc, "incorrect condition in IT block; got '" +
5511 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5512 "', but expected '" +
5513 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5514 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005515 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005516 } else if (isThumbTwo() && MCID.isPredicable() &&
5517 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005518 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5519 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005520 return Error(Loc, "predicated instructions must be in IT block");
5521
Tilmann Scheller255722b2013-09-30 16:11:48 +00005522 const unsigned Opcode = Inst.getOpcode();
5523 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005524 case ARM::LDRD:
5525 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005526 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005527 const unsigned RtReg = Inst.getOperand(0).getReg();
5528
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005529 // Rt can't be R14.
5530 if (RtReg == ARM::LR)
5531 return Error(Operands[3]->getStartLoc(),
5532 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005533
5534 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005535 // Rt must be even-numbered.
5536 if ((Rt & 1) == 1)
5537 return Error(Operands[3]->getStartLoc(),
5538 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005539
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005540 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005541 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005542 if (Rt2 != Rt + 1)
5543 return Error(Operands[3]->getStartLoc(),
5544 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005545
5546 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5547 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5548 // For addressing modes with writeback, the base register needs to be
5549 // different from the destination registers.
5550 if (Rn == Rt || Rn == Rt2)
5551 return Error(Operands[3]->getStartLoc(),
5552 "base register needs to be different from destination "
5553 "registers");
5554 }
5555
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005556 return false;
5557 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005558 case ARM::t2LDRDi8:
5559 case ARM::t2LDRD_PRE:
5560 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005561 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005562 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5563 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5564 if (Rt2 == Rt)
5565 return Error(Operands[3]->getStartLoc(),
5566 "destination operands can't be identical");
5567 return false;
5568 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005569 case ARM::STRD: {
5570 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005571 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5572 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005573 if (Rt2 != Rt + 1)
5574 return Error(Operands[3]->getStartLoc(),
5575 "source operands must be sequential");
5576 return false;
5577 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005578 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005579 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005580 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005581 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5582 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005583 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005584 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005585 "source operands must be sequential");
5586 return false;
5587 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005588 case ARM::SBFX:
5589 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005590 // Width must be in range [1, 32-lsb].
5591 unsigned LSB = Inst.getOperand(2).getImm();
5592 unsigned Widthm1 = Inst.getOperand(3).getImm();
5593 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005594 return Error(Operands[5]->getStartLoc(),
5595 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005596 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005597 }
Tim Northover08a86602013-10-22 19:00:39 +00005598 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005599 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005600 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005601 // most cases that are normally illegal for a Thumb1 LDM instruction.
5602 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005603 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005604 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005605 // in the register list.
5606 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005607 bool HasWritebackToken =
Jim Grosbach139acd22011-08-22 23:01:07 +00005608 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5609 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005610 bool ListContainsBase;
5611 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5612 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005613 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005614 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005615 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005616 return Error(Operands[2]->getStartLoc(),
5617 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005618 // If we should not have writeback, there must not be a '!'. This is
5619 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005620 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005621 return Error(Operands[3]->getStartLoc(),
5622 "writeback operator '!' not allowed when base register "
5623 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005624
5625 break;
5626 }
Tim Northover08a86602013-10-22 19:00:39 +00005627 case ARM::LDMIA_UPD:
5628 case ARM::LDMDB_UPD:
5629 case ARM::LDMIB_UPD:
5630 case ARM::LDMDA_UPD:
5631 // ARM variants loading and updating the same register are only officially
5632 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5633 if (!hasV7Ops())
5634 break;
5635 // Fallthrough
5636 case ARM::t2LDMIA_UPD:
5637 case ARM::t2LDMDB_UPD:
5638 case ARM::t2STMIA_UPD:
5639 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005640 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
Tim Northover741e6ef2013-10-24 09:37:18 +00005641 return Error(Operands.back()->getStartLoc(),
5642 "writeback register not allowed in register list");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005643 break;
5644 }
Tim Northover8eaf1542013-11-12 21:32:41 +00005645 case ARM::sysLDMIA_UPD:
5646 case ARM::sysLDMDA_UPD:
5647 case ARM::sysLDMDB_UPD:
5648 case ARM::sysLDMIB_UPD:
5649 if (!listContainsReg(Inst, 3, ARM::PC))
5650 return Error(Operands[4]->getStartLoc(),
5651 "writeback register only allowed on system LDM "
5652 "if PC in register-list");
5653 break;
5654 case ARM::sysSTMIA_UPD:
5655 case ARM::sysSTMDA_UPD:
5656 case ARM::sysSTMDB_UPD:
5657 case ARM::sysSTMIB_UPD:
5658 return Error(Operands[2]->getStartLoc(),
5659 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005660 case ARM::tMUL: {
5661 // The second source operand must be the same register as the destination
5662 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005663 //
5664 // In this case, we must directly check the parsed operands because the
5665 // cvtThumbMultiply() function is written in such a way that it guarantees
5666 // this first statement is always true for the new Inst. Essentially, the
5667 // destination is unconditionally copied into the second source operand
5668 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005669 if (Operands.size() == 6 &&
5670 (((ARMOperand*)Operands[3])->getReg() !=
5671 ((ARMOperand*)Operands[5])->getReg()) &&
5672 (((ARMOperand*)Operands[3])->getReg() !=
5673 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005674 return Error(Operands[3]->getStartLoc(),
5675 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005676 }
5677 break;
5678 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005679 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5680 // so only issue a diagnostic for thumb1. The instructions will be
5681 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005682 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005683 bool ListContainsBase;
5684 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005685 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005686 return Error(Operands[2]->getStartLoc(),
5687 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005688 break;
5689 }
5690 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005691 bool ListContainsBase;
5692 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005693 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005694 return Error(Operands[2]->getStartLoc(),
5695 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005696 break;
5697 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005698 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005699 bool ListContainsBase, InvalidLowList;
5700 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5701 0, ListContainsBase);
5702 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005703 return Error(Operands[4]->getStartLoc(),
5704 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005705
5706 // This would be converted to a 32-bit stm, but that's not valid if the
5707 // writeback register is in the list.
5708 if (InvalidLowList && ListContainsBase)
5709 return Error(Operands[4]->getStartLoc(),
5710 "writeback operator '!' not allowed when base register "
5711 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005712 break;
5713 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005714 case ARM::tADDrSP: {
5715 // If the non-SP source operand and the destination operand are not the
5716 // same, we need thumb2 (for the wide encoding), or we have an error.
5717 if (!isThumbTwo() &&
5718 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5719 return Error(Operands[4]->getStartLoc(),
5720 "source register must be the same as destination");
5721 }
5722 break;
5723 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005724 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005725 case ARM::tB:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005726 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5727 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005728 break;
5729 case ARM::t2B: {
5730 int op = (Operands[2]->isImm()) ? 2 : 3;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005731 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5732 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005733 break;
5734 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005735 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005736 case ARM::tBcc:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005737 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5738 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005739 break;
5740 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005741 int Op = (Operands[2]->isImm()) ? 2 : 3;
5742 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5743 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005744 break;
5745 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005746 }
5747
5748 return false;
5749}
5750
Jim Grosbach1a747242012-01-23 23:45:44 +00005751static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005752 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005753 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005754 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005755 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5756 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5757 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5758 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5759 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5760 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5761 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5762 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5763 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005764
5765 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005766 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5767 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5768 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5769 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5770 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005771
Jim Grosbach1e946a42012-01-24 00:43:12 +00005772 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5773 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5774 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5775 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5776 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005777
Jim Grosbach1e946a42012-01-24 00:43:12 +00005778 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5779 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5780 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5781 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5782 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005783
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005784 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005785 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5786 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5787 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5788 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5789 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5790 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5791 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5792 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5793 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5794 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5795 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5796 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5797 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5798 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5799 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005800
Jim Grosbach1a747242012-01-23 23:45:44 +00005801 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005802 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5803 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5804 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5805 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5806 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5807 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5808 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5809 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5810 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5811 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5812 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5813 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5814 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5815 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5816 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5817 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5818 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5819 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005820
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005821 // VST4LN
5822 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5823 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5824 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5825 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5826 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5827 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5828 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5829 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5830 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5831 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5832 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5833 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5834 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5835 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5836 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5837
Jim Grosbachda70eac2012-01-24 00:58:13 +00005838 // VST4
5839 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5840 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5841 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5842 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5843 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5844 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5845 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5846 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5847 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5848 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5849 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5850 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5851 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5852 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5853 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5854 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5855 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5856 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005857 }
5858}
5859
Jim Grosbach1a747242012-01-23 23:45:44 +00005860static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005861 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005862 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005863 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005864 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5865 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5866 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5867 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5868 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5869 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5870 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5871 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5872 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005873
5874 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005875 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5876 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5877 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5878 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5879 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5880 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5881 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5882 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5883 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5884 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5885 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5886 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5887 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5888 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5889 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005890
Jim Grosbachb78403c2012-01-24 23:47:04 +00005891 // VLD3DUP
5892 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5893 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5894 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5895 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5896 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5897 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5898 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5899 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5900 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5901 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5902 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5903 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5904 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5905 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5906 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5907 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5908 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5909 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5910
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005911 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005912 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5913 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5914 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5915 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5916 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5917 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5918 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5919 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5920 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5921 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5922 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5923 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5924 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5925 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5926 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005927
5928 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005929 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5930 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5931 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5932 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5933 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5934 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5935 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5936 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5937 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5938 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5939 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5940 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5941 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5942 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5943 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5944 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5945 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5946 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005947
Jim Grosbach14952a02012-01-24 18:37:25 +00005948 // VLD4LN
5949 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5950 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5951 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00005952 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00005953 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5954 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5955 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5956 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5957 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5958 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5959 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5960 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5961 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5962 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5963 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5964
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005965 // VLD4DUP
5966 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5967 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5968 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5969 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5970 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5971 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5972 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5973 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5974 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5975 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5976 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5977 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5978 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5979 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5980 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5981 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5982 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5983 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5984
Jim Grosbached561fc2012-01-24 00:43:17 +00005985 // VLD4
5986 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5987 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5988 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5989 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5990 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5991 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5992 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5993 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5994 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5995 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5996 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5997 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5998 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5999 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6000 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6001 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6002 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6003 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006004 }
6005}
6006
Jim Grosbachafad0532011-11-10 23:42:14 +00006007bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006008processInstruction(MCInst &Inst,
6009 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
6010 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006011 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6012 case ARM::LDRT_POST:
6013 case ARM::LDRBT_POST: {
6014 const unsigned Opcode =
6015 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6016 : ARM::LDRBT_POST_IMM;
6017 MCInst TmpInst;
6018 TmpInst.setOpcode(Opcode);
6019 TmpInst.addOperand(Inst.getOperand(0));
6020 TmpInst.addOperand(Inst.getOperand(1));
6021 TmpInst.addOperand(Inst.getOperand(1));
6022 TmpInst.addOperand(MCOperand::CreateReg(0));
6023 TmpInst.addOperand(MCOperand::CreateImm(0));
6024 TmpInst.addOperand(Inst.getOperand(2));
6025 TmpInst.addOperand(Inst.getOperand(3));
6026 Inst = TmpInst;
6027 return true;
6028 }
6029 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6030 case ARM::STRT_POST:
6031 case ARM::STRBT_POST: {
6032 const unsigned Opcode =
6033 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6034 : ARM::STRBT_POST_IMM;
6035 MCInst TmpInst;
6036 TmpInst.setOpcode(Opcode);
6037 TmpInst.addOperand(Inst.getOperand(1));
6038 TmpInst.addOperand(Inst.getOperand(0));
6039 TmpInst.addOperand(Inst.getOperand(1));
6040 TmpInst.addOperand(MCOperand::CreateReg(0));
6041 TmpInst.addOperand(MCOperand::CreateImm(0));
6042 TmpInst.addOperand(Inst.getOperand(2));
6043 TmpInst.addOperand(Inst.getOperand(3));
6044 Inst = TmpInst;
6045 return true;
6046 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006047 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6048 case ARM::ADDri: {
6049 if (Inst.getOperand(1).getReg() != ARM::PC ||
6050 Inst.getOperand(5).getReg() != 0)
6051 return false;
6052 MCInst TmpInst;
6053 TmpInst.setOpcode(ARM::ADR);
6054 TmpInst.addOperand(Inst.getOperand(0));
6055 TmpInst.addOperand(Inst.getOperand(2));
6056 TmpInst.addOperand(Inst.getOperand(3));
6057 TmpInst.addOperand(Inst.getOperand(4));
6058 Inst = TmpInst;
6059 return true;
6060 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006061 // Aliases for alternate PC+imm syntax of LDR instructions.
6062 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006063 // Select the narrow version if the immediate will fit.
6064 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006065 Inst.getOperand(1).getImm() <= 0xff &&
6066 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
6067 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006068 Inst.setOpcode(ARM::tLDRpci);
6069 else
6070 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006071 return true;
6072 case ARM::t2LDRBpcrel:
6073 Inst.setOpcode(ARM::t2LDRBpci);
6074 return true;
6075 case ARM::t2LDRHpcrel:
6076 Inst.setOpcode(ARM::t2LDRHpci);
6077 return true;
6078 case ARM::t2LDRSBpcrel:
6079 Inst.setOpcode(ARM::t2LDRSBpci);
6080 return true;
6081 case ARM::t2LDRSHpcrel:
6082 Inst.setOpcode(ARM::t2LDRSHpci);
6083 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006084 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006085 case ARM::VST1LNdWB_register_Asm_8:
6086 case ARM::VST1LNdWB_register_Asm_16:
6087 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006088 MCInst TmpInst;
6089 // Shuffle the operands around so the lane index operand is in the
6090 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006091 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006092 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006093 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6094 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6095 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6096 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6097 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6098 TmpInst.addOperand(Inst.getOperand(1)); // lane
6099 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6100 TmpInst.addOperand(Inst.getOperand(6));
6101 Inst = TmpInst;
6102 return true;
6103 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006104
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006105 case ARM::VST2LNdWB_register_Asm_8:
6106 case ARM::VST2LNdWB_register_Asm_16:
6107 case ARM::VST2LNdWB_register_Asm_32:
6108 case ARM::VST2LNqWB_register_Asm_16:
6109 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006110 MCInst TmpInst;
6111 // Shuffle the operands around so the lane index operand is in the
6112 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006113 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006114 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006115 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6116 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6117 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6118 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6119 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006120 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6121 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006122 TmpInst.addOperand(Inst.getOperand(1)); // lane
6123 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6124 TmpInst.addOperand(Inst.getOperand(6));
6125 Inst = TmpInst;
6126 return true;
6127 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006128
6129 case ARM::VST3LNdWB_register_Asm_8:
6130 case ARM::VST3LNdWB_register_Asm_16:
6131 case ARM::VST3LNdWB_register_Asm_32:
6132 case ARM::VST3LNqWB_register_Asm_16:
6133 case ARM::VST3LNqWB_register_Asm_32: {
6134 MCInst TmpInst;
6135 // Shuffle the operands around so the lane index operand is in the
6136 // right place.
6137 unsigned Spacing;
6138 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6139 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6140 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6141 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6142 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6143 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6144 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6145 Spacing));
6146 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6147 Spacing * 2));
6148 TmpInst.addOperand(Inst.getOperand(1)); // lane
6149 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6150 TmpInst.addOperand(Inst.getOperand(6));
6151 Inst = TmpInst;
6152 return true;
6153 }
6154
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006155 case ARM::VST4LNdWB_register_Asm_8:
6156 case ARM::VST4LNdWB_register_Asm_16:
6157 case ARM::VST4LNdWB_register_Asm_32:
6158 case ARM::VST4LNqWB_register_Asm_16:
6159 case ARM::VST4LNqWB_register_Asm_32: {
6160 MCInst TmpInst;
6161 // Shuffle the operands around so the lane index operand is in the
6162 // right place.
6163 unsigned Spacing;
6164 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6165 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6166 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6167 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6168 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6169 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6171 Spacing));
6172 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6173 Spacing * 2));
6174 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6175 Spacing * 3));
6176 TmpInst.addOperand(Inst.getOperand(1)); // lane
6177 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6178 TmpInst.addOperand(Inst.getOperand(6));
6179 Inst = TmpInst;
6180 return true;
6181 }
6182
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006183 case ARM::VST1LNdWB_fixed_Asm_8:
6184 case ARM::VST1LNdWB_fixed_Asm_16:
6185 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006186 MCInst TmpInst;
6187 // Shuffle the operands around so the lane index operand is in the
6188 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006189 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006190 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006191 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6192 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6193 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6194 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6195 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6196 TmpInst.addOperand(Inst.getOperand(1)); // lane
6197 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6198 TmpInst.addOperand(Inst.getOperand(5));
6199 Inst = TmpInst;
6200 return true;
6201 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006202
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006203 case ARM::VST2LNdWB_fixed_Asm_8:
6204 case ARM::VST2LNdWB_fixed_Asm_16:
6205 case ARM::VST2LNdWB_fixed_Asm_32:
6206 case ARM::VST2LNqWB_fixed_Asm_16:
6207 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006208 MCInst TmpInst;
6209 // Shuffle the operands around so the lane index operand is in the
6210 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006211 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006212 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006213 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6214 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6215 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6216 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6217 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6219 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006220 TmpInst.addOperand(Inst.getOperand(1)); // lane
6221 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6222 TmpInst.addOperand(Inst.getOperand(5));
6223 Inst = TmpInst;
6224 return true;
6225 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006226
6227 case ARM::VST3LNdWB_fixed_Asm_8:
6228 case ARM::VST3LNdWB_fixed_Asm_16:
6229 case ARM::VST3LNdWB_fixed_Asm_32:
6230 case ARM::VST3LNqWB_fixed_Asm_16:
6231 case ARM::VST3LNqWB_fixed_Asm_32: {
6232 MCInst TmpInst;
6233 // Shuffle the operands around so the lane index operand is in the
6234 // right place.
6235 unsigned Spacing;
6236 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6237 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6238 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6239 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6240 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
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(Inst.getOperand(1)); // lane
6247 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6248 TmpInst.addOperand(Inst.getOperand(5));
6249 Inst = TmpInst;
6250 return true;
6251 }
6252
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006253 case ARM::VST4LNdWB_fixed_Asm_8:
6254 case ARM::VST4LNdWB_fixed_Asm_16:
6255 case ARM::VST4LNdWB_fixed_Asm_32:
6256 case ARM::VST4LNqWB_fixed_Asm_16:
6257 case ARM::VST4LNqWB_fixed_Asm_32: {
6258 MCInst TmpInst;
6259 // Shuffle the operands around so the lane index operand is in the
6260 // right place.
6261 unsigned Spacing;
6262 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6263 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6264 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6265 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6266 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6267 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6268 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6269 Spacing));
6270 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6271 Spacing * 2));
6272 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6273 Spacing * 3));
6274 TmpInst.addOperand(Inst.getOperand(1)); // lane
6275 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6276 TmpInst.addOperand(Inst.getOperand(5));
6277 Inst = TmpInst;
6278 return true;
6279 }
6280
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006281 case ARM::VST1LNdAsm_8:
6282 case ARM::VST1LNdAsm_16:
6283 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006284 MCInst TmpInst;
6285 // Shuffle the operands around so the lane index operand is in the
6286 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006287 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006288 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006289 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6290 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6291 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6292 TmpInst.addOperand(Inst.getOperand(1)); // lane
6293 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6294 TmpInst.addOperand(Inst.getOperand(5));
6295 Inst = TmpInst;
6296 return true;
6297 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006298
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006299 case ARM::VST2LNdAsm_8:
6300 case ARM::VST2LNdAsm_16:
6301 case ARM::VST2LNdAsm_32:
6302 case ARM::VST2LNqAsm_16:
6303 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006304 MCInst TmpInst;
6305 // Shuffle the operands around so the lane index operand is in the
6306 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006307 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006308 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006309 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6310 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6311 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006312 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6313 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006314 TmpInst.addOperand(Inst.getOperand(1)); // lane
6315 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6316 TmpInst.addOperand(Inst.getOperand(5));
6317 Inst = TmpInst;
6318 return true;
6319 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006320
6321 case ARM::VST3LNdAsm_8:
6322 case ARM::VST3LNdAsm_16:
6323 case ARM::VST3LNdAsm_32:
6324 case ARM::VST3LNqAsm_16:
6325 case ARM::VST3LNqAsm_32: {
6326 MCInst TmpInst;
6327 // Shuffle the operands around so the lane index operand is in the
6328 // right place.
6329 unsigned Spacing;
6330 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6331 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6332 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6333 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6334 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6335 Spacing));
6336 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6337 Spacing * 2));
6338 TmpInst.addOperand(Inst.getOperand(1)); // lane
6339 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6340 TmpInst.addOperand(Inst.getOperand(5));
6341 Inst = TmpInst;
6342 return true;
6343 }
6344
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006345 case ARM::VST4LNdAsm_8:
6346 case ARM::VST4LNdAsm_16:
6347 case ARM::VST4LNdAsm_32:
6348 case ARM::VST4LNqAsm_16:
6349 case ARM::VST4LNqAsm_32: {
6350 MCInst TmpInst;
6351 // Shuffle the operands around so the lane index operand is in the
6352 // right place.
6353 unsigned Spacing;
6354 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6355 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6356 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6357 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6359 Spacing));
6360 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6361 Spacing * 2));
6362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6363 Spacing * 3));
6364 TmpInst.addOperand(Inst.getOperand(1)); // lane
6365 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6366 TmpInst.addOperand(Inst.getOperand(5));
6367 Inst = TmpInst;
6368 return true;
6369 }
6370
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006371 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006372 case ARM::VLD1LNdWB_register_Asm_8:
6373 case ARM::VLD1LNdWB_register_Asm_16:
6374 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006375 MCInst TmpInst;
6376 // Shuffle the operands around so the lane index operand is in the
6377 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006378 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006379 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006380 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6381 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6382 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6383 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6384 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6385 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6386 TmpInst.addOperand(Inst.getOperand(1)); // lane
6387 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6388 TmpInst.addOperand(Inst.getOperand(6));
6389 Inst = TmpInst;
6390 return true;
6391 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006392
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006393 case ARM::VLD2LNdWB_register_Asm_8:
6394 case ARM::VLD2LNdWB_register_Asm_16:
6395 case ARM::VLD2LNdWB_register_Asm_32:
6396 case ARM::VLD2LNqWB_register_Asm_16:
6397 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006398 MCInst TmpInst;
6399 // Shuffle the operands around so the lane index operand is in the
6400 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006401 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006402 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006403 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6405 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006406 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6407 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6408 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6409 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6410 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006411 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6412 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006413 TmpInst.addOperand(Inst.getOperand(1)); // lane
6414 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6415 TmpInst.addOperand(Inst.getOperand(6));
6416 Inst = TmpInst;
6417 return true;
6418 }
6419
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006420 case ARM::VLD3LNdWB_register_Asm_8:
6421 case ARM::VLD3LNdWB_register_Asm_16:
6422 case ARM::VLD3LNdWB_register_Asm_32:
6423 case ARM::VLD3LNqWB_register_Asm_16:
6424 case ARM::VLD3LNqWB_register_Asm_32: {
6425 MCInst TmpInst;
6426 // Shuffle the operands around so the lane index operand is in the
6427 // right place.
6428 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006429 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006430 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6431 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6432 Spacing));
6433 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006434 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006435 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6436 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6437 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6438 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6439 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6440 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6441 Spacing));
6442 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006443 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006444 TmpInst.addOperand(Inst.getOperand(1)); // lane
6445 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6446 TmpInst.addOperand(Inst.getOperand(6));
6447 Inst = TmpInst;
6448 return true;
6449 }
6450
Jim Grosbach14952a02012-01-24 18:37:25 +00006451 case ARM::VLD4LNdWB_register_Asm_8:
6452 case ARM::VLD4LNdWB_register_Asm_16:
6453 case ARM::VLD4LNdWB_register_Asm_32:
6454 case ARM::VLD4LNqWB_register_Asm_16:
6455 case ARM::VLD4LNqWB_register_Asm_32: {
6456 MCInst TmpInst;
6457 // Shuffle the operands around so the lane index operand is in the
6458 // right place.
6459 unsigned Spacing;
6460 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6461 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6462 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6463 Spacing));
6464 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6465 Spacing * 2));
6466 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6467 Spacing * 3));
6468 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6469 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6470 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6471 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6472 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6474 Spacing));
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 Spacing * 2));
6477 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6478 Spacing * 3));
6479 TmpInst.addOperand(Inst.getOperand(1)); // lane
6480 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6481 TmpInst.addOperand(Inst.getOperand(6));
6482 Inst = TmpInst;
6483 return true;
6484 }
6485
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006486 case ARM::VLD1LNdWB_fixed_Asm_8:
6487 case ARM::VLD1LNdWB_fixed_Asm_16:
6488 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006489 MCInst TmpInst;
6490 // Shuffle the operands around so the lane index operand is in the
6491 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006492 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006493 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006494 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6495 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6496 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6497 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6498 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6499 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6500 TmpInst.addOperand(Inst.getOperand(1)); // lane
6501 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6502 TmpInst.addOperand(Inst.getOperand(5));
6503 Inst = TmpInst;
6504 return true;
6505 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006506
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006507 case ARM::VLD2LNdWB_fixed_Asm_8:
6508 case ARM::VLD2LNdWB_fixed_Asm_16:
6509 case ARM::VLD2LNdWB_fixed_Asm_32:
6510 case ARM::VLD2LNqWB_fixed_Asm_16:
6511 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006512 MCInst TmpInst;
6513 // Shuffle the operands around so the lane index operand is in the
6514 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006515 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006516 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006517 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006518 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6519 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006520 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6521 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6522 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6523 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6524 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006525 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6526 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006527 TmpInst.addOperand(Inst.getOperand(1)); // lane
6528 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6529 TmpInst.addOperand(Inst.getOperand(5));
6530 Inst = TmpInst;
6531 return true;
6532 }
6533
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006534 case ARM::VLD3LNdWB_fixed_Asm_8:
6535 case ARM::VLD3LNdWB_fixed_Asm_16:
6536 case ARM::VLD3LNdWB_fixed_Asm_32:
6537 case ARM::VLD3LNqWB_fixed_Asm_16:
6538 case ARM::VLD3LNqWB_fixed_Asm_32: {
6539 MCInst TmpInst;
6540 // Shuffle the operands around so the lane index operand is in the
6541 // right place.
6542 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006543 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006544 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6545 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6546 Spacing));
6547 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006548 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006549 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6550 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6551 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6552 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6553 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6555 Spacing));
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006557 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006558 TmpInst.addOperand(Inst.getOperand(1)); // lane
6559 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6560 TmpInst.addOperand(Inst.getOperand(5));
6561 Inst = TmpInst;
6562 return true;
6563 }
6564
Jim Grosbach14952a02012-01-24 18:37:25 +00006565 case ARM::VLD4LNdWB_fixed_Asm_8:
6566 case ARM::VLD4LNdWB_fixed_Asm_16:
6567 case ARM::VLD4LNdWB_fixed_Asm_32:
6568 case ARM::VLD4LNqWB_fixed_Asm_16:
6569 case ARM::VLD4LNqWB_fixed_Asm_32: {
6570 MCInst TmpInst;
6571 // Shuffle the operands around so the lane index operand is in the
6572 // right place.
6573 unsigned Spacing;
6574 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6575 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 Spacing));
6578 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6579 Spacing * 2));
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6581 Spacing * 3));
6582 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6583 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6584 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6585 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6586 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6587 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6588 Spacing));
6589 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6590 Spacing * 2));
6591 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6592 Spacing * 3));
6593 TmpInst.addOperand(Inst.getOperand(1)); // lane
6594 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6595 TmpInst.addOperand(Inst.getOperand(5));
6596 Inst = TmpInst;
6597 return true;
6598 }
6599
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006600 case ARM::VLD1LNdAsm_8:
6601 case ARM::VLD1LNdAsm_16:
6602 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006603 MCInst TmpInst;
6604 // Shuffle the operands around so the lane index operand is in the
6605 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006606 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006607 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006608 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6609 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6610 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6611 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6612 TmpInst.addOperand(Inst.getOperand(1)); // lane
6613 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6614 TmpInst.addOperand(Inst.getOperand(5));
6615 Inst = TmpInst;
6616 return true;
6617 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006618
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006619 case ARM::VLD2LNdAsm_8:
6620 case ARM::VLD2LNdAsm_16:
6621 case ARM::VLD2LNdAsm_32:
6622 case ARM::VLD2LNqAsm_16:
6623 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006624 MCInst TmpInst;
6625 // Shuffle the operands around so the lane index operand is in the
6626 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006627 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006628 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006629 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006630 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6631 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006632 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6633 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6634 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006635 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6636 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006637 TmpInst.addOperand(Inst.getOperand(1)); // lane
6638 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6639 TmpInst.addOperand(Inst.getOperand(5));
6640 Inst = TmpInst;
6641 return true;
6642 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006643
6644 case ARM::VLD3LNdAsm_8:
6645 case ARM::VLD3LNdAsm_16:
6646 case ARM::VLD3LNdAsm_32:
6647 case ARM::VLD3LNqAsm_16:
6648 case ARM::VLD3LNqAsm_32: {
6649 MCInst TmpInst;
6650 // Shuffle the operands around so the lane index operand is in the
6651 // right place.
6652 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006653 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006654 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6656 Spacing));
6657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006658 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006659 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6660 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6661 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6662 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6663 Spacing));
6664 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006665 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006666 TmpInst.addOperand(Inst.getOperand(1)); // lane
6667 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6668 TmpInst.addOperand(Inst.getOperand(5));
6669 Inst = TmpInst;
6670 return true;
6671 }
6672
Jim Grosbach14952a02012-01-24 18:37:25 +00006673 case ARM::VLD4LNdAsm_8:
6674 case ARM::VLD4LNdAsm_16:
6675 case ARM::VLD4LNdAsm_32:
6676 case ARM::VLD4LNqAsm_16:
6677 case ARM::VLD4LNqAsm_32: {
6678 MCInst TmpInst;
6679 // Shuffle the operands around so the lane index operand is in the
6680 // right place.
6681 unsigned Spacing;
6682 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6683 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6684 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6685 Spacing));
6686 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6687 Spacing * 2));
6688 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6689 Spacing * 3));
6690 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6691 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6692 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6693 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6694 Spacing));
6695 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6696 Spacing * 2));
6697 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6698 Spacing * 3));
6699 TmpInst.addOperand(Inst.getOperand(1)); // lane
6700 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6701 TmpInst.addOperand(Inst.getOperand(5));
6702 Inst = TmpInst;
6703 return true;
6704 }
6705
Jim Grosbachb78403c2012-01-24 23:47:04 +00006706 // VLD3DUP single 3-element structure to all lanes instructions.
6707 case ARM::VLD3DUPdAsm_8:
6708 case ARM::VLD3DUPdAsm_16:
6709 case ARM::VLD3DUPdAsm_32:
6710 case ARM::VLD3DUPqAsm_8:
6711 case ARM::VLD3DUPqAsm_16:
6712 case ARM::VLD3DUPqAsm_32: {
6713 MCInst TmpInst;
6714 unsigned Spacing;
6715 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6716 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6717 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6718 Spacing));
6719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6720 Spacing * 2));
6721 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6722 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6723 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6724 TmpInst.addOperand(Inst.getOperand(4));
6725 Inst = TmpInst;
6726 return true;
6727 }
6728
6729 case ARM::VLD3DUPdWB_fixed_Asm_8:
6730 case ARM::VLD3DUPdWB_fixed_Asm_16:
6731 case ARM::VLD3DUPdWB_fixed_Asm_32:
6732 case ARM::VLD3DUPqWB_fixed_Asm_8:
6733 case ARM::VLD3DUPqWB_fixed_Asm_16:
6734 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6735 MCInst TmpInst;
6736 unsigned Spacing;
6737 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6738 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6739 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6740 Spacing));
6741 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6742 Spacing * 2));
6743 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6744 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6745 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6746 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6747 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6748 TmpInst.addOperand(Inst.getOperand(4));
6749 Inst = TmpInst;
6750 return true;
6751 }
6752
6753 case ARM::VLD3DUPdWB_register_Asm_8:
6754 case ARM::VLD3DUPdWB_register_Asm_16:
6755 case ARM::VLD3DUPdWB_register_Asm_32:
6756 case ARM::VLD3DUPqWB_register_Asm_8:
6757 case ARM::VLD3DUPqWB_register_Asm_16:
6758 case ARM::VLD3DUPqWB_register_Asm_32: {
6759 MCInst TmpInst;
6760 unsigned Spacing;
6761 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6762 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6763 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6764 Spacing));
6765 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6766 Spacing * 2));
6767 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6768 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6769 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6770 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6771 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6772 TmpInst.addOperand(Inst.getOperand(5));
6773 Inst = TmpInst;
6774 return true;
6775 }
6776
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006777 // VLD3 multiple 3-element structure instructions.
6778 case ARM::VLD3dAsm_8:
6779 case ARM::VLD3dAsm_16:
6780 case ARM::VLD3dAsm_32:
6781 case ARM::VLD3qAsm_8:
6782 case ARM::VLD3qAsm_16:
6783 case ARM::VLD3qAsm_32: {
6784 MCInst TmpInst;
6785 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006786 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006787 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6788 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6789 Spacing));
6790 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6791 Spacing * 2));
6792 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6793 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6794 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6795 TmpInst.addOperand(Inst.getOperand(4));
6796 Inst = TmpInst;
6797 return true;
6798 }
6799
6800 case ARM::VLD3dWB_fixed_Asm_8:
6801 case ARM::VLD3dWB_fixed_Asm_16:
6802 case ARM::VLD3dWB_fixed_Asm_32:
6803 case ARM::VLD3qWB_fixed_Asm_8:
6804 case ARM::VLD3qWB_fixed_Asm_16:
6805 case ARM::VLD3qWB_fixed_Asm_32: {
6806 MCInst TmpInst;
6807 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006808 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006809 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6810 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6811 Spacing));
6812 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6813 Spacing * 2));
6814 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6815 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6816 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6817 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6818 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6819 TmpInst.addOperand(Inst.getOperand(4));
6820 Inst = TmpInst;
6821 return true;
6822 }
6823
6824 case ARM::VLD3dWB_register_Asm_8:
6825 case ARM::VLD3dWB_register_Asm_16:
6826 case ARM::VLD3dWB_register_Asm_32:
6827 case ARM::VLD3qWB_register_Asm_8:
6828 case ARM::VLD3qWB_register_Asm_16:
6829 case ARM::VLD3qWB_register_Asm_32: {
6830 MCInst TmpInst;
6831 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006832 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006833 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6834 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6835 Spacing));
6836 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6837 Spacing * 2));
6838 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6839 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6840 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6841 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6842 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6843 TmpInst.addOperand(Inst.getOperand(5));
6844 Inst = TmpInst;
6845 return true;
6846 }
6847
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006848 // VLD4DUP single 3-element structure to all lanes instructions.
6849 case ARM::VLD4DUPdAsm_8:
6850 case ARM::VLD4DUPdAsm_16:
6851 case ARM::VLD4DUPdAsm_32:
6852 case ARM::VLD4DUPqAsm_8:
6853 case ARM::VLD4DUPqAsm_16:
6854 case ARM::VLD4DUPqAsm_32: {
6855 MCInst TmpInst;
6856 unsigned Spacing;
6857 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6858 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6859 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6860 Spacing));
6861 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6862 Spacing * 2));
6863 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6864 Spacing * 3));
6865 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6866 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6867 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6868 TmpInst.addOperand(Inst.getOperand(4));
6869 Inst = TmpInst;
6870 return true;
6871 }
6872
6873 case ARM::VLD4DUPdWB_fixed_Asm_8:
6874 case ARM::VLD4DUPdWB_fixed_Asm_16:
6875 case ARM::VLD4DUPdWB_fixed_Asm_32:
6876 case ARM::VLD4DUPqWB_fixed_Asm_8:
6877 case ARM::VLD4DUPqWB_fixed_Asm_16:
6878 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6879 MCInst TmpInst;
6880 unsigned Spacing;
6881 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6882 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6883 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6884 Spacing));
6885 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6886 Spacing * 2));
6887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6888 Spacing * 3));
6889 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6890 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6891 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6892 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6893 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6894 TmpInst.addOperand(Inst.getOperand(4));
6895 Inst = TmpInst;
6896 return true;
6897 }
6898
6899 case ARM::VLD4DUPdWB_register_Asm_8:
6900 case ARM::VLD4DUPdWB_register_Asm_16:
6901 case ARM::VLD4DUPdWB_register_Asm_32:
6902 case ARM::VLD4DUPqWB_register_Asm_8:
6903 case ARM::VLD4DUPqWB_register_Asm_16:
6904 case ARM::VLD4DUPqWB_register_Asm_32: {
6905 MCInst TmpInst;
6906 unsigned Spacing;
6907 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6908 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6909 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6910 Spacing));
6911 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6912 Spacing * 2));
6913 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6914 Spacing * 3));
6915 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6916 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6917 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6918 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6919 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6920 TmpInst.addOperand(Inst.getOperand(5));
6921 Inst = TmpInst;
6922 return true;
6923 }
6924
6925 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006926 case ARM::VLD4dAsm_8:
6927 case ARM::VLD4dAsm_16:
6928 case ARM::VLD4dAsm_32:
6929 case ARM::VLD4qAsm_8:
6930 case ARM::VLD4qAsm_16:
6931 case ARM::VLD4qAsm_32: {
6932 MCInst TmpInst;
6933 unsigned Spacing;
6934 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6935 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6936 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6937 Spacing));
6938 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6939 Spacing * 2));
6940 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6941 Spacing * 3));
6942 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6943 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6944 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6945 TmpInst.addOperand(Inst.getOperand(4));
6946 Inst = TmpInst;
6947 return true;
6948 }
6949
6950 case ARM::VLD4dWB_fixed_Asm_8:
6951 case ARM::VLD4dWB_fixed_Asm_16:
6952 case ARM::VLD4dWB_fixed_Asm_32:
6953 case ARM::VLD4qWB_fixed_Asm_8:
6954 case ARM::VLD4qWB_fixed_Asm_16:
6955 case ARM::VLD4qWB_fixed_Asm_32: {
6956 MCInst TmpInst;
6957 unsigned Spacing;
6958 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6959 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6960 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6961 Spacing));
6962 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6963 Spacing * 2));
6964 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6965 Spacing * 3));
6966 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6967 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6968 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6969 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6970 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6971 TmpInst.addOperand(Inst.getOperand(4));
6972 Inst = TmpInst;
6973 return true;
6974 }
6975
6976 case ARM::VLD4dWB_register_Asm_8:
6977 case ARM::VLD4dWB_register_Asm_16:
6978 case ARM::VLD4dWB_register_Asm_32:
6979 case ARM::VLD4qWB_register_Asm_8:
6980 case ARM::VLD4qWB_register_Asm_16:
6981 case ARM::VLD4qWB_register_Asm_32: {
6982 MCInst TmpInst;
6983 unsigned Spacing;
6984 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6985 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6986 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6987 Spacing));
6988 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6989 Spacing * 2));
6990 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6991 Spacing * 3));
6992 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6993 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6994 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6995 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6996 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6997 TmpInst.addOperand(Inst.getOperand(5));
6998 Inst = TmpInst;
6999 return true;
7000 }
7001
Jim Grosbach1a747242012-01-23 23:45:44 +00007002 // VST3 multiple 3-element structure instructions.
7003 case ARM::VST3dAsm_8:
7004 case ARM::VST3dAsm_16:
7005 case ARM::VST3dAsm_32:
7006 case ARM::VST3qAsm_8:
7007 case ARM::VST3qAsm_16:
7008 case ARM::VST3qAsm_32: {
7009 MCInst TmpInst;
7010 unsigned Spacing;
7011 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7012 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7013 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7014 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7015 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7016 Spacing));
7017 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7018 Spacing * 2));
7019 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7020 TmpInst.addOperand(Inst.getOperand(4));
7021 Inst = TmpInst;
7022 return true;
7023 }
7024
7025 case ARM::VST3dWB_fixed_Asm_8:
7026 case ARM::VST3dWB_fixed_Asm_16:
7027 case ARM::VST3dWB_fixed_Asm_32:
7028 case ARM::VST3qWB_fixed_Asm_8:
7029 case ARM::VST3qWB_fixed_Asm_16:
7030 case ARM::VST3qWB_fixed_Asm_32: {
7031 MCInst TmpInst;
7032 unsigned Spacing;
7033 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7034 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7035 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7036 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7037 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7038 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7039 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7040 Spacing));
7041 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7042 Spacing * 2));
7043 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7044 TmpInst.addOperand(Inst.getOperand(4));
7045 Inst = TmpInst;
7046 return true;
7047 }
7048
7049 case ARM::VST3dWB_register_Asm_8:
7050 case ARM::VST3dWB_register_Asm_16:
7051 case ARM::VST3dWB_register_Asm_32:
7052 case ARM::VST3qWB_register_Asm_8:
7053 case ARM::VST3qWB_register_Asm_16:
7054 case ARM::VST3qWB_register_Asm_32: {
7055 MCInst TmpInst;
7056 unsigned Spacing;
7057 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7058 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7059 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7060 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7061 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7062 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7063 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7064 Spacing));
7065 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7066 Spacing * 2));
7067 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7068 TmpInst.addOperand(Inst.getOperand(5));
7069 Inst = TmpInst;
7070 return true;
7071 }
7072
Jim Grosbachda70eac2012-01-24 00:58:13 +00007073 // VST4 multiple 3-element structure instructions.
7074 case ARM::VST4dAsm_8:
7075 case ARM::VST4dAsm_16:
7076 case ARM::VST4dAsm_32:
7077 case ARM::VST4qAsm_8:
7078 case ARM::VST4qAsm_16:
7079 case ARM::VST4qAsm_32: {
7080 MCInst TmpInst;
7081 unsigned Spacing;
7082 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7083 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7084 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7085 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7086 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7087 Spacing));
7088 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7089 Spacing * 2));
7090 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7091 Spacing * 3));
7092 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7093 TmpInst.addOperand(Inst.getOperand(4));
7094 Inst = TmpInst;
7095 return true;
7096 }
7097
7098 case ARM::VST4dWB_fixed_Asm_8:
7099 case ARM::VST4dWB_fixed_Asm_16:
7100 case ARM::VST4dWB_fixed_Asm_32:
7101 case ARM::VST4qWB_fixed_Asm_8:
7102 case ARM::VST4qWB_fixed_Asm_16:
7103 case ARM::VST4qWB_fixed_Asm_32: {
7104 MCInst TmpInst;
7105 unsigned Spacing;
7106 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7107 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7108 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7109 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7110 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7111 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7113 Spacing));
7114 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7115 Spacing * 2));
7116 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7117 Spacing * 3));
7118 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7119 TmpInst.addOperand(Inst.getOperand(4));
7120 Inst = TmpInst;
7121 return true;
7122 }
7123
7124 case ARM::VST4dWB_register_Asm_8:
7125 case ARM::VST4dWB_register_Asm_16:
7126 case ARM::VST4dWB_register_Asm_32:
7127 case ARM::VST4qWB_register_Asm_8:
7128 case ARM::VST4qWB_register_Asm_16:
7129 case ARM::VST4qWB_register_Asm_32: {
7130 MCInst TmpInst;
7131 unsigned Spacing;
7132 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7133 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7134 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7135 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7136 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7137 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7138 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7139 Spacing));
7140 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7141 Spacing * 2));
7142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7143 Spacing * 3));
7144 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7145 TmpInst.addOperand(Inst.getOperand(5));
7146 Inst = TmpInst;
7147 return true;
7148 }
7149
Jim Grosbachad66de12012-04-11 00:15:16 +00007150 // Handle encoding choice for the shift-immediate instructions.
7151 case ARM::t2LSLri:
7152 case ARM::t2LSRri:
7153 case ARM::t2ASRri: {
7154 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7155 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7156 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7157 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7158 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7159 unsigned NewOpc;
7160 switch (Inst.getOpcode()) {
7161 default: llvm_unreachable("unexpected opcode");
7162 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7163 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7164 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7165 }
7166 // The Thumb1 operands aren't in the same order. Awesome, eh?
7167 MCInst TmpInst;
7168 TmpInst.setOpcode(NewOpc);
7169 TmpInst.addOperand(Inst.getOperand(0));
7170 TmpInst.addOperand(Inst.getOperand(5));
7171 TmpInst.addOperand(Inst.getOperand(1));
7172 TmpInst.addOperand(Inst.getOperand(2));
7173 TmpInst.addOperand(Inst.getOperand(3));
7174 TmpInst.addOperand(Inst.getOperand(4));
7175 Inst = TmpInst;
7176 return true;
7177 }
7178 return false;
7179 }
7180
Jim Grosbach485e5622011-12-13 22:45:11 +00007181 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007182 case ARM::t2MOVsr:
7183 case ARM::t2MOVSsr: {
7184 // Which instruction to expand to depends on the CCOut operand and
7185 // whether we're in an IT block if the register operands are low
7186 // registers.
7187 bool isNarrow = false;
7188 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7189 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7190 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7191 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7192 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7193 isNarrow = true;
7194 MCInst TmpInst;
7195 unsigned newOpc;
7196 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7197 default: llvm_unreachable("unexpected opcode!");
7198 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7199 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7200 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7201 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7202 }
7203 TmpInst.setOpcode(newOpc);
7204 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7205 if (isNarrow)
7206 TmpInst.addOperand(MCOperand::CreateReg(
7207 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7208 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7209 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7210 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7211 TmpInst.addOperand(Inst.getOperand(5));
7212 if (!isNarrow)
7213 TmpInst.addOperand(MCOperand::CreateReg(
7214 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7215 Inst = TmpInst;
7216 return true;
7217 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007218 case ARM::t2MOVsi:
7219 case ARM::t2MOVSsi: {
7220 // Which instruction to expand to depends on the CCOut operand and
7221 // whether we're in an IT block if the register operands are low
7222 // registers.
7223 bool isNarrow = false;
7224 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7225 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7226 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7227 isNarrow = true;
7228 MCInst TmpInst;
7229 unsigned newOpc;
7230 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7231 default: llvm_unreachable("unexpected opcode!");
7232 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7233 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7234 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7235 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007236 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007237 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007238 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7239 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007240 TmpInst.setOpcode(newOpc);
7241 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7242 if (isNarrow)
7243 TmpInst.addOperand(MCOperand::CreateReg(
7244 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7245 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007246 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007247 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007248 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7249 TmpInst.addOperand(Inst.getOperand(4));
7250 if (!isNarrow)
7251 TmpInst.addOperand(MCOperand::CreateReg(
7252 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7253 Inst = TmpInst;
7254 return true;
7255 }
7256 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007257 case ARM::ASRr:
7258 case ARM::LSRr:
7259 case ARM::LSLr:
7260 case ARM::RORr: {
7261 ARM_AM::ShiftOpc ShiftTy;
7262 switch(Inst.getOpcode()) {
7263 default: llvm_unreachable("unexpected opcode!");
7264 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7265 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7266 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7267 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7268 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007269 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7270 MCInst TmpInst;
7271 TmpInst.setOpcode(ARM::MOVsr);
7272 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7273 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7274 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7275 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7276 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7277 TmpInst.addOperand(Inst.getOperand(4));
7278 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7279 Inst = TmpInst;
7280 return true;
7281 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007282 case ARM::ASRi:
7283 case ARM::LSRi:
7284 case ARM::LSLi:
7285 case ARM::RORi: {
7286 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007287 switch(Inst.getOpcode()) {
7288 default: llvm_unreachable("unexpected opcode!");
7289 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7290 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7291 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7292 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7293 }
7294 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007295 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007296 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007297 // A shift by 32 should be encoded as 0 when permitted
7298 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7299 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007300 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007301 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007302 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007303 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7304 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007305 if (Opc == ARM::MOVsi)
7306 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007307 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7308 TmpInst.addOperand(Inst.getOperand(4));
7309 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7310 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007311 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007312 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007313 case ARM::RRXi: {
7314 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7315 MCInst TmpInst;
7316 TmpInst.setOpcode(ARM::MOVsi);
7317 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7318 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7319 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7320 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7321 TmpInst.addOperand(Inst.getOperand(3));
7322 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7323 Inst = TmpInst;
7324 return true;
7325 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007326 case ARM::t2LDMIA_UPD: {
7327 // If this is a load of a single register, then we should use
7328 // a post-indexed LDR instruction instead, per the ARM ARM.
7329 if (Inst.getNumOperands() != 5)
7330 return false;
7331 MCInst TmpInst;
7332 TmpInst.setOpcode(ARM::t2LDR_POST);
7333 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7334 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7335 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7336 TmpInst.addOperand(MCOperand::CreateImm(4));
7337 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7338 TmpInst.addOperand(Inst.getOperand(3));
7339 Inst = TmpInst;
7340 return true;
7341 }
7342 case ARM::t2STMDB_UPD: {
7343 // If this is a store of a single register, then we should use
7344 // a pre-indexed STR instruction instead, per the ARM ARM.
7345 if (Inst.getNumOperands() != 5)
7346 return false;
7347 MCInst TmpInst;
7348 TmpInst.setOpcode(ARM::t2STR_PRE);
7349 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7350 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7351 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7352 TmpInst.addOperand(MCOperand::CreateImm(-4));
7353 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7354 TmpInst.addOperand(Inst.getOperand(3));
7355 Inst = TmpInst;
7356 return true;
7357 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007358 case ARM::LDMIA_UPD:
7359 // If this is a load of a single register via a 'pop', then we should use
7360 // a post-indexed LDR instruction instead, per the ARM ARM.
7361 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7362 Inst.getNumOperands() == 5) {
7363 MCInst TmpInst;
7364 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7365 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7366 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7367 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7368 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7369 TmpInst.addOperand(MCOperand::CreateImm(4));
7370 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7371 TmpInst.addOperand(Inst.getOperand(3));
7372 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007373 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007374 }
7375 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007376 case ARM::STMDB_UPD:
7377 // If this is a store of a single register via a 'push', then we should use
7378 // a pre-indexed STR instruction instead, per the ARM ARM.
7379 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7380 Inst.getNumOperands() == 5) {
7381 MCInst TmpInst;
7382 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7383 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7384 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7385 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7386 TmpInst.addOperand(MCOperand::CreateImm(-4));
7387 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7388 TmpInst.addOperand(Inst.getOperand(3));
7389 Inst = TmpInst;
7390 }
7391 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007392 case ARM::t2ADDri12:
7393 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7394 // mnemonic was used (not "addw"), encoding T3 is preferred.
7395 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7396 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7397 break;
7398 Inst.setOpcode(ARM::t2ADDri);
7399 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7400 break;
7401 case ARM::t2SUBri12:
7402 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7403 // mnemonic was used (not "subw"), encoding T3 is preferred.
7404 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7405 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7406 break;
7407 Inst.setOpcode(ARM::t2SUBri);
7408 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7409 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007410 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007411 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007412 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7413 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7414 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007415 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007416 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007417 return true;
7418 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007419 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007420 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007421 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007422 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7423 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7424 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007425 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007426 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007427 return true;
7428 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007429 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007430 case ARM::t2ADDri:
7431 case ARM::t2SUBri: {
7432 // If the destination and first source operand are the same, and
7433 // the flags are compatible with the current IT status, use encoding T2
7434 // instead of T3. For compatibility with the system 'as'. Make sure the
7435 // wide encoding wasn't explicit.
7436 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007437 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007438 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7439 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7440 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7441 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7442 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7443 break;
7444 MCInst TmpInst;
7445 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7446 ARM::tADDi8 : ARM::tSUBi8);
7447 TmpInst.addOperand(Inst.getOperand(0));
7448 TmpInst.addOperand(Inst.getOperand(5));
7449 TmpInst.addOperand(Inst.getOperand(0));
7450 TmpInst.addOperand(Inst.getOperand(2));
7451 TmpInst.addOperand(Inst.getOperand(3));
7452 TmpInst.addOperand(Inst.getOperand(4));
7453 Inst = TmpInst;
7454 return true;
7455 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007456 case ARM::t2ADDrr: {
7457 // If the destination and first source operand are the same, and
7458 // there's no setting of the flags, use encoding T2 instead of T3.
7459 // Note that this is only for ADD, not SUB. This mirrors the system
7460 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7461 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7462 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007463 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7464 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007465 break;
7466 MCInst TmpInst;
7467 TmpInst.setOpcode(ARM::tADDhirr);
7468 TmpInst.addOperand(Inst.getOperand(0));
7469 TmpInst.addOperand(Inst.getOperand(0));
7470 TmpInst.addOperand(Inst.getOperand(2));
7471 TmpInst.addOperand(Inst.getOperand(3));
7472 TmpInst.addOperand(Inst.getOperand(4));
7473 Inst = TmpInst;
7474 return true;
7475 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007476 case ARM::tADDrSP: {
7477 // If the non-SP source operand and the destination operand are not the
7478 // same, we need to use the 32-bit encoding if it's available.
7479 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7480 Inst.setOpcode(ARM::t2ADDrr);
7481 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7482 return true;
7483 }
7484 break;
7485 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007486 case ARM::tB:
7487 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007488 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007489 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007490 return true;
7491 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007492 break;
7493 case ARM::t2B:
7494 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007495 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007496 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007497 return true;
7498 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007499 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007500 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007501 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007502 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007503 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007504 return true;
7505 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007506 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007507 case ARM::tBcc:
7508 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007509 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007510 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007511 return true;
7512 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007513 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007514 case ARM::tLDMIA: {
7515 // If the register list contains any high registers, or if the writeback
7516 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7517 // instead if we're in Thumb2. Otherwise, this should have generated
7518 // an error in validateInstruction().
7519 unsigned Rn = Inst.getOperand(0).getReg();
7520 bool hasWritebackToken =
7521 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7522 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7523 bool listContainsBase;
7524 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7525 (!listContainsBase && !hasWritebackToken) ||
7526 (listContainsBase && hasWritebackToken)) {
7527 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7528 assert (isThumbTwo());
7529 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7530 // If we're switching to the updating version, we need to insert
7531 // the writeback tied operand.
7532 if (hasWritebackToken)
7533 Inst.insert(Inst.begin(),
7534 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007535 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007536 }
7537 break;
7538 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007539 case ARM::tSTMIA_UPD: {
7540 // If the register list contains any high registers, we need to use
7541 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7542 // should have generated an error in validateInstruction().
7543 unsigned Rn = Inst.getOperand(0).getReg();
7544 bool listContainsBase;
7545 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7546 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7547 assert (isThumbTwo());
7548 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007549 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007550 }
7551 break;
7552 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007553 case ARM::tPOP: {
7554 bool listContainsBase;
7555 // If the register list contains any high registers, we need to use
7556 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7557 // should have generated an error in validateInstruction().
7558 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007559 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007560 assert (isThumbTwo());
7561 Inst.setOpcode(ARM::t2LDMIA_UPD);
7562 // Add the base register and writeback operands.
7563 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7564 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007565 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007566 }
7567 case ARM::tPUSH: {
7568 bool listContainsBase;
7569 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007570 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007571 assert (isThumbTwo());
7572 Inst.setOpcode(ARM::t2STMDB_UPD);
7573 // Add the base register and writeback operands.
7574 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7575 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007576 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007577 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007578 case ARM::t2MOVi: {
7579 // If we can use the 16-bit encoding and the user didn't explicitly
7580 // request the 32-bit variant, transform it here.
7581 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007582 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007583 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7584 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7585 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007586 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7587 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7588 // The operands aren't in the same order for tMOVi8...
7589 MCInst TmpInst;
7590 TmpInst.setOpcode(ARM::tMOVi8);
7591 TmpInst.addOperand(Inst.getOperand(0));
7592 TmpInst.addOperand(Inst.getOperand(4));
7593 TmpInst.addOperand(Inst.getOperand(1));
7594 TmpInst.addOperand(Inst.getOperand(2));
7595 TmpInst.addOperand(Inst.getOperand(3));
7596 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007597 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007598 }
7599 break;
7600 }
7601 case ARM::t2MOVr: {
7602 // If we can use the 16-bit encoding and the user didn't explicitly
7603 // request the 32-bit variant, transform it here.
7604 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7605 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7606 Inst.getOperand(2).getImm() == ARMCC::AL &&
7607 Inst.getOperand(4).getReg() == ARM::CPSR &&
7608 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7609 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7610 // The operands aren't the same for tMOV[S]r... (no cc_out)
7611 MCInst TmpInst;
7612 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7613 TmpInst.addOperand(Inst.getOperand(0));
7614 TmpInst.addOperand(Inst.getOperand(1));
7615 TmpInst.addOperand(Inst.getOperand(2));
7616 TmpInst.addOperand(Inst.getOperand(3));
7617 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007618 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007619 }
7620 break;
7621 }
Jim Grosbach82213192011-09-19 20:29:33 +00007622 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007623 case ARM::t2SXTB:
7624 case ARM::t2UXTH:
7625 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007626 // If we can use the 16-bit encoding and the user didn't explicitly
7627 // request the 32-bit variant, transform it here.
7628 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7629 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7630 Inst.getOperand(2).getImm() == 0 &&
7631 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7632 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007633 unsigned NewOpc;
7634 switch (Inst.getOpcode()) {
7635 default: llvm_unreachable("Illegal opcode!");
7636 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7637 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7638 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7639 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7640 }
Jim Grosbach82213192011-09-19 20:29:33 +00007641 // The operands aren't the same for thumb1 (no rotate operand).
7642 MCInst TmpInst;
7643 TmpInst.setOpcode(NewOpc);
7644 TmpInst.addOperand(Inst.getOperand(0));
7645 TmpInst.addOperand(Inst.getOperand(1));
7646 TmpInst.addOperand(Inst.getOperand(3));
7647 TmpInst.addOperand(Inst.getOperand(4));
7648 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007649 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007650 }
7651 break;
7652 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007653 case ARM::MOVsi: {
7654 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007655 // rrx shifts and asr/lsr of #32 is encoded as 0
7656 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7657 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007658 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7659 // Shifting by zero is accepted as a vanilla 'MOVr'
7660 MCInst TmpInst;
7661 TmpInst.setOpcode(ARM::MOVr);
7662 TmpInst.addOperand(Inst.getOperand(0));
7663 TmpInst.addOperand(Inst.getOperand(1));
7664 TmpInst.addOperand(Inst.getOperand(3));
7665 TmpInst.addOperand(Inst.getOperand(4));
7666 TmpInst.addOperand(Inst.getOperand(5));
7667 Inst = TmpInst;
7668 return true;
7669 }
7670 return false;
7671 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007672 case ARM::ANDrsi:
7673 case ARM::ORRrsi:
7674 case ARM::EORrsi:
7675 case ARM::BICrsi:
7676 case ARM::SUBrsi:
7677 case ARM::ADDrsi: {
7678 unsigned newOpc;
7679 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7680 if (SOpc == ARM_AM::rrx) return false;
7681 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007682 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007683 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7684 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7685 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7686 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7687 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7688 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7689 }
7690 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007691 // The exception is for right shifts, where 0 == 32
7692 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7693 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007694 MCInst TmpInst;
7695 TmpInst.setOpcode(newOpc);
7696 TmpInst.addOperand(Inst.getOperand(0));
7697 TmpInst.addOperand(Inst.getOperand(1));
7698 TmpInst.addOperand(Inst.getOperand(2));
7699 TmpInst.addOperand(Inst.getOperand(4));
7700 TmpInst.addOperand(Inst.getOperand(5));
7701 TmpInst.addOperand(Inst.getOperand(6));
7702 Inst = TmpInst;
7703 return true;
7704 }
7705 return false;
7706 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007707 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007708 case ARM::t2IT: {
7709 // The mask bits for all but the first condition are represented as
7710 // the low bit of the condition code value implies 't'. We currently
7711 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007712 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007713 MCOperand &MO = Inst.getOperand(1);
7714 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007715 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007716 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007717 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007718 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007719 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007720 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007721 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007722
7723 // Set up the IT block state according to the IT instruction we just
7724 // matched.
7725 assert(!inITBlock() && "nested IT blocks?!");
7726 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7727 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7728 ITState.CurPosition = 0;
7729 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007730 break;
7731 }
Richard Bartona39625e2012-07-09 16:12:24 +00007732 case ARM::t2LSLrr:
7733 case ARM::t2LSRrr:
7734 case ARM::t2ASRrr:
7735 case ARM::t2SBCrr:
7736 case ARM::t2RORrr:
7737 case ARM::t2BICrr:
7738 {
Richard Bartond5660372012-07-09 16:14:28 +00007739 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007740 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7741 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7742 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007743 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7744 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007745 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7746 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7747 unsigned NewOpc;
7748 switch (Inst.getOpcode()) {
7749 default: llvm_unreachable("unexpected opcode");
7750 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7751 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7752 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7753 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7754 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7755 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7756 }
7757 MCInst TmpInst;
7758 TmpInst.setOpcode(NewOpc);
7759 TmpInst.addOperand(Inst.getOperand(0));
7760 TmpInst.addOperand(Inst.getOperand(5));
7761 TmpInst.addOperand(Inst.getOperand(1));
7762 TmpInst.addOperand(Inst.getOperand(2));
7763 TmpInst.addOperand(Inst.getOperand(3));
7764 TmpInst.addOperand(Inst.getOperand(4));
7765 Inst = TmpInst;
7766 return true;
7767 }
7768 return false;
7769 }
7770 case ARM::t2ANDrr:
7771 case ARM::t2EORrr:
7772 case ARM::t2ADCrr:
7773 case ARM::t2ORRrr:
7774 {
Richard Bartond5660372012-07-09 16:14:28 +00007775 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007776 // These instructions are special in that they are commutable, so shorter encodings
7777 // are available more often.
7778 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7779 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7780 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7781 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007782 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7783 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007784 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7785 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7786 unsigned NewOpc;
7787 switch (Inst.getOpcode()) {
7788 default: llvm_unreachable("unexpected opcode");
7789 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7790 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7791 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7792 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7793 }
7794 MCInst TmpInst;
7795 TmpInst.setOpcode(NewOpc);
7796 TmpInst.addOperand(Inst.getOperand(0));
7797 TmpInst.addOperand(Inst.getOperand(5));
7798 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7799 TmpInst.addOperand(Inst.getOperand(1));
7800 TmpInst.addOperand(Inst.getOperand(2));
7801 } else {
7802 TmpInst.addOperand(Inst.getOperand(2));
7803 TmpInst.addOperand(Inst.getOperand(1));
7804 }
7805 TmpInst.addOperand(Inst.getOperand(3));
7806 TmpInst.addOperand(Inst.getOperand(4));
7807 Inst = TmpInst;
7808 return true;
7809 }
7810 return false;
7811 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007812 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007813 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007814}
7815
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007816unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7817 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7818 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007819 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007820 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007821 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7822 assert(MCID.hasOptionalDef() &&
7823 "optionally flag setting instruction missing optional def operand");
7824 assert(MCID.NumOperands == Inst.getNumOperands() &&
7825 "operand count mismatch!");
7826 // Find the optional-def operand (cc_out).
7827 unsigned OpNo;
7828 for (OpNo = 0;
7829 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7830 ++OpNo)
7831 ;
7832 // If we're parsing Thumb1, reject it completely.
7833 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7834 return Match_MnemonicFail;
7835 // If we're parsing Thumb2, which form is legal depends on whether we're
7836 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007837 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7838 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007839 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007840 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7841 inITBlock())
7842 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007843 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007844 // Some high-register supporting Thumb1 encodings only allow both registers
7845 // to be from r0-r7 when in Thumb2.
7846 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7847 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7848 isARMLowRegister(Inst.getOperand(2).getReg()))
7849 return Match_RequiresThumb2;
7850 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007851 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007852 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7853 isARMLowRegister(Inst.getOperand(1).getReg()))
7854 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007855 return Match_Success;
7856}
7857
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00007858template<> inline bool IsCPSRDead<MCInst>(MCInst* Instr) {
7859 return true; // In an assembly source, no need to second-guess
7860}
7861
Jim Grosbach5117ef72012-04-24 22:40:08 +00007862static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007863bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007864MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007865 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007866 MCStreamer &Out, unsigned &ErrorInfo,
7867 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007868 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007869 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007870
Chad Rosier2f480a82012-10-12 22:53:36 +00007871 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007872 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007873 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007874 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007875 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007876 // Context sensitive operand constraints aren't handled by the matcher,
7877 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007878 if (validateInstruction(Inst, Operands)) {
7879 // Still progress the IT block, otherwise one wrong condition causes
7880 // nasty cascading errors.
7881 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007882 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007883 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007884
Amara Emerson52cfb6a2013-10-03 09:31:51 +00007885 { // processInstruction() updates inITBlock state, we need to save it away
7886 bool wasInITBlock = inITBlock();
7887
7888 // Some instructions need post-processing to, for example, tweak which
7889 // encoding is selected. Loop on it while changes happen so the
7890 // individual transformations can chain off each other. E.g.,
7891 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7892 while (processInstruction(Inst, Operands))
7893 ;
7894
7895 // Only after the instruction is fully processed, we can validate it
7896 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00007897 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00007898 Warning(IDLoc, "deprecated instruction in IT block");
7899 }
7900 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007901
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007902 // Only move forward at the very end so that everything in validate
7903 // and process gets a consistent answer about whether we're in an IT
7904 // block.
7905 forwardITPosition();
7906
Jim Grosbach82f76d12012-01-25 19:52:01 +00007907 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7908 // doesn't actually encode.
7909 if (Inst.getOpcode() == ARM::ITasm)
7910 return false;
7911
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007912 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00007913 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00007914 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007915 case Match_MissingFeature: {
7916 assert(ErrorInfo && "Unknown missing feature!");
7917 // Special case the error message for the very common case where only
7918 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7919 std::string Msg = "instruction requires:";
7920 unsigned Mask = 1;
7921 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7922 if (ErrorInfo & Mask) {
7923 Msg += " ";
7924 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7925 }
7926 Mask <<= 1;
7927 }
7928 return Error(IDLoc, Msg);
7929 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007930 case Match_InvalidOperand: {
7931 SMLoc ErrorLoc = IDLoc;
7932 if (ErrorInfo != ~0U) {
7933 if (ErrorInfo >= Operands.size())
7934 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007935
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007936 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7937 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7938 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007939
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007940 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007941 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007942 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007943 return Error(IDLoc, "invalid instruction",
7944 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007945 case Match_RequiresNotITBlock:
7946 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007947 case Match_RequiresITBlock:
7948 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007949 case Match_RequiresV6:
7950 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7951 case Match_RequiresThumb2:
7952 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007953 case Match_ImmRange0_15: {
7954 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7955 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7956 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7957 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00007958 case Match_ImmRange0_239: {
7959 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7960 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7961 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7962 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007963 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007964
Eric Christopher91d7b902010-10-29 09:26:59 +00007965 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007966}
7967
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007968/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007969bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7970 StringRef IDVal = DirectiveID.getIdentifier();
7971 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00007972 return parseLiteralValues(4, DirectiveID.getLoc());
7973 else if (IDVal == ".short" || IDVal == ".hword")
7974 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007975 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007976 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007977 else if (IDVal == ".arm")
7978 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007979 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007980 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007981 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007982 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007983 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007984 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007985 else if (IDVal == ".unreq")
7986 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007987 else if (IDVal == ".arch")
7988 return parseDirectiveArch(DirectiveID.getLoc());
7989 else if (IDVal == ".eabi_attribute")
7990 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien8cbb80d2013-10-28 17:51:12 +00007991 else if (IDVal == ".cpu")
7992 return parseDirectiveCPU(DirectiveID.getLoc());
7993 else if (IDVal == ".fpu")
7994 return parseDirectiveFPU(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007995 else if (IDVal == ".fnstart")
7996 return parseDirectiveFnStart(DirectiveID.getLoc());
7997 else if (IDVal == ".fnend")
7998 return parseDirectiveFnEnd(DirectiveID.getLoc());
7999 else if (IDVal == ".cantunwind")
8000 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8001 else if (IDVal == ".personality")
8002 return parseDirectivePersonality(DirectiveID.getLoc());
8003 else if (IDVal == ".handlerdata")
8004 return parseDirectiveHandlerData(DirectiveID.getLoc());
8005 else if (IDVal == ".setfp")
8006 return parseDirectiveSetFP(DirectiveID.getLoc());
8007 else if (IDVal == ".pad")
8008 return parseDirectivePad(DirectiveID.getLoc());
8009 else if (IDVal == ".save")
8010 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8011 else if (IDVal == ".vsave")
8012 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008013 else if (IDVal == ".inst")
8014 return parseDirectiveInst(DirectiveID.getLoc());
8015 else if (IDVal == ".inst.n")
8016 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8017 else if (IDVal == ".inst.w")
8018 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008019 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008020 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008021 else if (IDVal == ".even")
8022 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008023 else if (IDVal == ".personalityindex")
8024 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008025 else if (IDVal == ".unwind_raw")
8026 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00008027 else if (IDVal == ".tlsdescseq")
8028 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008029 else if (IDVal == ".movsp")
8030 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00008031 else if (IDVal == ".object_arch")
8032 return parseDirectiveObjectArch(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008033 else if (IDVal == ".arch_extension")
8034 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008035 else if (IDVal == ".align")
8036 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008037 else if (IDVal == ".thumb_set")
8038 return parseDirectiveThumbSet(DirectiveID.getLoc());
Kevin Enderbyccab3172009-09-15 00:27:25 +00008039 return true;
8040}
8041
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008042/// parseLiteralValues
8043/// ::= .hword expression [, expression]*
8044/// ::= .short expression [, expression]*
8045/// ::= .word expression [, expression]*
8046bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00008047 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8048 for (;;) {
8049 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008050 if (getParser().parseExpression(Value)) {
8051 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008052 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008053 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008054
Eric Christopherbf7bc492013-01-09 03:52:05 +00008055 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008056
8057 if (getLexer().is(AsmToken::EndOfStatement))
8058 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008059
Kevin Enderbyccab3172009-09-15 00:27:25 +00008060 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008061 if (getLexer().isNot(AsmToken::Comma)) {
8062 Error(L, "unexpected token in directive");
8063 return false;
8064 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008065 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008066 }
8067 }
8068
Sean Callanana83fd7d2010-01-19 20:27:46 +00008069 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008070 return false;
8071}
8072
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008073/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008074/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008075bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008076 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8077 Error(L, "unexpected token in directive");
8078 return false;
8079 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008080 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008081
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008082 if (!hasThumb()) {
8083 Error(L, "target does not support Thumb mode");
8084 return false;
8085 }
Tim Northovera2292d02013-06-10 23:20:58 +00008086
Jim Grosbach7f882392011-12-07 18:04:19 +00008087 if (!isThumb())
8088 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008089
Jim Grosbach7f882392011-12-07 18:04:19 +00008090 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8091 return false;
8092}
8093
8094/// parseDirectiveARM
8095/// ::= .arm
8096bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008097 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8098 Error(L, "unexpected token in directive");
8099 return false;
8100 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008101 Parser.Lex();
8102
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008103 if (!hasARM()) {
8104 Error(L, "target does not support ARM mode");
8105 return false;
8106 }
Tim Northovera2292d02013-06-10 23:20:58 +00008107
Jim Grosbach7f882392011-12-07 18:04:19 +00008108 if (isThumb())
8109 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008110
Jim Grosbach7f882392011-12-07 18:04:19 +00008111 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008112 return false;
8113}
8114
Tim Northover1744d0a2013-10-25 12:49:50 +00008115void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8116 if (NextSymbolIsThumb) {
8117 getParser().getStreamer().EmitThumbFunc(Symbol);
8118 NextSymbolIsThumb = false;
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008119 return;
8120 }
8121
8122 if (!isThumb())
8123 return;
8124
8125 const MCObjectFileInfo::Environment Format =
8126 getContext().getObjectFileInfo()->getObjectFileType();
8127 switch (Format) {
8128 case MCObjectFileInfo::IsCOFF: {
8129 const MCSymbolData &SD =
8130 getParser().getStreamer().getOrCreateSymbolData(Symbol);
8131 char Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
8132 if (SD.getFlags() & (Type << COFF::SF_TypeShift))
8133 getParser().getStreamer().EmitThumbFunc(Symbol);
8134 break;
8135 }
8136 case MCObjectFileInfo::IsELF: {
8137 const MCSymbolData &SD =
8138 getParser().getStreamer().getOrCreateSymbolData(Symbol);
8139 if (MCELF::GetType(SD) & (ELF::STT_FUNC << ELF_STT_Shift))
8140 getParser().getStreamer().EmitThumbFunc(Symbol);
8141 break;
8142 }
8143 case MCObjectFileInfo::IsMachO:
8144 break;
Tim Northover1744d0a2013-10-25 12:49:50 +00008145 }
8146}
8147
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008148/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008149/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008150bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00008151 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8152 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008153
Jim Grosbach1152cc02011-12-21 22:30:16 +00008154 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008155 // ELF doesn't
8156 if (isMachO) {
8157 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008158 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008159 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8160 Error(L, "unexpected token in .thumb_func directive");
8161 return false;
8162 }
8163
Tim Northover1744d0a2013-10-25 12:49:50 +00008164 MCSymbol *Func =
8165 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8166 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008167 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008168 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008169 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008170 }
8171
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008172 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8173 Error(L, "unexpected token in directive");
8174 return false;
8175 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008176
Tim Northover1744d0a2013-10-25 12:49:50 +00008177 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008178 return false;
8179}
8180
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008181/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008182/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008183bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008184 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008185 if (Tok.isNot(AsmToken::Identifier)) {
8186 Error(L, "unexpected token in .syntax directive");
8187 return false;
8188 }
8189
Benjamin Kramer92d89982010-07-14 22:38:02 +00008190 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008191 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008192 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008193 } else if (Mode == "divided" || Mode == "DIVIDED") {
8194 Error(L, "'.syntax divided' arm asssembly not supported");
8195 return false;
8196 } else {
8197 Error(L, "unrecognized syntax mode in .syntax directive");
8198 return false;
8199 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008200
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008201 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8202 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8203 return false;
8204 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008205 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008206
8207 // TODO tell the MC streamer the mode
8208 // getParser().getStreamer().Emit???();
8209 return false;
8210}
8211
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008212/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008213/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008214bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008215 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008216 if (Tok.isNot(AsmToken::Integer)) {
8217 Error(L, "unexpected token in .code directive");
8218 return false;
8219 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008220 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008221 if (Val != 16 && Val != 32) {
8222 Error(L, "invalid operand to .code directive");
8223 return false;
8224 }
8225 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008226
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008227 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8228 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8229 return false;
8230 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008231 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008232
Evan Cheng284b4672011-07-08 22:36:29 +00008233 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008234 if (!hasThumb()) {
8235 Error(L, "target does not support Thumb mode");
8236 return false;
8237 }
Tim Northovera2292d02013-06-10 23:20:58 +00008238
Jim Grosbachf471ac32011-09-06 18:46:23 +00008239 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008240 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008241 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008242 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008243 if (!hasARM()) {
8244 Error(L, "target does not support ARM mode");
8245 return false;
8246 }
Tim Northovera2292d02013-06-10 23:20:58 +00008247
Jim Grosbachf471ac32011-09-06 18:46:23 +00008248 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008249 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008250 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008251 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008252
Kevin Enderby146dcf22009-10-15 20:48:48 +00008253 return false;
8254}
8255
Jim Grosbachab5830e2011-12-14 02:16:11 +00008256/// parseDirectiveReq
8257/// ::= name .req registername
8258bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8259 Parser.Lex(); // Eat the '.req' token.
8260 unsigned Reg;
8261 SMLoc SRegLoc, ERegLoc;
8262 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008263 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008264 Error(SRegLoc, "register name expected");
8265 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008266 }
8267
8268 // Shouldn't be anything else.
8269 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008270 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008271 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8272 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008273 }
8274
8275 Parser.Lex(); // Consume the EndOfStatement
8276
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008277 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8278 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8279 return false;
8280 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00008281
8282 return false;
8283}
8284
8285/// parseDirectiveUneq
8286/// ::= .unreq registername
8287bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8288 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008289 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008290 Error(L, "unexpected input in .unreq directive.");
8291 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008292 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00008293 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008294 Parser.Lex(); // Eat the identifier.
8295 return false;
8296}
8297
Jason W Kim135d2442011-12-20 17:38:12 +00008298/// parseDirectiveArch
8299/// ::= .arch token
8300bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Kevin Enderby89299402014-03-25 00:05:50 +00008301 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8302 bool isMachO = MAI->hasSubsectionsViaSymbols();
8303 if (isMachO) {
8304 Error(L, ".arch directive not valid for Mach-O");
8305 Parser.eatToEndOfStatement();
8306 return false;
8307 }
8308
Logan Chien439e8f92013-12-11 17:16:25 +00008309 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8310
8311 unsigned ID = StringSwitch<unsigned>(Arch)
8312#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8313 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00008314#define ARM_ARCH_ALIAS(NAME, ID) \
8315 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00008316#include "MCTargetDesc/ARMArchName.def"
8317 .Default(ARM::INVALID_ARCH);
8318
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008319 if (ID == ARM::INVALID_ARCH) {
8320 Error(L, "Unknown arch name");
8321 return false;
8322 }
Logan Chien439e8f92013-12-11 17:16:25 +00008323
8324 getTargetStreamer().emitArch(ID);
8325 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008326}
8327
8328/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008329/// ::= .eabi_attribute int, int [, "str"]
8330/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00008331bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Kevin Enderby89299402014-03-25 00:05:50 +00008332 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8333 bool isMachO = MAI->hasSubsectionsViaSymbols();
8334 if (isMachO) {
8335 Error(L, ".eabi_attribute directive not valid for Mach-O");
8336 Parser.eatToEndOfStatement();
8337 return false;
8338 }
8339
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008340 int64_t Tag;
8341 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008342 TagLoc = Parser.getTok().getLoc();
8343 if (Parser.getTok().is(AsmToken::Identifier)) {
8344 StringRef Name = Parser.getTok().getIdentifier();
8345 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
8346 if (Tag == -1) {
8347 Error(TagLoc, "attribute name not recognised: " + Name);
8348 Parser.eatToEndOfStatement();
8349 return false;
8350 }
8351 Parser.Lex();
8352 } else {
8353 const MCExpr *AttrExpr;
8354
8355 TagLoc = Parser.getTok().getLoc();
8356 if (Parser.parseExpression(AttrExpr)) {
8357 Parser.eatToEndOfStatement();
8358 return false;
8359 }
8360
8361 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
8362 if (!CE) {
8363 Error(TagLoc, "expected numeric constant");
8364 Parser.eatToEndOfStatement();
8365 return false;
8366 }
8367
8368 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008369 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008370
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008371 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008372 Error(Parser.getTok().getLoc(), "comma expected");
8373 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008374 return false;
8375 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008376 Parser.Lex(); // skip comma
8377
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008378 StringRef StringValue = "";
8379 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00008380
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008381 int64_t IntegerValue = 0;
8382 bool IsIntegerValue = false;
8383
8384 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
8385 IsStringValue = true;
8386 else if (Tag == ARMBuildAttrs::compatibility) {
8387 IsStringValue = true;
8388 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00008389 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008390 IsIntegerValue = true;
8391 else if (Tag % 2 == 1)
8392 IsStringValue = true;
8393 else
8394 llvm_unreachable("invalid tag type");
8395
8396 if (IsIntegerValue) {
8397 const MCExpr *ValueExpr;
8398 SMLoc ValueExprLoc = Parser.getTok().getLoc();
8399 if (Parser.parseExpression(ValueExpr)) {
8400 Parser.eatToEndOfStatement();
8401 return false;
8402 }
8403
8404 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
8405 if (!CE) {
8406 Error(ValueExprLoc, "expected numeric constant");
8407 Parser.eatToEndOfStatement();
8408 return false;
8409 }
8410
8411 IntegerValue = CE->getValue();
8412 }
8413
8414 if (Tag == ARMBuildAttrs::compatibility) {
8415 if (Parser.getTok().isNot(AsmToken::Comma))
8416 IsStringValue = false;
8417 else
8418 Parser.Lex();
8419 }
8420
8421 if (IsStringValue) {
8422 if (Parser.getTok().isNot(AsmToken::String)) {
8423 Error(Parser.getTok().getLoc(), "bad string constant");
8424 Parser.eatToEndOfStatement();
8425 return false;
8426 }
8427
8428 StringValue = Parser.getTok().getStringContents();
8429 Parser.Lex();
8430 }
8431
8432 if (IsIntegerValue && IsStringValue) {
8433 assert(Tag == ARMBuildAttrs::compatibility);
8434 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
8435 } else if (IsIntegerValue)
8436 getTargetStreamer().emitAttribute(Tag, IntegerValue);
8437 else if (IsStringValue)
8438 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00008439 return false;
8440}
8441
8442/// parseDirectiveCPU
8443/// ::= .cpu str
8444bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
Kevin Enderby89299402014-03-25 00:05:50 +00008445 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8446 bool isMachO = MAI->hasSubsectionsViaSymbols();
8447 if (isMachO) {
8448 Error(L, ".cpu directive not valid for Mach-O");
8449 Parser.eatToEndOfStatement();
8450 return false;
8451 }
8452
Logan Chien8cbb80d2013-10-28 17:51:12 +00008453 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8454 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8455 return false;
8456}
8457
8458/// parseDirectiveFPU
8459/// ::= .fpu str
8460bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
Kevin Enderby89299402014-03-25 00:05:50 +00008461 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8462 bool isMachO = MAI->hasSubsectionsViaSymbols();
8463 if (isMachO) {
8464 Error(L, ".fpu directive not valid for Mach-O");
8465 Parser.eatToEndOfStatement();
8466 return false;
8467 }
8468
Logan Chien8cbb80d2013-10-28 17:51:12 +00008469 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8470
8471 unsigned ID = StringSwitch<unsigned>(FPU)
8472#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8473#include "ARMFPUName.def"
8474 .Default(ARM::INVALID_FPU);
8475
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008476 if (ID == ARM::INVALID_FPU) {
8477 Error(L, "Unknown FPU name");
8478 return false;
8479 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008480
8481 getTargetStreamer().emitFPU(ID);
8482 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008483}
8484
Logan Chien4ea23b52013-05-10 16:17:24 +00008485/// parseDirectiveFnStart
8486/// ::= .fnstart
8487bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Kevin Enderby89299402014-03-25 00:05:50 +00008488 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8489 bool isMachO = MAI->hasSubsectionsViaSymbols();
8490 if (isMachO) {
8491 Error(L, ".fnstart directive not valid for Mach-O");
8492 Parser.eatToEndOfStatement();
8493 return false;
8494 }
8495
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008496 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008497 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008498 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008499 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008500 }
8501
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008502 // Reset the unwind directives parser state
8503 UC.reset();
8504
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008505 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008506
8507 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00008508 return false;
8509}
8510
8511/// parseDirectiveFnEnd
8512/// ::= .fnend
8513bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8514 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008515 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008516 Error(L, ".fnstart must precede .fnend directive");
8517 return false;
8518 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008519
8520 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008521 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008522
8523 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00008524 return false;
8525}
8526
8527/// parseDirectiveCantUnwind
8528/// ::= .cantunwind
8529bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008530 UC.recordCantUnwind(L);
8531
Logan Chien4ea23b52013-05-10 16:17:24 +00008532 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008533 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008534 Error(L, ".fnstart must precede .cantunwind directive");
8535 return false;
8536 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008537 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008538 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008539 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008540 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008541 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008542 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008543 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008544 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008545 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008546 }
8547
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008548 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008549 return false;
8550}
8551
8552/// parseDirectivePersonality
8553/// ::= .personality name
8554bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008555 bool HasExistingPersonality = UC.hasPersonality();
8556
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008557 UC.recordPersonality(L);
8558
Logan Chien4ea23b52013-05-10 16:17:24 +00008559 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008560 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008561 Error(L, ".fnstart must precede .personality directive");
8562 return false;
8563 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008564 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008565 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008566 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008567 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008568 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008569 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008570 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008571 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008572 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008573 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008574 if (HasExistingPersonality) {
8575 Parser.eatToEndOfStatement();
8576 Error(L, "multiple personality directives");
8577 UC.emitPersonalityLocNotes();
8578 return false;
8579 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008580
8581 // Parse the name of the personality routine
8582 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8583 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008584 Error(L, "unexpected input in .personality directive.");
8585 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008586 }
8587 StringRef Name(Parser.getTok().getIdentifier());
8588 Parser.Lex();
8589
8590 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008591 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008592 return false;
8593}
8594
8595/// parseDirectiveHandlerData
8596/// ::= .handlerdata
8597bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008598 UC.recordHandlerData(L);
8599
Logan Chien4ea23b52013-05-10 16:17:24 +00008600 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008601 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008602 Error(L, ".fnstart must precede .personality directive");
8603 return false;
8604 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008605 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008606 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008607 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008608 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008609 }
8610
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008611 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008612 return false;
8613}
8614
8615/// parseDirectiveSetFP
8616/// ::= .setfp fpreg, spreg [, offset]
8617bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8618 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008619 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008620 Error(L, ".fnstart must precede .setfp directive");
8621 return false;
8622 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008623 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008624 Error(L, ".setfp must precede .handlerdata directive");
8625 return false;
8626 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008627
8628 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008629 SMLoc FPRegLoc = Parser.getTok().getLoc();
8630 int FPReg = tryParseRegister();
8631 if (FPReg == -1) {
8632 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008633 return false;
8634 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008635
8636 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008637 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008638 Error(Parser.getTok().getLoc(), "comma expected");
8639 return false;
8640 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008641 Parser.Lex(); // skip comma
8642
8643 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008644 SMLoc SPRegLoc = Parser.getTok().getLoc();
8645 int SPReg = tryParseRegister();
8646 if (SPReg == -1) {
8647 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008648 return false;
8649 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008650
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008651 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
8652 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008653 return false;
8654 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008655
8656 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008657 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00008658
8659 // Parse offset
8660 int64_t Offset = 0;
8661 if (Parser.getTok().is(AsmToken::Comma)) {
8662 Parser.Lex(); // skip comma
8663
8664 if (Parser.getTok().isNot(AsmToken::Hash) &&
8665 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008666 Error(Parser.getTok().getLoc(), "'#' expected");
8667 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008668 }
8669 Parser.Lex(); // skip hash token.
8670
8671 const MCExpr *OffsetExpr;
8672 SMLoc ExLoc = Parser.getTok().getLoc();
8673 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008674 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8675 Error(ExLoc, "malformed setfp offset");
8676 return false;
8677 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008679 if (!CE) {
8680 Error(ExLoc, "setfp offset must be an immediate");
8681 return false;
8682 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008683
8684 Offset = CE->getValue();
8685 }
8686
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008687 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
8688 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008689 return false;
8690}
8691
8692/// parseDirective
8693/// ::= .pad offset
8694bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8695 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008696 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008697 Error(L, ".fnstart must precede .pad directive");
8698 return false;
8699 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008700 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008701 Error(L, ".pad must precede .handlerdata directive");
8702 return false;
8703 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008704
8705 // Parse the offset
8706 if (Parser.getTok().isNot(AsmToken::Hash) &&
8707 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008708 Error(Parser.getTok().getLoc(), "'#' expected");
8709 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008710 }
8711 Parser.Lex(); // skip hash token.
8712
8713 const MCExpr *OffsetExpr;
8714 SMLoc ExLoc = Parser.getTok().getLoc();
8715 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008716 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8717 Error(ExLoc, "malformed pad offset");
8718 return false;
8719 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008721 if (!CE) {
8722 Error(ExLoc, "pad offset must be an immediate");
8723 return false;
8724 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008725
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008726 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008727 return false;
8728}
8729
8730/// parseDirectiveRegSave
8731/// ::= .save { registers }
8732/// ::= .vsave { registers }
8733bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8734 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008735 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008736 Error(L, ".fnstart must precede .save or .vsave directives");
8737 return false;
8738 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008739 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008740 Error(L, ".save or .vsave must precede .handlerdata directive");
8741 return false;
8742 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008743
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008744 // RAII object to make sure parsed operands are deleted.
8745 struct CleanupObject {
8746 SmallVector<MCParsedAsmOperand *, 1> Operands;
8747 ~CleanupObject() {
8748 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8749 delete Operands[I];
8750 }
8751 } CO;
8752
Logan Chien4ea23b52013-05-10 16:17:24 +00008753 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008754 if (parseRegisterList(CO.Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008755 return false;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008756 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008757 if (!IsVector && !Op->isRegList()) {
8758 Error(L, ".save expects GPR registers");
8759 return false;
8760 }
8761 if (IsVector && !Op->isDPRRegList()) {
8762 Error(L, ".vsave expects DPR registers");
8763 return false;
8764 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008765
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008766 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008767 return false;
8768}
8769
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008770/// parseDirectiveInst
8771/// ::= .inst opcode [, ...]
8772/// ::= .inst.n opcode [, ...]
8773/// ::= .inst.w opcode [, ...]
8774bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
Kevin Enderby89299402014-03-25 00:05:50 +00008775 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8776 bool isMachO = MAI->hasSubsectionsViaSymbols();
8777 if (isMachO) {
8778 Error(Loc, ".inst directive not valid for Mach-O");
8779 Parser.eatToEndOfStatement();
8780 return false;
8781 }
8782
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008783 int Width;
8784
8785 if (isThumb()) {
8786 switch (Suffix) {
8787 case 'n':
8788 Width = 2;
8789 break;
8790 case 'w':
8791 Width = 4;
8792 break;
8793 default:
8794 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008795 Error(Loc, "cannot determine Thumb instruction size, "
8796 "use inst.n/inst.w instead");
8797 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008798 }
8799 } else {
8800 if (Suffix) {
8801 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008802 Error(Loc, "width suffixes are invalid in ARM mode");
8803 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008804 }
8805 Width = 4;
8806 }
8807
8808 if (getLexer().is(AsmToken::EndOfStatement)) {
8809 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008810 Error(Loc, "expected expression following directive");
8811 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008812 }
8813
8814 for (;;) {
8815 const MCExpr *Expr;
8816
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008817 if (getParser().parseExpression(Expr)) {
8818 Error(Loc, "expected expression");
8819 return false;
8820 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008821
8822 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008823 if (!Value) {
8824 Error(Loc, "expected constant expression");
8825 return false;
8826 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008827
8828 switch (Width) {
8829 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008830 if (Value->getValue() > 0xffff) {
8831 Error(Loc, "inst.n operand is too big, use inst.w instead");
8832 return false;
8833 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008834 break;
8835 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008836 if (Value->getValue() > 0xffffffff) {
8837 Error(Loc,
8838 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8839 return false;
8840 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008841 break;
8842 default:
8843 llvm_unreachable("only supported widths are 2 and 4");
8844 }
8845
8846 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8847
8848 if (getLexer().is(AsmToken::EndOfStatement))
8849 break;
8850
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008851 if (getLexer().isNot(AsmToken::Comma)) {
8852 Error(Loc, "unexpected token in directive");
8853 return false;
8854 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008855
8856 Parser.Lex();
8857 }
8858
8859 Parser.Lex();
8860 return false;
8861}
8862
David Peixotto80c083a2013-12-19 18:26:07 +00008863/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008864/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00008865bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00008866 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00008867 return false;
8868}
8869
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008870bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
8871 const MCSection *Section = getStreamer().getCurrentSection().first;
8872
8873 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8874 TokError("unexpected token in directive");
8875 return false;
8876 }
8877
8878 if (!Section) {
Rafael Espindolaf1440342014-01-23 23:14:14 +00008879 getStreamer().InitSections();
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008880 Section = getStreamer().getCurrentSection().first;
8881 }
8882
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00008883 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008884 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00008885 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008886 else
Rafael Espindola7b514962014-02-04 18:34:04 +00008887 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008888
8889 return false;
8890}
8891
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008892/// parseDirectivePersonalityIndex
8893/// ::= .personalityindex index
8894bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
8895 bool HasExistingPersonality = UC.hasPersonality();
8896
8897 UC.recordPersonalityIndex(L);
8898
8899 if (!UC.hasFnStart()) {
8900 Parser.eatToEndOfStatement();
8901 Error(L, ".fnstart must precede .personalityindex directive");
8902 return false;
8903 }
8904 if (UC.cantUnwind()) {
8905 Parser.eatToEndOfStatement();
8906 Error(L, ".personalityindex cannot be used with .cantunwind");
8907 UC.emitCantUnwindLocNotes();
8908 return false;
8909 }
8910 if (UC.hasHandlerData()) {
8911 Parser.eatToEndOfStatement();
8912 Error(L, ".personalityindex must precede .handlerdata directive");
8913 UC.emitHandlerDataLocNotes();
8914 return false;
8915 }
8916 if (HasExistingPersonality) {
8917 Parser.eatToEndOfStatement();
8918 Error(L, "multiple personality directives");
8919 UC.emitPersonalityLocNotes();
8920 return false;
8921 }
8922
8923 const MCExpr *IndexExpression;
8924 SMLoc IndexLoc = Parser.getTok().getLoc();
8925 if (Parser.parseExpression(IndexExpression)) {
8926 Parser.eatToEndOfStatement();
8927 return false;
8928 }
8929
8930 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
8931 if (!CE) {
8932 Parser.eatToEndOfStatement();
8933 Error(IndexLoc, "index must be a constant number");
8934 return false;
8935 }
8936 if (CE->getValue() < 0 ||
8937 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
8938 Parser.eatToEndOfStatement();
8939 Error(IndexLoc, "personality routine index should be in range [0-3]");
8940 return false;
8941 }
8942
8943 getTargetStreamer().emitPersonalityIndex(CE->getValue());
8944 return false;
8945}
8946
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008947/// parseDirectiveUnwindRaw
8948/// ::= .unwind_raw offset, opcode [, opcode...]
8949bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
8950 if (!UC.hasFnStart()) {
8951 Parser.eatToEndOfStatement();
8952 Error(L, ".fnstart must precede .unwind_raw directives");
8953 return false;
8954 }
8955
8956 int64_t StackOffset;
8957
8958 const MCExpr *OffsetExpr;
8959 SMLoc OffsetLoc = getLexer().getLoc();
8960 if (getLexer().is(AsmToken::EndOfStatement) ||
8961 getParser().parseExpression(OffsetExpr)) {
8962 Error(OffsetLoc, "expected expression");
8963 Parser.eatToEndOfStatement();
8964 return false;
8965 }
8966
8967 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8968 if (!CE) {
8969 Error(OffsetLoc, "offset must be a constant");
8970 Parser.eatToEndOfStatement();
8971 return false;
8972 }
8973
8974 StackOffset = CE->getValue();
8975
8976 if (getLexer().isNot(AsmToken::Comma)) {
8977 Error(getLexer().getLoc(), "expected comma");
8978 Parser.eatToEndOfStatement();
8979 return false;
8980 }
8981 Parser.Lex();
8982
8983 SmallVector<uint8_t, 16> Opcodes;
8984 for (;;) {
8985 const MCExpr *OE;
8986
8987 SMLoc OpcodeLoc = getLexer().getLoc();
8988 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
8989 Error(OpcodeLoc, "expected opcode expression");
8990 Parser.eatToEndOfStatement();
8991 return false;
8992 }
8993
8994 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
8995 if (!OC) {
8996 Error(OpcodeLoc, "opcode value must be a constant");
8997 Parser.eatToEndOfStatement();
8998 return false;
8999 }
9000
9001 const int64_t Opcode = OC->getValue();
9002 if (Opcode & ~0xff) {
9003 Error(OpcodeLoc, "invalid opcode");
9004 Parser.eatToEndOfStatement();
9005 return false;
9006 }
9007
9008 Opcodes.push_back(uint8_t(Opcode));
9009
9010 if (getLexer().is(AsmToken::EndOfStatement))
9011 break;
9012
9013 if (getLexer().isNot(AsmToken::Comma)) {
9014 Error(getLexer().getLoc(), "unexpected token in directive");
9015 Parser.eatToEndOfStatement();
9016 return false;
9017 }
9018
9019 Parser.Lex();
9020 }
9021
9022 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9023
9024 Parser.Lex();
9025 return false;
9026}
9027
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009028/// parseDirectiveTLSDescSeq
9029/// ::= .tlsdescseq tls-variable
9030bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
Kevin Enderby89299402014-03-25 00:05:50 +00009031 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
9032 bool isMachO = MAI->hasSubsectionsViaSymbols();
9033 if (isMachO) {
9034 Error(L, ".tlsdescseq directive not valid for Mach-O");
9035 Parser.eatToEndOfStatement();
9036 return false;
9037 }
9038
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009039 if (getLexer().isNot(AsmToken::Identifier)) {
9040 TokError("expected variable after '.tlsdescseq' directive");
9041 Parser.eatToEndOfStatement();
9042 return false;
9043 }
9044
9045 const MCSymbolRefExpr *SRE =
9046 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9047 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9048 Lex();
9049
9050 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9051 Error(Parser.getTok().getLoc(), "unexpected token");
9052 Parser.eatToEndOfStatement();
9053 return false;
9054 }
9055
9056 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9057 return false;
9058}
9059
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009060/// parseDirectiveMovSP
9061/// ::= .movsp reg [, #offset]
9062bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
9063 if (!UC.hasFnStart()) {
9064 Parser.eatToEndOfStatement();
9065 Error(L, ".fnstart must precede .movsp directives");
9066 return false;
9067 }
9068 if (UC.getFPReg() != ARM::SP) {
9069 Parser.eatToEndOfStatement();
9070 Error(L, "unexpected .movsp directive");
9071 return false;
9072 }
9073
9074 SMLoc SPRegLoc = Parser.getTok().getLoc();
9075 int SPReg = tryParseRegister();
9076 if (SPReg == -1) {
9077 Parser.eatToEndOfStatement();
9078 Error(SPRegLoc, "register expected");
9079 return false;
9080 }
9081
9082 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9083 Parser.eatToEndOfStatement();
9084 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9085 return false;
9086 }
9087
9088 int64_t Offset = 0;
9089 if (Parser.getTok().is(AsmToken::Comma)) {
9090 Parser.Lex();
9091
9092 if (Parser.getTok().isNot(AsmToken::Hash)) {
9093 Error(Parser.getTok().getLoc(), "expected #constant");
9094 Parser.eatToEndOfStatement();
9095 return false;
9096 }
9097 Parser.Lex();
9098
9099 const MCExpr *OffsetExpr;
9100 SMLoc OffsetLoc = Parser.getTok().getLoc();
9101 if (Parser.parseExpression(OffsetExpr)) {
9102 Parser.eatToEndOfStatement();
9103 Error(OffsetLoc, "malformed offset expression");
9104 return false;
9105 }
9106
9107 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9108 if (!CE) {
9109 Parser.eatToEndOfStatement();
9110 Error(OffsetLoc, "offset must be an immediate constant");
9111 return false;
9112 }
9113
9114 Offset = CE->getValue();
9115 }
9116
9117 getTargetStreamer().emitMovSP(SPReg, Offset);
9118 UC.saveFPReg(SPReg);
9119
9120 return false;
9121}
9122
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009123/// parseDirectiveObjectArch
9124/// ::= .object_arch name
9125bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
Kevin Enderby89299402014-03-25 00:05:50 +00009126 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
9127 bool isMachO = MAI->hasSubsectionsViaSymbols();
9128 if (isMachO) {
9129 Error(L, ".object_arch directive not valid for Mach-O");
9130 Parser.eatToEndOfStatement();
9131 return false;
9132 }
9133
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009134 if (getLexer().isNot(AsmToken::Identifier)) {
9135 Error(getLexer().getLoc(), "unexpected token");
9136 Parser.eatToEndOfStatement();
9137 return false;
9138 }
9139
9140 StringRef Arch = Parser.getTok().getString();
9141 SMLoc ArchLoc = Parser.getTok().getLoc();
9142 getLexer().Lex();
9143
9144 unsigned ID = StringSwitch<unsigned>(Arch)
9145#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9146 .Case(NAME, ARM::ID)
9147#define ARM_ARCH_ALIAS(NAME, ID) \
9148 .Case(NAME, ARM::ID)
9149#include "MCTargetDesc/ARMArchName.def"
9150#undef ARM_ARCH_NAME
9151#undef ARM_ARCH_ALIAS
9152 .Default(ARM::INVALID_ARCH);
9153
9154 if (ID == ARM::INVALID_ARCH) {
9155 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9156 Parser.eatToEndOfStatement();
9157 return false;
9158 }
9159
9160 getTargetStreamer().emitObjectArch(ID);
9161
9162 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9163 Error(getLexer().getLoc(), "unexpected token");
9164 Parser.eatToEndOfStatement();
9165 }
9166
9167 return false;
9168}
9169
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009170/// parseDirectiveAlign
9171/// ::= .align
9172bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9173 // NOTE: if this is not the end of the statement, fall back to the target
9174 // agnostic handling for this directive which will correctly handle this.
9175 if (getLexer().isNot(AsmToken::EndOfStatement))
9176 return true;
9177
9178 // '.align' is target specifically handled to mean 2**2 byte alignment.
9179 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9180 getStreamer().EmitCodeAlignment(4, 0);
9181 else
9182 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9183
9184 return false;
9185}
9186
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009187/// parseDirectiveThumbSet
9188/// ::= .thumb_set name, value
9189bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
9190 StringRef Name;
9191 if (Parser.parseIdentifier(Name)) {
9192 TokError("expected identifier after '.thumb_set'");
9193 Parser.eatToEndOfStatement();
9194 return false;
9195 }
9196
9197 if (getLexer().isNot(AsmToken::Comma)) {
9198 TokError("expected comma after name '" + Name + "'");
9199 Parser.eatToEndOfStatement();
9200 return false;
9201 }
9202 Lex();
9203
9204 const MCExpr *Value;
9205 if (Parser.parseExpression(Value)) {
9206 TokError("missing expression");
9207 Parser.eatToEndOfStatement();
9208 return false;
9209 }
9210
9211 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9212 TokError("unexpected token");
9213 Parser.eatToEndOfStatement();
9214 return false;
9215 }
9216 Lex();
9217
9218 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
9219 if (const MCSymbolRefExpr *SRE = dyn_cast<MCSymbolRefExpr>(Value)) {
9220 MCSymbol *Sym = getContext().LookupSymbol(SRE->getSymbol().getName());
9221 if (!Sym->isDefined()) {
9222 getStreamer().EmitSymbolAttribute(Sym, MCSA_Global);
9223 getStreamer().EmitAssignment(Alias, Value);
9224 return false;
9225 }
9226
9227 const MCObjectFileInfo::Environment Format =
9228 getContext().getObjectFileInfo()->getObjectFileType();
9229 switch (Format) {
9230 case MCObjectFileInfo::IsCOFF: {
9231 char Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
9232 getStreamer().EmitCOFFSymbolType(Type);
9233 // .set values are always local in COFF
9234 getStreamer().EmitSymbolAttribute(Alias, MCSA_Local);
9235 break;
9236 }
9237 case MCObjectFileInfo::IsELF:
9238 getStreamer().EmitSymbolAttribute(Alias, MCSA_ELF_TypeFunction);
9239 break;
9240 case MCObjectFileInfo::IsMachO:
9241 break;
9242 }
9243 }
9244
9245 // FIXME: set the function as being a thumb function via the assembler
9246 getStreamer().EmitThumbFunc(Alias);
9247 getStreamer().EmitAssignment(Alias, Value);
9248
9249 return false;
9250}
9251
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009252/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009253extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00009254 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
9255 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009256}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009257
Chris Lattner3e4582a2010-09-06 19:11:01 +00009258#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009259#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009260#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009261#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009262
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009263static const struct ExtMapEntry {
9264 const char *Extension;
9265 const unsigned ArchCheck;
9266 const uint64_t Features;
9267} Extensions[] = {
9268 { "crc", Feature_HasV8, ARM::FeatureCRC },
9269 { "crypto", Feature_HasV8,
9270 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9271 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9272 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9273 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9274 // FIXME: iWMMXT not supported
9275 { "iwmmxt", Feature_None, 0 },
9276 // FIXME: iWMMXT2 not supported
9277 { "iwmmxt2", Feature_None, 0 },
9278 // FIXME: Maverick not supported
9279 { "maverick", Feature_None, 0 },
9280 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9281 // FIXME: ARMv6-m OS Extensions feature not checked
9282 { "os", Feature_None, 0 },
9283 // FIXME: Also available in ARMv6-K
9284 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9285 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9286 // FIXME: Only available in A-class, isel not predicated
9287 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9288 // FIXME: xscale not supported
9289 { "xscale", Feature_None, 0 },
9290};
9291
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009292/// parseDirectiveArchExtension
9293/// ::= .arch_extension [no]feature
9294bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
9295 if (getLexer().isNot(AsmToken::Identifier)) {
9296 Error(getLexer().getLoc(), "unexpected token");
9297 Parser.eatToEndOfStatement();
9298 return false;
9299 }
9300
9301 StringRef Extension = Parser.getTok().getString();
9302 SMLoc ExtLoc = Parser.getTok().getLoc();
9303 getLexer().Lex();
9304
9305 bool EnableFeature = true;
Benjamin Kramere9391a52014-02-20 17:36:31 +00009306 if (Extension.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009307 EnableFeature = false;
9308 Extension = Extension.substr(2);
9309 }
9310
Benjamin Kramere9391a52014-02-20 17:36:31 +00009311 for (unsigned EI = 0, EE = array_lengthof(Extensions); EI != EE; ++EI) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009312 if (Extensions[EI].Extension != Extension)
9313 continue;
9314
9315 unsigned FB = getAvailableFeatures();
9316 if ((FB & Extensions[EI].ArchCheck) != Extensions[EI].ArchCheck) {
9317 Error(ExtLoc, "architectural extension '" + Extension + "' is not "
9318 "allowed for the current base architecture");
9319 return false;
9320 }
9321
9322 if (!Extensions[EI].Features)
9323 report_fatal_error("unsupported architectural extension: " + Extension);
9324
9325 if (EnableFeature)
9326 FB |= ComputeAvailableFeatures(Extensions[EI].Features);
9327 else
9328 FB &= ~ComputeAvailableFeatures(Extensions[EI].Features);
9329
9330 setAvailableFeatures(FB);
9331 return false;
9332 }
9333
9334 Error(ExtLoc, "unknown architectural extension: " + Extension);
9335 Parser.eatToEndOfStatement();
9336 return false;
9337}
9338
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009339// Define this matcher function after the auto-generated include so we
9340// have the match class enum definitions.
9341unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
9342 unsigned Kind) {
9343 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
9344 // If the kind is a token for a literal immediate, check if our asm
9345 // operand matches. This is for InstAliases which have a fixed-value
9346 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009347 switch (Kind) {
9348 default: break;
9349 case MCK__35_0:
9350 if (Op->isImm())
9351 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm()))
9352 if (CE->getValue() == 0)
9353 return Match_Success;
9354 break;
9355 case MCK_ARMSOImm:
9356 if (Op->isImm()) {
9357 const MCExpr *SOExpr = Op->getImm();
9358 int64_t Value;
9359 if (!SOExpr->EvaluateAsAbsolute(Value))
9360 return Match_Success;
9361 assert((Value >= INT32_MIN && Value <= INT32_MAX) &&
9362 "expression value must be representiable in 32 bits");
9363 }
9364 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009365 case MCK_GPRPair:
9366 if (Op->isReg() &&
9367 MRI->getRegClass(ARM::GPRRegClassID).contains(Op->getReg()))
9368 return Match_Success;
9369 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009370 }
9371 return Match_InvalidOperand;
9372}