blob: 0eec8622e975c7c1e4ca0f2888b3dd3b920c1f89 [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Evan Cheng11424442011-07-26 00:24:13 +000010#include "MCTargetDesc/ARMBaseInfo.h"
Evan Chenga20cde32011-07-20 23:34:39 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMMCExpr.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000013#include "llvm/MC/MCParser/MCAsmLexer.h"
14#include "llvm/MC/MCParser/MCAsmParser.h"
15#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
Rafael Espindolae90c1cb2011-05-16 16:17:21 +000016#include "llvm/MC/MCAsmInfo.h"
Jim Grosbachc6db8ce2010-11-05 22:33:53 +000017#include "llvm/MC/MCContext.h"
Kevin Enderbyccab3172009-09-15 00:27:25 +000018#include "llvm/MC/MCStreamer.h"
19#include "llvm/MC/MCExpr.h"
20#include "llvm/MC/MCInst.h"
Evan Cheng4d6c9d72011-08-23 20:15:21 +000021#include "llvm/MC/MCInstrDesc.h"
Evan Cheng11424442011-07-26 00:24:13 +000022#include "llvm/MC/MCRegisterInfo.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000023#include "llvm/MC/MCSubtargetInfo.h"
Evan Cheng11424442011-07-26 00:24:13 +000024#include "llvm/MC/MCTargetAsmParser.h"
Jim Grosbach3d1eac82011-08-26 21:43:41 +000025#include "llvm/Support/MathExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000026#include "llvm/Support/SourceMgr.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000027#include "llvm/Support/TargetRegistry.h"
Daniel Dunbar4a863e62010-08-11 06:37:12 +000028#include "llvm/Support/raw_ostream.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000029#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000030#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000031#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000032#include "llvm/ADT/SmallVector.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000033#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000034#include "llvm/ADT/Twine.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000035
Kevin Enderbyccab3172009-09-15 00:27:25 +000036using namespace llvm;
37
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000038namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000039
40class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000041
Jim Grosbach04945c42011-12-02 00:35:16 +000042enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000043
Evan Cheng11424442011-07-26 00:24:13 +000044class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000045 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000046 MCAsmParser &Parser;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000047 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000048
Jim Grosbachab5830e2011-12-14 02:16:11 +000049 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
51
Jim Grosbached16ec42011-08-29 22:24:09 +000052 struct {
53 ARMCC::CondCodes Cond; // Condition for IT block.
54 unsigned Mask:4; // Condition mask for instructions.
55 // Starting at first 1 (from lsb).
56 // '1' condition as indicated in IT.
57 // '0' inverse of condition (else).
58 // Count of instructions in IT block is
59 // 4 - trailingzeroes(mask)
60
61 bool FirstCond; // Explicit flag for when we're parsing the
62 // First instruction in the IT block. It's
63 // implied in the mask, so needs special
64 // handling.
65
66 unsigned CurPosition; // Current position in parsing of IT
67 // block. In range [0,3]. Initialized
68 // according to count of instructions in block.
69 // ~0U if no active IT block.
70 } ITState;
71 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000072 void forwardITPosition() {
73 if (!inITBlock()) return;
74 // Move to the next instruction in the IT block, if there is one. If not,
75 // mark the block as done.
76 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
77 if (++ITState.CurPosition == 5 - TZ)
78 ITState.CurPosition = ~0U; // Done with the IT block after this.
79 }
Jim Grosbached16ec42011-08-29 22:24:09 +000080
81
Kevin Enderbyccab3172009-09-15 00:27:25 +000082 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +000083 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
84
Benjamin Kramer673824b2012-04-15 17:04:27 +000085 bool Warning(SMLoc L, const Twine &Msg,
86 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
87 return Parser.Warning(L, Msg, Ranges);
88 }
89 bool Error(SMLoc L, const Twine &Msg,
90 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
91 return Parser.Error(L, Msg, Ranges);
92 }
Kevin Enderbyccab3172009-09-15 00:27:25 +000093
Jim Grosbacheab1c0d2011-07-26 17:10:22 +000094 int tryParseRegister();
95 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +000096 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +000097 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +000098 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +000099 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
100 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000101 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
102 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000103 bool parseDirectiveWord(unsigned Size, SMLoc L);
104 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000105 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000106 bool parseDirectiveThumbFunc(SMLoc L);
107 bool parseDirectiveCode(SMLoc L);
108 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000109 bool parseDirectiveReq(StringRef Name, SMLoc L);
110 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000111 bool parseDirectiveArch(SMLoc L);
112 bool parseDirectiveEabiAttr(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000113
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000115 bool &CarrySetting, unsigned &ProcessorIMod,
116 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000117 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000118 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000119
Evan Cheng4d1ca962011-07-08 01:53:10 +0000120 bool isThumb() const {
121 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000122 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000123 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000124 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000125 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000126 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000127 bool isThumbTwo() const {
128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
129 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000130 bool hasV6Ops() const {
131 return STI.getFeatureBits() & ARM::HasV6Ops;
132 }
James Molloy21efa7d2011-09-28 14:21:38 +0000133 bool hasV7Ops() const {
134 return STI.getFeatureBits() & ARM::HasV7Ops;
135 }
Evan Cheng284b4672011-07-08 22:36:29 +0000136 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000137 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
138 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000139 }
James Molloy21efa7d2011-09-28 14:21:38 +0000140 bool isMClass() const {
141 return STI.getFeatureBits() & ARM::FeatureMClass;
142 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000143
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000144 /// @name Auto-generated Match Functions
145 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000146
Chris Lattner3e4582a2010-09-06 19:11:01 +0000147#define GET_ASSEMBLER_HEADER
148#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000149
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000150 /// }
151
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000152 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000153 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000154 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000155 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000156 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000157 OperandMatchResultTy parseCoprocOptionOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000159 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000160 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000161 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000162 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000163 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000164 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000165 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
166 StringRef Op, int Low, int High);
167 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
168 return parsePKHImm(O, "lsl", 0, 31);
169 }
170 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
171 return parsePKHImm(O, "asr", 1, 32);
172 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000173 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000174 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000175 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000176 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000177 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000178 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000179 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000180 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach04945c42011-12-02 00:35:16 +0000181 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000182
183 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000184 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
185 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
186 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +0000187 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000188 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +0000189 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000190 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000191 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000192 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +0000193 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000194 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +0000195 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000196 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000197 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000198 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +0000199 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000200 void cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000201 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000202 void cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000203 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000204 void cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000205 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000206 void cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +0000207 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000208 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
209 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
210 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +0000211 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000212 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000213 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000214 void cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000215 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000216 void cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +0000217 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000218 void cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000219 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier451ef132012-08-31 22:12:31 +0000220 void cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +0000221 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000222 bool validateInstruction(MCInst &Inst,
223 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000224 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000226 bool shouldOmitCCOutOperand(StringRef Mnemonic,
227 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000228
Kevin Enderbyccab3172009-09-15 00:27:25 +0000229public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000230 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000231 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000232 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000233 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000234 Match_RequiresThumb2,
235#define GET_OPERAND_DIAGNOSTIC_TYPES
236#include "ARMGenAsmMatcher.inc"
237
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000238 };
239
Evan Cheng91111d22011-07-09 05:47:46 +0000240 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Evan Cheng11424442011-07-26 00:24:13 +0000241 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000242 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000243
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000244 // Cache the MCRegisterInfo.
245 MRI = &getContext().getRegisterInfo();
246
Evan Cheng4d1ca962011-07-08 01:53:10 +0000247 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000248 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000249
250 // Not in an ITBlock to start with.
251 ITState.CurPosition = ~0U;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000252 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000253
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000254 // Implementation of the MCTargetAsmParser interface:
255 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
256 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000257 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000258 bool ParseDirective(AsmToken DirectiveID);
259
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000260 unsigned checkTargetMatchPredicate(MCInst &Inst);
261
Chad Rosier49963552012-10-13 00:26:04 +0000262 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000263 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000264 MCStreamer &Out, unsigned &ErrorInfo,
265 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000266};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000267} // end anonymous namespace
268
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000269namespace {
270
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000271/// ARMOperand - Instances of this class represent a parsed ARM machine
272/// instruction.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000273class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000274 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000275 k_CondCode,
276 k_CCOut,
277 k_ITCondMask,
278 k_CoprocNum,
279 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000280 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000281 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000282 k_MemBarrierOpt,
283 k_Memory,
284 k_PostIndexRegister,
285 k_MSRMask,
286 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000287 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000288 k_Register,
289 k_RegisterList,
290 k_DPRRegisterList,
291 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000292 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000293 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000294 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000295 k_ShiftedRegister,
296 k_ShiftedImmediate,
297 k_ShifterImmediate,
298 k_RotateImmediate,
299 k_BitfieldDescriptor,
300 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000301 } Kind;
302
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000303 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000304 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000305
306 union {
307 struct {
Daniel Dunbard8042b72010-08-11 06:36:53 +0000308 ARMCC::CondCodes Val;
309 } CC;
310
311 struct {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000312 unsigned Val;
313 } Cop;
314
315 struct {
Jim Grosbach48399582011-10-12 17:34:41 +0000316 unsigned Val;
317 } CoprocOption;
318
319 struct {
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000320 unsigned Mask:4;
321 } ITMask;
322
323 struct {
324 ARM_MB::MemBOpt Val;
325 } MBOpt;
326
327 struct {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000328 ARM_PROC::IFlags Val;
329 } IFlags;
330
331 struct {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000332 unsigned Val;
333 } MMask;
334
335 struct {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000336 const char *Data;
337 unsigned Length;
338 } Tok;
339
340 struct {
341 unsigned RegNum;
342 } Reg;
343
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000344 // A vector register list is a sequential list of 1 to 4 registers.
345 struct {
346 unsigned RegNum;
347 unsigned Count;
Jim Grosbach04945c42011-12-02 00:35:16 +0000348 unsigned LaneIndex;
Jim Grosbach2f50e922011-12-15 21:44:33 +0000349 bool isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000350 } VectorList;
351
Bill Wendlingb884a8e2010-11-06 22:19:43 +0000352 struct {
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000353 unsigned Val;
354 } VectorIndex;
355
356 struct {
Kevin Enderbyf5079942009-10-13 22:19:02 +0000357 const MCExpr *Val;
358 } Imm;
Jim Grosbach624bcc72010-10-29 14:46:02 +0000359
Daniel Dunbar2be732a2011-01-10 15:26:21 +0000360 /// Combined record for all forms of ARM address expressions.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000361 struct {
362 unsigned BaseRegNum;
Jim Grosbachd3595712011-08-03 23:50:40 +0000363 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
364 // was specified.
365 const MCConstantExpr *OffsetImm; // Offset immediate value
366 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
367 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbacha95ec992011-10-11 17:29:55 +0000368 unsigned ShiftImm; // shift for OffsetReg.
369 unsigned Alignment; // 0 = no alignment specified
Jim Grosbachcef98cd2011-12-19 18:31:43 +0000370 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbachd3595712011-08-03 23:50:40 +0000371 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbach871dff72011-10-11 15:59:20 +0000372 } Memory;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000373
374 struct {
Jim Grosbachd3595712011-08-03 23:50:40 +0000375 unsigned RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +0000376 bool isAdd;
377 ARM_AM::ShiftOpc ShiftTy;
378 unsigned ShiftImm;
Jim Grosbachd3595712011-08-03 23:50:40 +0000379 } PostIdxReg;
380
381 struct {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000382 bool isASR;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000383 unsigned Imm;
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000384 } ShifterImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000385 struct {
386 ARM_AM::ShiftOpc ShiftTy;
387 unsigned SrcReg;
388 unsigned ShiftReg;
389 unsigned ShiftImm;
Jim Grosbachac798e12011-07-25 20:49:51 +0000390 } RegShiftedReg;
Owen Andersonb595ed02011-07-21 18:54:16 +0000391 struct {
392 ARM_AM::ShiftOpc ShiftTy;
393 unsigned SrcReg;
394 unsigned ShiftImm;
Jim Grosbachac798e12011-07-25 20:49:51 +0000395 } RegShiftedImm;
Jim Grosbach833b9d32011-07-27 20:15:40 +0000396 struct {
397 unsigned Imm;
398 } RotImm;
Jim Grosbach864b6092011-07-28 21:34:26 +0000399 struct {
400 unsigned LSB;
401 unsigned Width;
402 } Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000403 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000404
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000405 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
406public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000407 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
408 Kind = o.Kind;
409 StartLoc = o.StartLoc;
410 EndLoc = o.EndLoc;
411 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000412 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000413 CC = o.CC;
414 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000415 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000416 ITMask = o.ITMask;
417 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000418 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000419 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000420 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000421 case k_CCOut:
422 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000423 Reg = o.Reg;
424 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000425 case k_RegisterList:
426 case k_DPRRegisterList:
427 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000428 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000429 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000430 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000431 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000432 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000433 VectorList = o.VectorList;
434 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000435 case k_CoprocNum:
436 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000437 Cop = o.Cop;
438 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000439 case k_CoprocOption:
440 CoprocOption = o.CoprocOption;
441 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000442 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000443 Imm = o.Imm;
444 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000445 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000446 MBOpt = o.MBOpt;
447 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000448 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000449 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000450 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000451 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000452 PostIdxReg = o.PostIdxReg;
453 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000454 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000455 MMask = o.MMask;
456 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000457 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000458 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000459 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000460 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000461 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000462 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000463 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000464 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000465 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000466 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000467 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000468 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000469 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000470 RotImm = o.RotImm;
471 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000472 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000473 Bitfield = o.Bitfield;
474 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000475 case k_VectorIndex:
476 VectorIndex = o.VectorIndex;
477 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000478 }
479 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000480
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000481 /// getStartLoc - Get the location of the first token of this operand.
482 SMLoc getStartLoc() const { return StartLoc; }
483 /// getEndLoc - Get the location of the last token of this operand.
484 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000485 /// getLocRange - Get the range between the first and last token of this
486 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000487 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
488
Daniel Dunbard8042b72010-08-11 06:36:53 +0000489 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000490 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000491 return CC.Val;
492 }
493
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000494 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000495 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000496 return Cop.Val;
497 }
498
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000499 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000500 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000501 return StringRef(Tok.Data, Tok.Length);
502 }
503
504 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000505 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000506 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000507 }
508
Bill Wendlingbed94652010-11-09 23:28:44 +0000509 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000510 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
511 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000512 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000513 }
514
Kevin Enderbyf5079942009-10-13 22:19:02 +0000515 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000516 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000517 return Imm.Val;
518 }
519
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000520 unsigned getVectorIndex() const {
521 assert(Kind == k_VectorIndex && "Invalid access!");
522 return VectorIndex.Val;
523 }
524
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000525 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000526 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000527 return MBOpt.Val;
528 }
529
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000530 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000531 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000532 return IFlags.Val;
533 }
534
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000535 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000536 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000537 return MMask.Val;
538 }
539
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000540 bool isCoprocNum() const { return Kind == k_CoprocNum; }
541 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000542 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000543 bool isCondCode() const { return Kind == k_CondCode; }
544 bool isCCOut() const { return Kind == k_CCOut; }
545 bool isITMask() const { return Kind == k_ITCondMask; }
546 bool isITCondCode() const { return Kind == k_CondCode; }
547 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000548 bool isFPImm() const {
549 if (!isImm()) return false;
550 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
551 if (!CE) return false;
552 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
553 return Val != -1;
554 }
Jim Grosbachea231912011-12-22 22:19:05 +0000555 bool isFBits16() const {
556 if (!isImm()) return false;
557 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
558 if (!CE) return false;
559 int64_t Value = CE->getValue();
560 return Value >= 0 && Value <= 16;
561 }
562 bool isFBits32() const {
563 if (!isImm()) return false;
564 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
565 if (!CE) return false;
566 int64_t Value = CE->getValue();
567 return Value >= 1 && Value <= 32;
568 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000569 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000570 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000571 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
572 if (!CE) return false;
573 int64_t Value = CE->getValue();
574 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
575 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000576 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000577 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000578 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
579 if (!CE) return false;
580 int64_t Value = CE->getValue();
581 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
582 }
583 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000584 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000585 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
586 if (!CE) return false;
587 int64_t Value = CE->getValue();
588 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
589 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000590 bool isImm0_508s4Neg() const {
591 if (!isImm()) return false;
592 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
593 if (!CE) return false;
594 int64_t Value = -CE->getValue();
595 // explicitly exclude zero. we want that to use the normal 0_508 version.
596 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
597 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000598 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000599 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000600 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
601 if (!CE) return false;
602 int64_t Value = CE->getValue();
603 return Value >= 0 && Value < 256;
604 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000605 bool isImm0_4095() const {
606 if (!isImm()) return false;
607 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
608 if (!CE) return false;
609 int64_t Value = CE->getValue();
610 return Value >= 0 && Value < 4096;
611 }
612 bool isImm0_4095Neg() const {
613 if (!isImm()) return false;
614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
615 if (!CE) return false;
616 int64_t Value = -CE->getValue();
617 return Value > 0 && Value < 4096;
618 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000619 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000620 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
622 if (!CE) return false;
623 int64_t Value = CE->getValue();
624 return Value >= 0 && Value < 2;
625 }
626 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000627 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000628 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
629 if (!CE) return false;
630 int64_t Value = CE->getValue();
631 return Value >= 0 && Value < 4;
632 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000633 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000634 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
636 if (!CE) return false;
637 int64_t Value = CE->getValue();
638 return Value >= 0 && Value < 8;
639 }
640 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000641 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
643 if (!CE) return false;
644 int64_t Value = CE->getValue();
645 return Value >= 0 && Value < 16;
646 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000647 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000648 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
650 if (!CE) return false;
651 int64_t Value = CE->getValue();
652 return Value >= 0 && Value < 32;
653 }
Jim Grosbach00326402011-12-08 01:30:04 +0000654 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000655 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
657 if (!CE) return false;
658 int64_t Value = CE->getValue();
659 return Value >= 0 && Value < 64;
660 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000661 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000662 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
664 if (!CE) return false;
665 int64_t Value = CE->getValue();
666 return Value == 8;
667 }
668 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000669 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
671 if (!CE) return false;
672 int64_t Value = CE->getValue();
673 return Value == 16;
674 }
675 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000676 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000677 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
678 if (!CE) return false;
679 int64_t Value = CE->getValue();
680 return Value == 32;
681 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000682 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000683 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
685 if (!CE) return false;
686 int64_t Value = CE->getValue();
687 return Value > 0 && Value <= 8;
688 }
689 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000690 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
692 if (!CE) return false;
693 int64_t Value = CE->getValue();
694 return Value > 0 && Value <= 16;
695 }
696 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000697 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
699 if (!CE) return false;
700 int64_t Value = CE->getValue();
701 return Value > 0 && Value <= 32;
702 }
703 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000704 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
706 if (!CE) return false;
707 int64_t Value = CE->getValue();
708 return Value > 0 && Value <= 64;
709 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000710 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000711 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
713 if (!CE) return false;
714 int64_t Value = CE->getValue();
715 return Value > 0 && Value < 8;
716 }
717 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000718 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
720 if (!CE) return false;
721 int64_t Value = CE->getValue();
722 return Value > 0 && Value < 16;
723 }
724 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000725 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
727 if (!CE) return false;
728 int64_t Value = CE->getValue();
729 return Value > 0 && Value < 32;
730 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000731 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000732 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
734 if (!CE) return false;
735 int64_t Value = CE->getValue();
736 return Value > 0 && Value < 17;
737 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000738 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000739 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
741 if (!CE) return false;
742 int64_t Value = CE->getValue();
743 return Value > 0 && Value < 33;
744 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000745 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000746 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
748 if (!CE) return false;
749 int64_t Value = CE->getValue();
750 return Value >= 0 && Value < 33;
751 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000752 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000753 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
755 if (!CE) return false;
756 int64_t Value = CE->getValue();
757 return Value >= 0 && Value < 65536;
758 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000759 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000760 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
762 // If it's not a constant expression, it'll generate a fixup and be
763 // handled later.
764 if (!CE) return true;
765 int64_t Value = CE->getValue();
766 return Value >= 0 && Value < 65536;
767 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000768 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000769 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
771 if (!CE) return false;
772 int64_t Value = CE->getValue();
773 return Value >= 0 && Value <= 0xffffff;
774 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000775 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000776 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
778 if (!CE) return false;
779 int64_t Value = CE->getValue();
780 return Value > 0 && Value < 33;
781 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000782 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000783 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
785 if (!CE) return false;
786 int64_t Value = CE->getValue();
787 return Value >= 0 && Value < 32;
788 }
789 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000790 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
792 if (!CE) return false;
793 int64_t Value = CE->getValue();
794 return Value > 0 && Value <= 32;
795 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000796 bool isAdrLabel() const {
797 // If we have an immediate that's not a constant, treat it as a label
798 // reference needing a fixup. If it is a constant, but it can't fit
799 // into shift immediate encoding, we reject it.
800 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
801 else return (isARMSOImm() || isARMSOImmNeg());
802 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000803 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000804 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000805 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
806 if (!CE) return false;
807 int64_t Value = CE->getValue();
808 return ARM_AM::getSOImmVal(Value) != -1;
809 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000810 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000811 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
813 if (!CE) return false;
814 int64_t Value = CE->getValue();
815 return ARM_AM::getSOImmVal(~Value) != -1;
816 }
Jim Grosbach30506252011-12-08 00:31:07 +0000817 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000818 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000819 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
820 if (!CE) return false;
821 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000822 // Only use this when not representable as a plain so_imm.
823 return ARM_AM::getSOImmVal(Value) == -1 &&
824 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000825 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000826 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000827 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
829 if (!CE) return false;
830 int64_t Value = CE->getValue();
831 return ARM_AM::getT2SOImmVal(Value) != -1;
832 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000833 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000834 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
836 if (!CE) return false;
837 int64_t Value = CE->getValue();
838 return ARM_AM::getT2SOImmVal(~Value) != -1;
839 }
Jim Grosbach30506252011-12-08 00:31:07 +0000840 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000841 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000842 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
843 if (!CE) return false;
844 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000845 // Only use this when not representable as a plain so_imm.
846 return ARM_AM::getT2SOImmVal(Value) == -1 &&
847 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000848 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000849 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000850 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
852 if (!CE) return false;
853 int64_t Value = CE->getValue();
854 return Value == 1 || Value == 0;
855 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000856 bool isReg() const { return Kind == k_Register; }
857 bool isRegList() const { return Kind == k_RegisterList; }
858 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
859 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
860 bool isToken() const { return Kind == k_Token; }
861 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000862 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000863 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
864 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
865 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
866 bool isRotImm() const { return Kind == k_RotateImmediate; }
867 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
868 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000869 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000870 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000871 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000872 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000873 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000874 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000875 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000876 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
877 (alignOK || Memory.Alignment == 0);
878 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000879 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000880 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000881 return false;
882 // Base register must be PC.
883 if (Memory.BaseRegNum != ARM::PC)
884 return false;
885 // Immediate offset in range [-4095, 4095].
886 if (!Memory.OffsetImm) return true;
887 int64_t Val = Memory.OffsetImm->getValue();
888 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
889 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000890 bool isAlignedMemory() const {
891 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000892 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000893 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000894 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000895 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000896 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000897 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000898 if (!Memory.OffsetImm) return true;
899 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000900 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000901 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000902 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000903 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000904 // Immediate offset in range [-4095, 4095].
905 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
906 if (!CE) return false;
907 int64_t Val = CE->getValue();
908 return Val > -4096 && Val < 4096;
909 }
Jim Grosbach5b96b802011-08-10 20:29:19 +0000910 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +0000911 // If we have an immediate that's not a constant, treat it as a label
912 // reference needing a fixup. If it is a constant, it's something else
913 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000914 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +0000915 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000916 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000917 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +0000918 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000919 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000920 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000921 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +0000922 if (!Memory.OffsetImm) return true;
923 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +0000924 // The #-0 offset is encoded as INT32_MIN, and we have to check
925 // for this too.
926 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000927 }
928 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000929 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000930 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000931 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000932 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
933 // Immediate offset in range [-255, 255].
934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
935 if (!CE) return false;
936 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000937 // Special case, #-0 is INT32_MIN.
938 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000939 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000940 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000941 // If we have an immediate that's not a constant, treat it as a label
942 // reference needing a fixup. If it is a constant, it's something else
943 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000944 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000945 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000946 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000947 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000948 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000949 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +0000950 if (!Memory.OffsetImm) return true;
951 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +0000952 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000953 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +0000954 }
Jim Grosbach05541f42011-09-19 22:21:13 +0000955 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +0000956 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000957 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +0000958 return false;
959 return true;
960 }
961 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +0000962 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000963 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
964 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +0000965 return false;
966 return true;
967 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000968 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +0000969 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +0000970 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +0000971 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000972 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000973 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +0000974 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000975 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000976 return false;
977 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +0000978 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000979 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +0000980 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000981 return false;
982 return true;
983 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000984 bool isMemThumbRR() const {
985 // Thumb reg+reg addressing is simple. Just two registers, a base and
986 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +0000987 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000988 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +0000989 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +0000990 return isARMLowRegister(Memory.BaseRegNum) &&
991 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000992 }
993 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +0000994 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000995 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000996 return false;
997 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +0000998 if (!Memory.OffsetImm) return true;
999 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001000 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1001 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001002 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001003 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001004 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001005 return false;
1006 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001007 if (!Memory.OffsetImm) return true;
1008 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001009 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1010 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001011 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001012 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001013 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001014 return false;
1015 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001016 if (!Memory.OffsetImm) return true;
1017 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001018 return Val >= 0 && Val <= 31;
1019 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001020 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001021 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001022 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001023 return false;
1024 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001025 if (!Memory.OffsetImm) return true;
1026 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001027 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001028 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001029 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001030 // If we have an immediate that's not a constant, treat it as a label
1031 // reference needing a fixup. If it is a constant, it's something else
1032 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001033 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001034 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001035 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001036 return false;
1037 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001038 if (!Memory.OffsetImm) return true;
1039 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001040 // Special case, #-0 is INT32_MIN.
1041 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001042 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001043 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001044 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001045 return false;
1046 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001047 if (!Memory.OffsetImm) return true;
1048 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001049 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1050 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001051 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001052 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001053 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001054 // Base reg of PC isn't allowed for these encodings.
1055 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001056 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001057 if (!Memory.OffsetImm) return true;
1058 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001059 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001060 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001061 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001062 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001063 return false;
1064 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001065 if (!Memory.OffsetImm) return true;
1066 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001067 return Val >= 0 && Val < 256;
1068 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001069 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001070 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001071 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001072 // Base reg of PC isn't allowed for these encodings.
1073 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001074 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001075 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001076 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001077 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001078 }
1079 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001080 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001081 return false;
1082 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001083 if (!Memory.OffsetImm) return true;
1084 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001085 return (Val >= 0 && Val < 4096);
1086 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001087 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001088 // If we have an immediate that's not a constant, treat it as a label
1089 // reference needing a fixup. If it is a constant, it's something else
1090 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001091 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001092 return true;
1093
Chad Rosier41099832012-09-11 23:02:35 +00001094 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001095 return false;
1096 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001097 if (!Memory.OffsetImm) return true;
1098 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001099 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001100 }
1101 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001102 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001103 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1104 if (!CE) return false;
1105 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001106 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001107 }
Jim Grosbach93981412011-10-11 21:55:36 +00001108 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001109 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001110 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1111 if (!CE) return false;
1112 int64_t Val = CE->getValue();
1113 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1114 (Val == INT32_MIN);
1115 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001116
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001117 bool isMSRMask() const { return Kind == k_MSRMask; }
1118 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001119
Jim Grosbach741cd732011-10-17 22:26:03 +00001120 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001121 bool isSingleSpacedVectorList() const {
1122 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1123 }
1124 bool isDoubleSpacedVectorList() const {
1125 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1126 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001127 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001128 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001129 return VectorList.Count == 1;
1130 }
1131
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001132 bool isVecListDPair() const {
1133 if (!isSingleSpacedVectorList()) return false;
1134 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1135 .contains(VectorList.RegNum));
1136 }
1137
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001138 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001139 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001140 return VectorList.Count == 3;
1141 }
1142
Jim Grosbach846bcff2011-10-21 20:35:01 +00001143 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001144 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001145 return VectorList.Count == 4;
1146 }
1147
Jim Grosbache5307f92012-03-05 21:43:40 +00001148 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001149 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001150 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1151 .contains(VectorList.RegNum));
1152 }
1153
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001154 bool isVecListThreeQ() const {
1155 if (!isDoubleSpacedVectorList()) return false;
1156 return VectorList.Count == 3;
1157 }
1158
Jim Grosbach1e946a42012-01-24 00:43:12 +00001159 bool isVecListFourQ() const {
1160 if (!isDoubleSpacedVectorList()) return false;
1161 return VectorList.Count == 4;
1162 }
1163
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001164 bool isSingleSpacedVectorAllLanes() const {
1165 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1166 }
1167 bool isDoubleSpacedVectorAllLanes() const {
1168 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1169 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001170 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001171 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001172 return VectorList.Count == 1;
1173 }
1174
Jim Grosbach13a292c2012-03-06 22:01:44 +00001175 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001176 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001177 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1178 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001179 }
1180
Jim Grosbached428bc2012-03-06 23:10:38 +00001181 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001182 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001183 return VectorList.Count == 2;
1184 }
1185
Jim Grosbachb78403c2012-01-24 23:47:04 +00001186 bool isVecListThreeDAllLanes() const {
1187 if (!isSingleSpacedVectorAllLanes()) return false;
1188 return VectorList.Count == 3;
1189 }
1190
1191 bool isVecListThreeQAllLanes() const {
1192 if (!isDoubleSpacedVectorAllLanes()) return false;
1193 return VectorList.Count == 3;
1194 }
1195
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001196 bool isVecListFourDAllLanes() const {
1197 if (!isSingleSpacedVectorAllLanes()) return false;
1198 return VectorList.Count == 4;
1199 }
1200
1201 bool isVecListFourQAllLanes() const {
1202 if (!isDoubleSpacedVectorAllLanes()) return false;
1203 return VectorList.Count == 4;
1204 }
1205
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001206 bool isSingleSpacedVectorIndexed() const {
1207 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1208 }
1209 bool isDoubleSpacedVectorIndexed() const {
1210 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1211 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001212 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001213 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001214 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1215 }
1216
Jim Grosbachda511042011-12-14 23:35:06 +00001217 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001218 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001219 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1220 }
1221
1222 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001223 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001224 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1225 }
1226
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001227 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001228 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001229 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1230 }
1231
Jim Grosbachda511042011-12-14 23:35:06 +00001232 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001233 if (!isSingleSpacedVectorIndexed()) return false;
1234 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1235 }
1236
1237 bool isVecListTwoQWordIndexed() const {
1238 if (!isDoubleSpacedVectorIndexed()) return false;
1239 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1240 }
1241
1242 bool isVecListTwoQHWordIndexed() const {
1243 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001244 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1245 }
1246
1247 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001248 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001249 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1250 }
1251
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001252 bool isVecListThreeDByteIndexed() const {
1253 if (!isSingleSpacedVectorIndexed()) return false;
1254 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1255 }
1256
1257 bool isVecListThreeDHWordIndexed() const {
1258 if (!isSingleSpacedVectorIndexed()) return false;
1259 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1260 }
1261
1262 bool isVecListThreeQWordIndexed() const {
1263 if (!isDoubleSpacedVectorIndexed()) return false;
1264 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1265 }
1266
1267 bool isVecListThreeQHWordIndexed() const {
1268 if (!isDoubleSpacedVectorIndexed()) return false;
1269 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1270 }
1271
1272 bool isVecListThreeDWordIndexed() const {
1273 if (!isSingleSpacedVectorIndexed()) return false;
1274 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1275 }
1276
Jim Grosbach14952a02012-01-24 18:37:25 +00001277 bool isVecListFourDByteIndexed() const {
1278 if (!isSingleSpacedVectorIndexed()) return false;
1279 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1280 }
1281
1282 bool isVecListFourDHWordIndexed() const {
1283 if (!isSingleSpacedVectorIndexed()) return false;
1284 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1285 }
1286
1287 bool isVecListFourQWordIndexed() const {
1288 if (!isDoubleSpacedVectorIndexed()) return false;
1289 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1290 }
1291
1292 bool isVecListFourQHWordIndexed() const {
1293 if (!isDoubleSpacedVectorIndexed()) return false;
1294 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1295 }
1296
1297 bool isVecListFourDWordIndexed() const {
1298 if (!isSingleSpacedVectorIndexed()) return false;
1299 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1300 }
1301
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001302 bool isVectorIndex8() const {
1303 if (Kind != k_VectorIndex) return false;
1304 return VectorIndex.Val < 8;
1305 }
1306 bool isVectorIndex16() const {
1307 if (Kind != k_VectorIndex) return false;
1308 return VectorIndex.Val < 4;
1309 }
1310 bool isVectorIndex32() const {
1311 if (Kind != k_VectorIndex) return false;
1312 return VectorIndex.Val < 2;
1313 }
1314
Jim Grosbach741cd732011-10-17 22:26:03 +00001315 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001316 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001317 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1318 // Must be a constant.
1319 if (!CE) return false;
1320 int64_t Value = CE->getValue();
1321 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1322 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001323 return Value >= 0 && Value < 256;
1324 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001325
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001326 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001327 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001328 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1329 // Must be a constant.
1330 if (!CE) return false;
1331 int64_t Value = CE->getValue();
1332 // i16 value in the range [0,255] or [0x0100, 0xff00]
1333 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1334 }
1335
Jim Grosbach8211c052011-10-18 00:22:00 +00001336 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001337 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001338 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1339 // Must be a constant.
1340 if (!CE) return false;
1341 int64_t Value = CE->getValue();
1342 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1343 return (Value >= 0 && Value < 256) ||
1344 (Value >= 0x0100 && Value <= 0xff00) ||
1345 (Value >= 0x010000 && Value <= 0xff0000) ||
1346 (Value >= 0x01000000 && Value <= 0xff000000);
1347 }
1348
1349 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001350 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001351 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1352 // Must be a constant.
1353 if (!CE) return false;
1354 int64_t Value = CE->getValue();
1355 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1356 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1357 return (Value >= 0 && Value < 256) ||
1358 (Value >= 0x0100 && Value <= 0xff00) ||
1359 (Value >= 0x010000 && Value <= 0xff0000) ||
1360 (Value >= 0x01000000 && Value <= 0xff000000) ||
1361 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1362 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1363 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001364 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001365 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001366 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1367 // Must be a constant.
1368 if (!CE) return false;
1369 int64_t Value = ~CE->getValue();
1370 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1371 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1372 return (Value >= 0 && Value < 256) ||
1373 (Value >= 0x0100 && Value <= 0xff00) ||
1374 (Value >= 0x010000 && Value <= 0xff0000) ||
1375 (Value >= 0x01000000 && Value <= 0xff000000) ||
1376 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1377 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1378 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001379
Jim Grosbache4454e02011-10-18 16:18:11 +00001380 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001381 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001382 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1383 // Must be a constant.
1384 if (!CE) return false;
1385 uint64_t Value = CE->getValue();
1386 // i64 value with each byte being either 0 or 0xff.
1387 for (unsigned i = 0; i < 8; ++i)
1388 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1389 return true;
1390 }
1391
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001392 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001393 // Add as immediates when possible. Null MCExpr = 0.
1394 if (Expr == 0)
1395 Inst.addOperand(MCOperand::CreateImm(0));
1396 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001397 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1398 else
1399 Inst.addOperand(MCOperand::CreateExpr(Expr));
1400 }
1401
Daniel Dunbard8042b72010-08-11 06:36:53 +00001402 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001403 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001404 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001405 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1406 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001407 }
1408
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001409 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1410 assert(N == 1 && "Invalid number of operands!");
1411 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1412 }
1413
Jim Grosbach48399582011-10-12 17:34:41 +00001414 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1415 assert(N == 1 && "Invalid number of operands!");
1416 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1417 }
1418
1419 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1420 assert(N == 1 && "Invalid number of operands!");
1421 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1422 }
1423
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001424 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1425 assert(N == 1 && "Invalid number of operands!");
1426 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1427 }
1428
1429 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1430 assert(N == 1 && "Invalid number of operands!");
1431 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1432 }
1433
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001434 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1435 assert(N == 1 && "Invalid number of operands!");
1436 Inst.addOperand(MCOperand::CreateReg(getReg()));
1437 }
1438
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001439 void addRegOperands(MCInst &Inst, unsigned N) const {
1440 assert(N == 1 && "Invalid number of operands!");
1441 Inst.addOperand(MCOperand::CreateReg(getReg()));
1442 }
1443
Jim Grosbachac798e12011-07-25 20:49:51 +00001444 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001445 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001446 assert(isRegShiftedReg() &&
1447 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001448 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1449 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001450 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001451 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001452 }
1453
Jim Grosbachac798e12011-07-25 20:49:51 +00001454 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001455 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001456 assert(isRegShiftedImm() &&
1457 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001458 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001459 // Shift of #32 is encoded as 0 where permitted
1460 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001461 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001462 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001463 }
1464
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001465 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001466 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001467 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1468 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001469 }
1470
Bill Wendling8d2aa032010-11-08 23:49:57 +00001471 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001472 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001473 const SmallVectorImpl<unsigned> &RegList = getRegList();
1474 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001475 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1476 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001477 }
1478
Bill Wendling9898ac92010-11-17 04:32:08 +00001479 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1480 addRegListOperands(Inst, N);
1481 }
1482
1483 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1484 addRegListOperands(Inst, N);
1485 }
1486
Jim Grosbach833b9d32011-07-27 20:15:40 +00001487 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1488 assert(N == 1 && "Invalid number of operands!");
1489 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1490 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1491 }
1492
Jim Grosbach864b6092011-07-28 21:34:26 +00001493 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1494 assert(N == 1 && "Invalid number of operands!");
1495 // Munge the lsb/width into a bitfield mask.
1496 unsigned lsb = Bitfield.LSB;
1497 unsigned width = Bitfield.Width;
1498 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1499 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1500 (32 - (lsb + width)));
1501 Inst.addOperand(MCOperand::CreateImm(Mask));
1502 }
1503
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001504 void addImmOperands(MCInst &Inst, unsigned N) const {
1505 assert(N == 1 && "Invalid number of operands!");
1506 addExpr(Inst, getImm());
1507 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001508
Jim Grosbachea231912011-12-22 22:19:05 +00001509 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1510 assert(N == 1 && "Invalid number of operands!");
1511 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1512 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1513 }
1514
1515 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1516 assert(N == 1 && "Invalid number of operands!");
1517 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1518 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1519 }
1520
Jim Grosbache7fbce72011-10-03 23:38:36 +00001521 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1522 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001523 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1524 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1525 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001526 }
1527
Jim Grosbach7db8d692011-09-08 22:07:06 +00001528 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1529 assert(N == 1 && "Invalid number of operands!");
1530 // FIXME: We really want to scale the value here, but the LDRD/STRD
1531 // instruction don't encode operands that way yet.
1532 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1533 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1534 }
1535
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001536 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1537 assert(N == 1 && "Invalid number of operands!");
1538 // The immediate is scaled by four in the encoding and is stored
1539 // in the MCInst as such. Lop off the low two bits here.
1540 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1541 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1542 }
1543
Jim Grosbach930f2f62012-04-05 20:57:13 +00001544 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1545 assert(N == 1 && "Invalid number of operands!");
1546 // The immediate is scaled by four in the encoding and is stored
1547 // in the MCInst as such. Lop off the low two bits here.
1548 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1549 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1550 }
1551
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001552 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1553 assert(N == 1 && "Invalid number of operands!");
1554 // The immediate is scaled by four in the encoding and is stored
1555 // in the MCInst as such. Lop off the low two bits here.
1556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1557 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1558 }
1559
Jim Grosbach475c6db2011-07-25 23:09:14 +00001560 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1561 assert(N == 1 && "Invalid number of operands!");
1562 // The constant encodes as the immediate-1, and we store in the instruction
1563 // the bits as encoded, so subtract off one here.
1564 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1565 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1566 }
1567
Jim Grosbach801e0a32011-07-22 23:16:18 +00001568 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1569 assert(N == 1 && "Invalid number of operands!");
1570 // The constant encodes as the immediate-1, and we store in the instruction
1571 // the bits as encoded, so subtract off one here.
1572 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1573 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1574 }
1575
Jim Grosbach46dd4132011-08-17 21:51:27 +00001576 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1577 assert(N == 1 && "Invalid number of operands!");
1578 // The constant encodes as the immediate, except for 32, which encodes as
1579 // zero.
1580 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1581 unsigned Imm = CE->getValue();
1582 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1583 }
1584
Jim Grosbach27c1e252011-07-21 17:23:04 +00001585 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1586 assert(N == 1 && "Invalid number of operands!");
1587 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1588 // the instruction as well.
1589 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1590 int Val = CE->getValue();
1591 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1592 }
1593
Jim Grosbachb009a872011-10-28 22:36:30 +00001594 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1595 assert(N == 1 && "Invalid number of operands!");
1596 // The operand is actually a t2_so_imm, but we have its bitwise
1597 // negation in the assembly source, so twiddle it here.
1598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1599 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1600 }
1601
Jim Grosbach30506252011-12-08 00:31:07 +00001602 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1603 assert(N == 1 && "Invalid number of operands!");
1604 // The operand is actually a t2_so_imm, but we have its
1605 // negation in the assembly source, so twiddle it here.
1606 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1607 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1608 }
1609
Jim Grosbach930f2f62012-04-05 20:57:13 +00001610 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1611 assert(N == 1 && "Invalid number of operands!");
1612 // The operand is actually an imm0_4095, but we have its
1613 // negation in the assembly source, so twiddle it here.
1614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1615 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1616 }
1617
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001618 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1619 assert(N == 1 && "Invalid number of operands!");
1620 // The operand is actually a so_imm, but we have its bitwise
1621 // negation in the assembly source, so twiddle it here.
1622 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1623 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1624 }
1625
Jim Grosbach30506252011-12-08 00:31:07 +00001626 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1627 assert(N == 1 && "Invalid number of operands!");
1628 // The operand is actually a so_imm, but we have its
1629 // negation in the assembly source, so twiddle it here.
1630 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1631 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1632 }
1633
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001634 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1635 assert(N == 1 && "Invalid number of operands!");
1636 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1637 }
1638
Jim Grosbachd3595712011-08-03 23:50:40 +00001639 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1640 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001641 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001642 }
1643
Jim Grosbach94298a92012-01-18 22:46:46 +00001644 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1645 assert(N == 1 && "Invalid number of operands!");
1646 int32_t Imm = Memory.OffsetImm->getValue();
1647 // FIXME: Handle #-0
1648 if (Imm == INT32_MIN) Imm = 0;
1649 Inst.addOperand(MCOperand::CreateImm(Imm));
1650 }
1651
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001652 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1653 assert(N == 1 && "Invalid number of operands!");
1654 assert(isImm() && "Not an immediate!");
1655
1656 // If we have an immediate that's not a constant, treat it as a label
1657 // reference needing a fixup.
1658 if (!isa<MCConstantExpr>(getImm())) {
1659 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1660 return;
1661 }
1662
1663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1664 int Val = CE->getValue();
1665 Inst.addOperand(MCOperand::CreateImm(Val));
1666 }
1667
Jim Grosbacha95ec992011-10-11 17:29:55 +00001668 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1669 assert(N == 2 && "Invalid number of operands!");
1670 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1671 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1672 }
1673
Jim Grosbachd3595712011-08-03 23:50:40 +00001674 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1675 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001676 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1677 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001678 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1679 // Special case for #-0
1680 if (Val == INT32_MIN) Val = 0;
1681 if (Val < 0) Val = -Val;
1682 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1683 } else {
1684 // For register offset, we encode the shift type and negation flag
1685 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001686 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1687 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001688 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001689 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1690 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001691 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001692 }
1693
Jim Grosbachcd17c122011-08-04 23:01:30 +00001694 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1695 assert(N == 2 && "Invalid number of operands!");
1696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1697 assert(CE && "non-constant AM2OffsetImm operand!");
1698 int32_t Val = CE->getValue();
1699 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1700 // Special case for #-0
1701 if (Val == INT32_MIN) Val = 0;
1702 if (Val < 0) Val = -Val;
1703 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1704 Inst.addOperand(MCOperand::CreateReg(0));
1705 Inst.addOperand(MCOperand::CreateImm(Val));
1706 }
1707
Jim Grosbach5b96b802011-08-10 20:29:19 +00001708 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1709 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001710 // If we have an immediate that's not a constant, treat it as a label
1711 // reference needing a fixup. If it is a constant, it's something else
1712 // and we reject it.
1713 if (isImm()) {
1714 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1715 Inst.addOperand(MCOperand::CreateReg(0));
1716 Inst.addOperand(MCOperand::CreateImm(0));
1717 return;
1718 }
1719
Jim Grosbach871dff72011-10-11 15:59:20 +00001720 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1721 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001722 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1723 // Special case for #-0
1724 if (Val == INT32_MIN) Val = 0;
1725 if (Val < 0) Val = -Val;
1726 Val = ARM_AM::getAM3Opc(AddSub, Val);
1727 } else {
1728 // For register offset, we encode the shift type and negation flag
1729 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001730 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001731 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001732 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1733 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001734 Inst.addOperand(MCOperand::CreateImm(Val));
1735 }
1736
1737 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1738 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001739 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001740 int32_t Val =
1741 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1742 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1743 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001744 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001745 }
1746
1747 // Constant offset.
1748 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1749 int32_t Val = CE->getValue();
1750 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1751 // Special case for #-0
1752 if (Val == INT32_MIN) Val = 0;
1753 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001754 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001755 Inst.addOperand(MCOperand::CreateReg(0));
1756 Inst.addOperand(MCOperand::CreateImm(Val));
1757 }
1758
Jim Grosbachd3595712011-08-03 23:50:40 +00001759 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1760 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001761 // If we have an immediate that's not a constant, treat it as a label
1762 // reference needing a fixup. If it is a constant, it's something else
1763 // and we reject it.
1764 if (isImm()) {
1765 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1766 Inst.addOperand(MCOperand::CreateImm(0));
1767 return;
1768 }
1769
Jim Grosbachd3595712011-08-03 23:50:40 +00001770 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001771 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001772 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1773 // Special case for #-0
1774 if (Val == INT32_MIN) Val = 0;
1775 if (Val < 0) Val = -Val;
1776 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001777 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001778 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001779 }
1780
Jim Grosbach7db8d692011-09-08 22:07:06 +00001781 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1782 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001783 // If we have an immediate that's not a constant, treat it as a label
1784 // reference needing a fixup. If it is a constant, it's something else
1785 // and we reject it.
1786 if (isImm()) {
1787 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1788 Inst.addOperand(MCOperand::CreateImm(0));
1789 return;
1790 }
1791
Jim Grosbach871dff72011-10-11 15:59:20 +00001792 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1793 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001794 Inst.addOperand(MCOperand::CreateImm(Val));
1795 }
1796
Jim Grosbacha05627e2011-09-09 18:37:27 +00001797 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1798 assert(N == 2 && "Invalid number of operands!");
1799 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001800 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1801 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001802 Inst.addOperand(MCOperand::CreateImm(Val));
1803 }
1804
Jim Grosbachd3595712011-08-03 23:50:40 +00001805 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1806 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001807 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1808 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001809 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001810 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001811
Jim Grosbach2392c532011-09-07 23:39:14 +00001812 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1813 addMemImm8OffsetOperands(Inst, N);
1814 }
1815
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001816 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001817 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001818 }
1819
1820 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1821 assert(N == 2 && "Invalid number of operands!");
1822 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001823 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001824 addExpr(Inst, getImm());
1825 Inst.addOperand(MCOperand::CreateImm(0));
1826 return;
1827 }
1828
1829 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001830 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1831 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001832 Inst.addOperand(MCOperand::CreateImm(Val));
1833 }
1834
Jim Grosbachd3595712011-08-03 23:50:40 +00001835 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1836 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001837 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001838 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001839 addExpr(Inst, getImm());
1840 Inst.addOperand(MCOperand::CreateImm(0));
1841 return;
1842 }
1843
1844 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001845 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1846 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001847 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001848 }
Bill Wendling811c9362010-11-30 07:44:32 +00001849
Jim Grosbach05541f42011-09-19 22:21:13 +00001850 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1851 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001852 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1853 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001854 }
1855
1856 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1857 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001858 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1859 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001860 }
1861
Jim Grosbachd3595712011-08-03 23:50:40 +00001862 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1863 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001864 unsigned Val =
1865 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1866 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001867 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1868 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001869 Inst.addOperand(MCOperand::CreateImm(Val));
1870 }
1871
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001872 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1873 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001874 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1875 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1876 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001877 }
1878
Jim Grosbachd3595712011-08-03 23:50:40 +00001879 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1880 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001881 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1882 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001883 }
1884
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001885 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1886 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001887 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1888 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001889 Inst.addOperand(MCOperand::CreateImm(Val));
1890 }
1891
Jim Grosbach26d35872011-08-19 18:55:51 +00001892 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1893 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001894 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1895 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00001896 Inst.addOperand(MCOperand::CreateImm(Val));
1897 }
1898
Jim Grosbacha32c7532011-08-19 18:49:59 +00001899 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1900 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001901 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1902 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00001903 Inst.addOperand(MCOperand::CreateImm(Val));
1904 }
1905
Jim Grosbach23983d62011-08-19 18:13:48 +00001906 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1907 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001908 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1909 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00001910 Inst.addOperand(MCOperand::CreateImm(Val));
1911 }
1912
Jim Grosbachd3595712011-08-03 23:50:40 +00001913 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1914 assert(N == 1 && "Invalid number of operands!");
1915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1916 assert(CE && "non-constant post-idx-imm8 operand!");
1917 int Imm = CE->getValue();
1918 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00001919 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001920 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1921 Inst.addOperand(MCOperand::CreateImm(Imm));
1922 }
1923
Jim Grosbach93981412011-10-11 21:55:36 +00001924 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1925 assert(N == 1 && "Invalid number of operands!");
1926 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1927 assert(CE && "non-constant post-idx-imm8s4 operand!");
1928 int Imm = CE->getValue();
1929 bool isAdd = Imm >= 0;
1930 if (Imm == INT32_MIN) Imm = 0;
1931 // Immediate is scaled by 4.
1932 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1933 Inst.addOperand(MCOperand::CreateImm(Imm));
1934 }
1935
Jim Grosbachd3595712011-08-03 23:50:40 +00001936 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1937 assert(N == 2 && "Invalid number of operands!");
1938 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00001939 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1940 }
1941
1942 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1943 assert(N == 2 && "Invalid number of operands!");
1944 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1945 // The sign, shift type, and shift amount are encoded in a single operand
1946 // using the AM2 encoding helpers.
1947 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1948 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1949 PostIdxReg.ShiftTy);
1950 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00001951 }
1952
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00001953 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1954 assert(N == 1 && "Invalid number of operands!");
1955 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1956 }
1957
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00001958 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1959 assert(N == 1 && "Invalid number of operands!");
1960 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1961 }
1962
Jim Grosbach182b6a02011-11-29 23:51:09 +00001963 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001964 assert(N == 1 && "Invalid number of operands!");
1965 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1966 }
1967
Jim Grosbach04945c42011-12-02 00:35:16 +00001968 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1969 assert(N == 2 && "Invalid number of operands!");
1970 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1971 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1972 }
1973
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001974 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1975 assert(N == 1 && "Invalid number of operands!");
1976 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1977 }
1978
1979 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1980 assert(N == 1 && "Invalid number of operands!");
1981 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1982 }
1983
1984 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1985 assert(N == 1 && "Invalid number of operands!");
1986 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1987 }
1988
Jim Grosbach741cd732011-10-17 22:26:03 +00001989 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1990 assert(N == 1 && "Invalid number of operands!");
1991 // The immediate encodes the type of constant as well as the value.
1992 // Mask in that this is an i8 splat.
1993 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1994 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1995 }
1996
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001997 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1998 assert(N == 1 && "Invalid number of operands!");
1999 // The immediate encodes the type of constant as well as the value.
2000 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2001 unsigned Value = CE->getValue();
2002 if (Value >= 256)
2003 Value = (Value >> 8) | 0xa00;
2004 else
2005 Value |= 0x800;
2006 Inst.addOperand(MCOperand::CreateImm(Value));
2007 }
2008
Jim Grosbach8211c052011-10-18 00:22:00 +00002009 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2010 assert(N == 1 && "Invalid number of operands!");
2011 // The immediate encodes the type of constant as well as the value.
2012 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2013 unsigned Value = CE->getValue();
2014 if (Value >= 256 && Value <= 0xff00)
2015 Value = (Value >> 8) | 0x200;
2016 else if (Value > 0xffff && Value <= 0xff0000)
2017 Value = (Value >> 16) | 0x400;
2018 else if (Value > 0xffffff)
2019 Value = (Value >> 24) | 0x600;
2020 Inst.addOperand(MCOperand::CreateImm(Value));
2021 }
2022
2023 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2024 assert(N == 1 && "Invalid number of operands!");
2025 // The immediate encodes the type of constant as well as the value.
2026 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2027 unsigned Value = CE->getValue();
2028 if (Value >= 256 && Value <= 0xffff)
2029 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2030 else if (Value > 0xffff && Value <= 0xffffff)
2031 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2032 else if (Value > 0xffffff)
2033 Value = (Value >> 24) | 0x600;
2034 Inst.addOperand(MCOperand::CreateImm(Value));
2035 }
2036
Jim Grosbach045b6c72011-12-19 23:51:07 +00002037 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2038 assert(N == 1 && "Invalid number of operands!");
2039 // The immediate encodes the type of constant as well as the value.
2040 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2041 unsigned Value = ~CE->getValue();
2042 if (Value >= 256 && Value <= 0xffff)
2043 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2044 else if (Value > 0xffff && Value <= 0xffffff)
2045 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2046 else if (Value > 0xffffff)
2047 Value = (Value >> 24) | 0x600;
2048 Inst.addOperand(MCOperand::CreateImm(Value));
2049 }
2050
Jim Grosbache4454e02011-10-18 16:18:11 +00002051 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2052 assert(N == 1 && "Invalid number of operands!");
2053 // The immediate encodes the type of constant as well as the value.
2054 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2055 uint64_t Value = CE->getValue();
2056 unsigned Imm = 0;
2057 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2058 Imm |= (Value & 1) << i;
2059 }
2060 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2061 }
2062
Jim Grosbach602aa902011-07-13 15:34:57 +00002063 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002064
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002065 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002066 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002067 Op->ITMask.Mask = Mask;
2068 Op->StartLoc = S;
2069 Op->EndLoc = S;
2070 return Op;
2071 }
2072
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002073 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002074 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002075 Op->CC.Val = CC;
2076 Op->StartLoc = S;
2077 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002078 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002079 }
2080
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002081 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002082 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002083 Op->Cop.Val = CopVal;
2084 Op->StartLoc = S;
2085 Op->EndLoc = S;
2086 return Op;
2087 }
2088
2089 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002090 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002091 Op->Cop.Val = CopVal;
2092 Op->StartLoc = S;
2093 Op->EndLoc = S;
2094 return Op;
2095 }
2096
Jim Grosbach48399582011-10-12 17:34:41 +00002097 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2098 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2099 Op->Cop.Val = Val;
2100 Op->StartLoc = S;
2101 Op->EndLoc = E;
2102 return Op;
2103 }
2104
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002105 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002106 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002107 Op->Reg.RegNum = RegNum;
2108 Op->StartLoc = S;
2109 Op->EndLoc = S;
2110 return Op;
2111 }
2112
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002113 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002114 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002115 Op->Tok.Data = Str.data();
2116 Op->Tok.Length = Str.size();
2117 Op->StartLoc = S;
2118 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002119 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002120 }
2121
Bill Wendling2063b842010-11-18 23:43:05 +00002122 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002123 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002124 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002125 Op->StartLoc = S;
2126 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002127 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002128 }
2129
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002130 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2131 unsigned SrcReg,
2132 unsigned ShiftReg,
2133 unsigned ShiftImm,
2134 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002135 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002136 Op->RegShiftedReg.ShiftTy = ShTy;
2137 Op->RegShiftedReg.SrcReg = SrcReg;
2138 Op->RegShiftedReg.ShiftReg = ShiftReg;
2139 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002140 Op->StartLoc = S;
2141 Op->EndLoc = E;
2142 return Op;
2143 }
2144
Owen Andersonb595ed02011-07-21 18:54:16 +00002145 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2146 unsigned SrcReg,
2147 unsigned ShiftImm,
2148 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002149 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002150 Op->RegShiftedImm.ShiftTy = ShTy;
2151 Op->RegShiftedImm.SrcReg = SrcReg;
2152 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002153 Op->StartLoc = S;
2154 Op->EndLoc = E;
2155 return Op;
2156 }
2157
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002158 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002159 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002160 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002161 Op->ShifterImm.isASR = isASR;
2162 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002163 Op->StartLoc = S;
2164 Op->EndLoc = E;
2165 return Op;
2166 }
2167
Jim Grosbach833b9d32011-07-27 20:15:40 +00002168 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002169 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002170 Op->RotImm.Imm = Imm;
2171 Op->StartLoc = S;
2172 Op->EndLoc = E;
2173 return Op;
2174 }
2175
Jim Grosbach864b6092011-07-28 21:34:26 +00002176 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2177 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002178 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002179 Op->Bitfield.LSB = LSB;
2180 Op->Bitfield.Width = Width;
2181 Op->StartLoc = S;
2182 Op->EndLoc = E;
2183 return Op;
2184 }
2185
Bill Wendling2cae3272010-11-09 22:44:22 +00002186 static ARMOperand *
Bill Wendlingbed94652010-11-09 23:28:44 +00002187 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002188 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002189 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002190
Jim Grosbach75461af2011-09-13 22:56:44 +00002191 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002192 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002193 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng9eec7642011-07-25 21:32:49 +00002194 contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002195 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002196
2197 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendlingbed94652010-11-09 23:28:44 +00002198 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002199 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling0ab0f672010-11-18 21:50:54 +00002200 Op->Registers.push_back(I->first);
Bill Wendling20b5ea982010-11-19 00:38:19 +00002201 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002202 Op->StartLoc = StartLoc;
2203 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002204 return Op;
2205 }
2206
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002207 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002208 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002209 ARMOperand *Op = new ARMOperand(k_VectorList);
2210 Op->VectorList.RegNum = RegNum;
2211 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002212 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002213 Op->StartLoc = S;
2214 Op->EndLoc = E;
2215 return Op;
2216 }
2217
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002218 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002219 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002220 SMLoc S, SMLoc E) {
2221 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2222 Op->VectorList.RegNum = RegNum;
2223 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002224 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002225 Op->StartLoc = S;
2226 Op->EndLoc = E;
2227 return Op;
2228 }
2229
Jim Grosbach04945c42011-12-02 00:35:16 +00002230 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002231 unsigned Index,
2232 bool isDoubleSpaced,
2233 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002234 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2235 Op->VectorList.RegNum = RegNum;
2236 Op->VectorList.Count = Count;
2237 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002238 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002239 Op->StartLoc = S;
2240 Op->EndLoc = E;
2241 return Op;
2242 }
2243
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002244 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2245 MCContext &Ctx) {
2246 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2247 Op->VectorIndex.Val = Idx;
2248 Op->StartLoc = S;
2249 Op->EndLoc = E;
2250 return Op;
2251 }
2252
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002253 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002254 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002255 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002256 Op->StartLoc = S;
2257 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002258 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002259 }
2260
Jim Grosbachd3595712011-08-03 23:50:40 +00002261 static ARMOperand *CreateMem(unsigned BaseRegNum,
2262 const MCConstantExpr *OffsetImm,
2263 unsigned OffsetRegNum,
2264 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002265 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002266 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002267 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002268 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002269 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002270 Op->Memory.BaseRegNum = BaseRegNum;
2271 Op->Memory.OffsetImm = OffsetImm;
2272 Op->Memory.OffsetRegNum = OffsetRegNum;
2273 Op->Memory.ShiftType = ShiftType;
2274 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002275 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002276 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002277 Op->StartLoc = S;
2278 Op->EndLoc = E;
2279 return Op;
2280 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002281
Jim Grosbachc320c852011-08-05 21:28:30 +00002282 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2283 ARM_AM::ShiftOpc ShiftTy,
2284 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002285 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002286 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002287 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002288 Op->PostIdxReg.isAdd = isAdd;
2289 Op->PostIdxReg.ShiftTy = ShiftTy;
2290 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002291 Op->StartLoc = S;
2292 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002293 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002294 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002295
2296 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002297 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002298 Op->MBOpt.Val = Opt;
2299 Op->StartLoc = S;
2300 Op->EndLoc = S;
2301 return Op;
2302 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002303
2304 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002305 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002306 Op->IFlags.Val = IFlags;
2307 Op->StartLoc = S;
2308 Op->EndLoc = S;
2309 return Op;
2310 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002311
2312 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002313 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002314 Op->MMask.Val = MMask;
2315 Op->StartLoc = S;
2316 Op->EndLoc = S;
2317 return Op;
2318 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002319};
2320
2321} // end anonymous namespace.
2322
Jim Grosbach602aa902011-07-13 15:34:57 +00002323void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002324 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002325 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002326 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002327 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002328 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002329 OS << "<ccout " << getReg() << ">";
2330 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002331 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002332 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002333 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2334 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2335 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002336 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2337 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2338 break;
2339 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002340 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002341 OS << "<coprocessor number: " << getCoproc() << ">";
2342 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002343 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002344 OS << "<coprocessor register: " << getCoproc() << ">";
2345 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002346 case k_CoprocOption:
2347 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2348 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002349 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002350 OS << "<mask: " << getMSRMask() << ">";
2351 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002352 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002353 getImm()->print(OS);
2354 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002355 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002356 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2357 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002358 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002359 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002360 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002361 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002362 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002363 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002364 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2365 << PostIdxReg.RegNum;
2366 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2367 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2368 << PostIdxReg.ShiftImm;
2369 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002370 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002371 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002372 OS << "<ARM_PROC::";
2373 unsigned IFlags = getProcIFlags();
2374 for (int i=2; i >= 0; --i)
2375 if (IFlags & (1 << i))
2376 OS << ARM_PROC::IFlagsToString(1 << i);
2377 OS << ">";
2378 break;
2379 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002380 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002381 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002382 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002383 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002384 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2385 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002386 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002387 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002388 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002389 << RegShiftedReg.SrcReg << " "
2390 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2391 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002392 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002393 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002394 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002395 << RegShiftedImm.SrcReg << " "
2396 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2397 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002398 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002399 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002400 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2401 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002402 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002403 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2404 << ", width: " << Bitfield.Width << ">";
2405 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002406 case k_RegisterList:
2407 case k_DPRRegisterList:
2408 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002409 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002410
Bill Wendlingbed94652010-11-09 23:28:44 +00002411 const SmallVectorImpl<unsigned> &RegList = getRegList();
2412 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002413 I = RegList.begin(), E = RegList.end(); I != E; ) {
2414 OS << *I;
2415 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002416 }
2417
2418 OS << ">";
2419 break;
2420 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002421 case k_VectorList:
2422 OS << "<vector_list " << VectorList.Count << " * "
2423 << VectorList.RegNum << ">";
2424 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002425 case k_VectorListAllLanes:
2426 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2427 << VectorList.RegNum << ">";
2428 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002429 case k_VectorListIndexed:
2430 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2431 << VectorList.Count << " * " << VectorList.RegNum << ">";
2432 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002433 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002434 OS << "'" << getToken() << "'";
2435 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002436 case k_VectorIndex:
2437 OS << "<vectorindex " << getVectorIndex() << ">";
2438 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002439 }
2440}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002441
2442/// @name Auto-generated Match Functions
2443/// {
2444
2445static unsigned MatchRegisterName(StringRef Name);
2446
2447/// }
2448
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002449bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2450 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002451 StartLoc = Parser.getTok().getLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002452 RegNo = tryParseRegister();
Jim Grosbachab5830e2011-12-14 02:16:11 +00002453 EndLoc = Parser.getTok().getLoc();
Roman Divacky36b1b472011-01-27 17:14:22 +00002454
2455 return (RegNo == (unsigned)-1);
2456}
2457
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002458/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002459/// and if it is a register name the token is eaten and the register number is
2460/// returned. Otherwise return -1.
2461///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002462int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002463 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002464 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002465
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002466 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002467 unsigned RegNum = MatchRegisterName(lowerCase);
2468 if (!RegNum) {
2469 RegNum = StringSwitch<unsigned>(lowerCase)
2470 .Case("r13", ARM::SP)
2471 .Case("r14", ARM::LR)
2472 .Case("r15", ARM::PC)
2473 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002474 // Additional register name aliases for 'gas' compatibility.
2475 .Case("a1", ARM::R0)
2476 .Case("a2", ARM::R1)
2477 .Case("a3", ARM::R2)
2478 .Case("a4", ARM::R3)
2479 .Case("v1", ARM::R4)
2480 .Case("v2", ARM::R5)
2481 .Case("v3", ARM::R6)
2482 .Case("v4", ARM::R7)
2483 .Case("v5", ARM::R8)
2484 .Case("v6", ARM::R9)
2485 .Case("v7", ARM::R10)
2486 .Case("v8", ARM::R11)
2487 .Case("sb", ARM::R9)
2488 .Case("sl", ARM::R10)
2489 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002490 .Default(0);
2491 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002492 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002493 // Check for aliases registered via .req. Canonicalize to lower case.
2494 // That's more consistent since register names are case insensitive, and
2495 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2496 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002497 // If no match, return failure.
2498 if (Entry == RegisterReqs.end())
2499 return -1;
2500 Parser.Lex(); // Eat identifier token.
2501 return Entry->getValue();
2502 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002503
Chris Lattner44e5981c2010-10-30 04:09:10 +00002504 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002505
Chris Lattner44e5981c2010-10-30 04:09:10 +00002506 return RegNum;
2507}
Jim Grosbach99710a82010-11-01 16:44:21 +00002508
Jim Grosbachbb24c592011-07-13 18:49:30 +00002509// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2510// If a recoverable error occurs, return 1. If an irrecoverable error
2511// occurs, return -1. An irrecoverable error is one where tokens have been
2512// consumed in the process of trying to parse the shifter (i.e., when it is
2513// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002514int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002515 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2516 SMLoc S = Parser.getTok().getLoc();
2517 const AsmToken &Tok = Parser.getTok();
2518 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2519
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002520 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002521 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002522 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002523 .Case("lsl", ARM_AM::lsl)
2524 .Case("lsr", ARM_AM::lsr)
2525 .Case("asr", ARM_AM::asr)
2526 .Case("ror", ARM_AM::ror)
2527 .Case("rrx", ARM_AM::rrx)
2528 .Default(ARM_AM::no_shift);
2529
2530 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002531 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002532
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002533 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002534
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002535 // The source register for the shift has already been added to the
2536 // operand list, so we need to pop it off and combine it into the shifted
2537 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002538 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002539 if (!PrevOp->isReg())
2540 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2541 int SrcReg = PrevOp->getReg();
2542 int64_t Imm = 0;
2543 int ShiftReg = 0;
2544 if (ShiftTy == ARM_AM::rrx) {
2545 // RRX Doesn't have an explicit shift amount. The encoder expects
2546 // the shift register to be the same as the source register. Seems odd,
2547 // but OK.
2548 ShiftReg = SrcReg;
2549 } else {
2550 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002551 if (Parser.getTok().is(AsmToken::Hash) ||
2552 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002553 Parser.Lex(); // Eat hash.
2554 SMLoc ImmLoc = Parser.getTok().getLoc();
2555 const MCExpr *ShiftExpr = 0;
Jim Grosbachbb24c592011-07-13 18:49:30 +00002556 if (getParser().ParseExpression(ShiftExpr)) {
2557 Error(ImmLoc, "invalid immediate shift value");
2558 return -1;
2559 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002560 // The expression must be evaluatable as an immediate.
2561 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002562 if (!CE) {
2563 Error(ImmLoc, "invalid immediate shift value");
2564 return -1;
2565 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002566 // Range check the immediate.
2567 // lsl, ror: 0 <= imm <= 31
2568 // lsr, asr: 0 <= imm <= 32
2569 Imm = CE->getValue();
2570 if (Imm < 0 ||
2571 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2572 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002573 Error(ImmLoc, "immediate shift value out of range");
2574 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002575 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002576 // shift by zero is a nop. Always send it through as lsl.
2577 // ('as' compatibility)
2578 if (Imm == 0)
2579 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002580 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002581 ShiftReg = tryParseRegister();
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002582 SMLoc L = Parser.getTok().getLoc();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002583 if (ShiftReg == -1) {
2584 Error (L, "expected immediate or register in shift operand");
2585 return -1;
2586 }
2587 } else {
2588 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002589 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002590 return -1;
2591 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002592 }
2593
Owen Andersonb595ed02011-07-21 18:54:16 +00002594 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2595 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002596 ShiftReg, Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002597 S, Parser.getTok().getLoc()));
Owen Andersonb595ed02011-07-21 18:54:16 +00002598 else
2599 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2600 S, Parser.getTok().getLoc()));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002601
Jim Grosbachbb24c592011-07-13 18:49:30 +00002602 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002603}
2604
2605
Bill Wendling2063b842010-11-18 23:43:05 +00002606/// Try to parse a register name. The token must be an Identifier when called.
2607/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2608/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002609///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002610/// TODO this is likely to change to allow different register types and or to
2611/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002612bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002613tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002614 SMLoc S = Parser.getTok().getLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002615 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002616 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002617 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002618
Bill Wendling2063b842010-11-18 23:43:05 +00002619 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002620
Chris Lattner44e5981c2010-10-30 04:09:10 +00002621 const AsmToken &ExclaimTok = Parser.getTok();
2622 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002623 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2624 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002625 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002626 return false;
2627 }
2628
2629 // Also check for an index operand. This is only legal for vector registers,
2630 // but that'll get caught OK in operand matching, so we don't need to
2631 // explicitly filter everything else out here.
2632 if (Parser.getTok().is(AsmToken::LBrac)) {
2633 SMLoc SIdx = Parser.getTok().getLoc();
2634 Parser.Lex(); // Eat left bracket token.
2635
2636 const MCExpr *ImmVal;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002637 if (getParser().ParseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002638 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002639 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002640 if (!MCE)
2641 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002642
2643 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002644 if (Parser.getTok().isNot(AsmToken::RBrac))
2645 return Error(E, "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002646
2647 Parser.Lex(); // Eat right bracket token.
2648
2649 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2650 SIdx, E,
2651 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002652 }
2653
Bill Wendling2063b842010-11-18 23:43:05 +00002654 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002655}
2656
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002657/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2658/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2659/// "c5", ...
2660static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002661 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2662 // but efficient.
2663 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002664 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002665 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002666 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002667 return -1;
2668 switch (Name[1]) {
2669 default: return -1;
2670 case '0': return 0;
2671 case '1': return 1;
2672 case '2': return 2;
2673 case '3': return 3;
2674 case '4': return 4;
2675 case '5': return 5;
2676 case '6': return 6;
2677 case '7': return 7;
2678 case '8': return 8;
2679 case '9': return 9;
2680 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002681 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002682 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002683 return -1;
2684 switch (Name[2]) {
2685 default: return -1;
2686 case '0': return 10;
2687 case '1': return 11;
2688 case '2': return 12;
2689 case '3': return 13;
2690 case '4': return 14;
2691 case '5': return 15;
2692 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002693 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002694}
2695
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002696/// parseITCondCode - Try to parse a condition code for an IT instruction.
2697ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2698parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2699 SMLoc S = Parser.getTok().getLoc();
2700 const AsmToken &Tok = Parser.getTok();
2701 if (!Tok.is(AsmToken::Identifier))
2702 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002703 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002704 .Case("eq", ARMCC::EQ)
2705 .Case("ne", ARMCC::NE)
2706 .Case("hs", ARMCC::HS)
2707 .Case("cs", ARMCC::HS)
2708 .Case("lo", ARMCC::LO)
2709 .Case("cc", ARMCC::LO)
2710 .Case("mi", ARMCC::MI)
2711 .Case("pl", ARMCC::PL)
2712 .Case("vs", ARMCC::VS)
2713 .Case("vc", ARMCC::VC)
2714 .Case("hi", ARMCC::HI)
2715 .Case("ls", ARMCC::LS)
2716 .Case("ge", ARMCC::GE)
2717 .Case("lt", ARMCC::LT)
2718 .Case("gt", ARMCC::GT)
2719 .Case("le", ARMCC::LE)
2720 .Case("al", ARMCC::AL)
2721 .Default(~0U);
2722 if (CC == ~0U)
2723 return MatchOperand_NoMatch;
2724 Parser.Lex(); // Eat the token.
2725
2726 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2727
2728 return MatchOperand_Success;
2729}
2730
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002731/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002732/// token must be an Identifier when called, and if it is a coprocessor
2733/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002734ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002735parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002736 SMLoc S = Parser.getTok().getLoc();
2737 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002738 if (Tok.isNot(AsmToken::Identifier))
2739 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002740
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002741 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002742 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002743 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002744
2745 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002746 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002747 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002748}
2749
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002750/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002751/// token must be an Identifier when called, and if it is a coprocessor
2752/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002753ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002754parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002755 SMLoc S = Parser.getTok().getLoc();
2756 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002757 if (Tok.isNot(AsmToken::Identifier))
2758 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002759
2760 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2761 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002762 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002763
2764 Parser.Lex(); // Eat identifier token.
2765 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002766 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002767}
2768
Jim Grosbach48399582011-10-12 17:34:41 +00002769/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2770/// coproc_option : '{' imm0_255 '}'
2771ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2772parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2773 SMLoc S = Parser.getTok().getLoc();
2774
2775 // If this isn't a '{', this isn't a coprocessor immediate operand.
2776 if (Parser.getTok().isNot(AsmToken::LCurly))
2777 return MatchOperand_NoMatch;
2778 Parser.Lex(); // Eat the '{'
2779
2780 const MCExpr *Expr;
2781 SMLoc Loc = Parser.getTok().getLoc();
2782 if (getParser().ParseExpression(Expr)) {
2783 Error(Loc, "illegal expression");
2784 return MatchOperand_ParseFail;
2785 }
2786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2787 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2788 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2789 return MatchOperand_ParseFail;
2790 }
2791 int Val = CE->getValue();
2792
2793 // Check for and consume the closing '}'
2794 if (Parser.getTok().isNot(AsmToken::RCurly))
2795 return MatchOperand_ParseFail;
2796 SMLoc E = Parser.getTok().getLoc();
2797 Parser.Lex(); // Eat the '}'
2798
2799 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2800 return MatchOperand_Success;
2801}
2802
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002803// For register list parsing, we need to map from raw GPR register numbering
2804// to the enumeration values. The enumeration values aren't sorted by
2805// register number due to our using "sp", "lr" and "pc" as canonical names.
2806static unsigned getNextRegister(unsigned Reg) {
2807 // If this is a GPR, we need to do it manually, otherwise we can rely
2808 // on the sort ordering of the enumeration since the other reg-classes
2809 // are sane.
2810 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2811 return Reg + 1;
2812 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002813 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002814 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2815 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2816 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2817 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2818 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2819 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2820 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2821 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2822 }
2823}
2824
Jim Grosbach85a23432011-11-11 21:27:40 +00002825// Return the low-subreg of a given Q register.
2826static unsigned getDRegFromQReg(unsigned QReg) {
2827 switch (QReg) {
2828 default: llvm_unreachable("expected a Q register!");
2829 case ARM::Q0: return ARM::D0;
2830 case ARM::Q1: return ARM::D2;
2831 case ARM::Q2: return ARM::D4;
2832 case ARM::Q3: return ARM::D6;
2833 case ARM::Q4: return ARM::D8;
2834 case ARM::Q5: return ARM::D10;
2835 case ARM::Q6: return ARM::D12;
2836 case ARM::Q7: return ARM::D14;
2837 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002838 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002839 case ARM::Q10: return ARM::D20;
2840 case ARM::Q11: return ARM::D22;
2841 case ARM::Q12: return ARM::D24;
2842 case ARM::Q13: return ARM::D26;
2843 case ARM::Q14: return ARM::D28;
2844 case ARM::Q15: return ARM::D30;
2845 }
2846}
2847
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002848/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002849bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002850parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002851 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002852 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00002853 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002854 Parser.Lex(); // Eat '{' token.
2855 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00002856
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002857 // Check the first register in the list to see what register class
2858 // this is a list of.
2859 int Reg = tryParseRegister();
2860 if (Reg == -1)
2861 return Error(RegLoc, "register expected");
2862
Jim Grosbach85a23432011-11-11 21:27:40 +00002863 // The reglist instructions have at most 16 registers, so reserve
2864 // space for that many.
2865 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2866
2867 // Allow Q regs and just interpret them as the two D sub-registers.
2868 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2869 Reg = getDRegFromQReg(Reg);
2870 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2871 ++Reg;
2872 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002873 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002874 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2875 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2876 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2877 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2878 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2879 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2880 else
2881 return Error(RegLoc, "invalid register in register list");
2882
Jim Grosbach85a23432011-11-11 21:27:40 +00002883 // Store the register.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002884 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbya2b99102009-10-09 21:12:28 +00002885
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002886 // This starts immediately after the first register token in the list,
2887 // so we can see either a comma or a minus (range separator) as a legal
2888 // next token.
2889 while (Parser.getTok().is(AsmToken::Comma) ||
2890 Parser.getTok().is(AsmToken::Minus)) {
2891 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00002892 Parser.Lex(); // Eat the minus.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002893 SMLoc EndLoc = Parser.getTok().getLoc();
2894 int EndReg = tryParseRegister();
2895 if (EndReg == -1)
2896 return Error(EndLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002897 // Allow Q regs and just interpret them as the two D sub-registers.
2898 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2899 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002900 // If the register is the same as the start reg, there's nothing
2901 // more to do.
2902 if (Reg == EndReg)
2903 continue;
2904 // The register must be in the same register class as the first.
2905 if (!RC->contains(EndReg))
2906 return Error(EndLoc, "invalid register in register list");
2907 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002908 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002909 return Error(EndLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00002910
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002911 // Add all the registers in the range to the register list.
2912 while (Reg != EndReg) {
2913 Reg = getNextRegister(Reg);
2914 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2915 }
2916 continue;
2917 }
2918 Parser.Lex(); // Eat the comma.
2919 RegLoc = Parser.getTok().getLoc();
2920 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00002921 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002922 Reg = tryParseRegister();
2923 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00002924 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002925 // Allow Q regs and just interpret them as the two D sub-registers.
2926 bool isQReg = false;
2927 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2928 Reg = getDRegFromQReg(Reg);
2929 isQReg = true;
2930 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002931 // The register must be in the same register class as the first.
2932 if (!RC->contains(Reg))
2933 return Error(RegLoc, "invalid register in register list");
2934 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002935 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00002936 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2937 Warning(RegLoc, "register list not in ascending order");
2938 else
2939 return Error(RegLoc, "register list not in ascending order");
2940 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00002941 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00002942 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2943 ") in register list");
2944 continue;
2945 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002946 // VFP register lists must also be contiguous.
2947 // It's OK to use the enumeration values directly here rather, as the
2948 // VFP register classes have the enum sorted properly.
2949 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2950 Reg != OldReg + 1)
2951 return Error(RegLoc, "non-contiguous register range");
2952 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbach85a23432011-11-11 21:27:40 +00002953 if (isQReg)
2954 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge18980a2010-11-06 22:36:58 +00002955 }
2956
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002957 SMLoc E = Parser.getTok().getLoc();
2958 if (Parser.getTok().isNot(AsmToken::RCurly))
2959 return Error(E, "'}' expected");
2960 Parser.Lex(); // Eat '}' token.
2961
Jim Grosbach18bf3632011-12-13 21:48:29 +00002962 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00002963 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00002964
2965 // The ARM system instruction variants for LDM/STM have a '^' token here.
2966 if (Parser.getTok().is(AsmToken::Caret)) {
2967 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2968 Parser.Lex(); // Eat '^' token.
2969 }
2970
Bill Wendling2063b842010-11-18 23:43:05 +00002971 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00002972}
2973
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002974// Helper function to parse the lane index for vector lists.
2975ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach04945c42011-12-02 00:35:16 +00002976parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2977 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002978 if (Parser.getTok().is(AsmToken::LBrac)) {
2979 Parser.Lex(); // Eat the '['.
2980 if (Parser.getTok().is(AsmToken::RBrac)) {
2981 // "Dn[]" is the 'all lanes' syntax.
2982 LaneKind = AllLanes;
2983 Parser.Lex(); // Eat the ']'.
2984 return MatchOperand_Success;
2985 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00002986
2987 // There's an optional '#' token here. Normally there wouldn't be, but
2988 // inline assemble puts one in, and it's friendly to accept that.
2989 if (Parser.getTok().is(AsmToken::Hash))
2990 Parser.Lex(); // Eat the '#'
2991
Jim Grosbach7de7ab82011-12-21 01:19:23 +00002992 const MCExpr *LaneIndex;
2993 SMLoc Loc = Parser.getTok().getLoc();
2994 if (getParser().ParseExpression(LaneIndex)) {
2995 Error(Loc, "illegal expression");
2996 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00002997 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00002998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2999 if (!CE) {
3000 Error(Loc, "lane index must be empty or an integer");
3001 return MatchOperand_ParseFail;
3002 }
3003 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3004 Error(Parser.getTok().getLoc(), "']' expected");
3005 return MatchOperand_ParseFail;
3006 }
3007 Parser.Lex(); // Eat the ']'.
3008 int64_t Val = CE->getValue();
3009
3010 // FIXME: Make this range check context sensitive for .8, .16, .32.
3011 if (Val < 0 || Val > 7) {
3012 Error(Parser.getTok().getLoc(), "lane index out of range");
3013 return MatchOperand_ParseFail;
3014 }
3015 Index = Val;
3016 LaneKind = IndexedLane;
3017 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003018 }
3019 LaneKind = NoLanes;
3020 return MatchOperand_Success;
3021}
3022
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003023// parse a vector register list
3024ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3025parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003026 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003027 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003028 SMLoc S = Parser.getTok().getLoc();
3029 // As an extension (to match gas), support a plain D register or Q register
3030 // (without encosing curly braces) as a single or double entry list,
3031 // respectively.
3032 if (Parser.getTok().is(AsmToken::Identifier)) {
3033 int Reg = tryParseRegister();
3034 if (Reg == -1)
3035 return MatchOperand_NoMatch;
3036 SMLoc E = Parser.getTok().getLoc();
3037 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003038 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003039 if (Res != MatchOperand_Success)
3040 return Res;
3041 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003042 case NoLanes:
3043 E = Parser.getTok().getLoc();
Jim Grosbach2f50e922011-12-15 21:44:33 +00003044 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003045 break;
3046 case AllLanes:
3047 E = Parser.getTok().getLoc();
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003048 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3049 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003050 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003051 case IndexedLane:
3052 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003053 LaneIndex,
3054 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003055 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003056 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003057 return MatchOperand_Success;
3058 }
3059 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3060 Reg = getDRegFromQReg(Reg);
Jim Grosbach04945c42011-12-02 00:35:16 +00003061 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003062 if (Res != MatchOperand_Success)
3063 return Res;
3064 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003065 case NoLanes:
3066 E = Parser.getTok().getLoc();
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003067 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003068 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003069 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003070 break;
3071 case AllLanes:
3072 E = Parser.getTok().getLoc();
Jim Grosbach13a292c2012-03-06 22:01:44 +00003073 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3074 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003075 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3076 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003077 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003078 case IndexedLane:
3079 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003080 LaneIndex,
3081 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003082 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003083 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003084 return MatchOperand_Success;
3085 }
3086 Error(S, "vector register expected");
3087 return MatchOperand_ParseFail;
3088 }
3089
3090 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003091 return MatchOperand_NoMatch;
3092
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003093 Parser.Lex(); // Eat '{' token.
3094 SMLoc RegLoc = Parser.getTok().getLoc();
3095
3096 int Reg = tryParseRegister();
3097 if (Reg == -1) {
3098 Error(RegLoc, "register expected");
3099 return MatchOperand_ParseFail;
3100 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003101 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003102 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003103 unsigned FirstReg = Reg;
3104 // The list is of D registers, but we also allow Q regs and just interpret
3105 // them as the two D sub-registers.
3106 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3107 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003108 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3109 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003110 ++Reg;
3111 ++Count;
3112 }
Jim Grosbach04945c42011-12-02 00:35:16 +00003113 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003114 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003115
Jim Grosbache891fe82011-11-15 23:19:15 +00003116 while (Parser.getTok().is(AsmToken::Comma) ||
3117 Parser.getTok().is(AsmToken::Minus)) {
3118 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003119 if (!Spacing)
3120 Spacing = 1; // Register range implies a single spaced list.
3121 else if (Spacing == 2) {
3122 Error(Parser.getTok().getLoc(),
3123 "sequential registers in double spaced list");
3124 return MatchOperand_ParseFail;
3125 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003126 Parser.Lex(); // Eat the minus.
3127 SMLoc EndLoc = Parser.getTok().getLoc();
3128 int EndReg = tryParseRegister();
3129 if (EndReg == -1) {
3130 Error(EndLoc, "register expected");
3131 return MatchOperand_ParseFail;
3132 }
3133 // Allow Q regs and just interpret them as the two D sub-registers.
3134 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3135 EndReg = getDRegFromQReg(EndReg) + 1;
3136 // If the register is the same as the start reg, there's nothing
3137 // more to do.
3138 if (Reg == EndReg)
3139 continue;
3140 // The register must be in the same register class as the first.
3141 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3142 Error(EndLoc, "invalid register in register list");
3143 return MatchOperand_ParseFail;
3144 }
3145 // Ranges must go from low to high.
3146 if (Reg > EndReg) {
3147 Error(EndLoc, "bad range in register list");
3148 return MatchOperand_ParseFail;
3149 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003150 // Parse the lane specifier if present.
3151 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003152 unsigned NextLaneIndex;
3153 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003154 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003155 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003156 Error(EndLoc, "mismatched lane index in register list");
3157 return MatchOperand_ParseFail;
3158 }
3159 EndLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003160
3161 // Add all the registers in the range to the register list.
3162 Count += EndReg - Reg;
3163 Reg = EndReg;
3164 continue;
3165 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003166 Parser.Lex(); // Eat the comma.
3167 RegLoc = Parser.getTok().getLoc();
3168 int OldReg = Reg;
3169 Reg = tryParseRegister();
3170 if (Reg == -1) {
3171 Error(RegLoc, "register expected");
3172 return MatchOperand_ParseFail;
3173 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003174 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003175 // It's OK to use the enumeration values directly here rather, as the
3176 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003177 //
3178 // The list is of D registers, but we also allow Q regs and just interpret
3179 // them as the two D sub-registers.
3180 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003181 if (!Spacing)
3182 Spacing = 1; // Register range implies a single spaced list.
3183 else if (Spacing == 2) {
3184 Error(RegLoc,
3185 "invalid register in double-spaced list (must be 'D' register')");
3186 return MatchOperand_ParseFail;
3187 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003188 Reg = getDRegFromQReg(Reg);
3189 if (Reg != OldReg + 1) {
3190 Error(RegLoc, "non-contiguous register range");
3191 return MatchOperand_ParseFail;
3192 }
3193 ++Reg;
3194 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003195 // Parse the lane specifier if present.
3196 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003197 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003198 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach04945c42011-12-02 00:35:16 +00003199 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003200 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003201 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003202 Error(EndLoc, "mismatched lane index in register list");
3203 return MatchOperand_ParseFail;
3204 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003205 continue;
3206 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003207 // Normal D register.
3208 // Figure out the register spacing (single or double) of the list if
3209 // we don't know it already.
3210 if (!Spacing)
3211 Spacing = 1 + (Reg == OldReg + 2);
3212
3213 // Just check that it's contiguous and keep going.
3214 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003215 Error(RegLoc, "non-contiguous register range");
3216 return MatchOperand_ParseFail;
3217 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003218 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003219 // Parse the lane specifier if present.
3220 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003221 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003222 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach04945c42011-12-02 00:35:16 +00003223 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003224 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003225 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003226 Error(EndLoc, "mismatched lane index in register list");
3227 return MatchOperand_ParseFail;
3228 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003229 }
3230
3231 SMLoc E = Parser.getTok().getLoc();
3232 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3233 Error(E, "'}' expected");
3234 return MatchOperand_ParseFail;
3235 }
3236 Parser.Lex(); // Eat '}' token.
3237
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003238 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003239 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003240 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003241 // composite register classes.
3242 if (Count == 2) {
3243 const MCRegisterClass *RC = (Spacing == 1) ?
3244 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3245 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3246 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3247 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003248
Jim Grosbach2f50e922011-12-15 21:44:33 +00003249 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3250 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003251 break;
3252 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003253 // Two-register operands have been converted to the
3254 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003255 if (Count == 2) {
3256 const MCRegisterClass *RC = (Spacing == 1) ?
3257 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3258 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003259 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3260 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003261 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003262 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003263 S, E));
3264 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003265 case IndexedLane:
3266 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003267 LaneIndex,
3268 (Spacing == 2),
3269 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003270 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003271 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003272 return MatchOperand_Success;
3273}
3274
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003275/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003276ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003277parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003278 SMLoc S = Parser.getTok().getLoc();
3279 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003280 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003281
Jiangning Liu288e1af2012-08-02 08:21:27 +00003282 if (Tok.is(AsmToken::Identifier)) {
3283 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003284
Jiangning Liu288e1af2012-08-02 08:21:27 +00003285 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3286 .Case("sy", ARM_MB::SY)
3287 .Case("st", ARM_MB::ST)
3288 .Case("sh", ARM_MB::ISH)
3289 .Case("ish", ARM_MB::ISH)
3290 .Case("shst", ARM_MB::ISHST)
3291 .Case("ishst", ARM_MB::ISHST)
3292 .Case("nsh", ARM_MB::NSH)
3293 .Case("un", ARM_MB::NSH)
3294 .Case("nshst", ARM_MB::NSHST)
3295 .Case("unst", ARM_MB::NSHST)
3296 .Case("osh", ARM_MB::OSH)
3297 .Case("oshst", ARM_MB::OSHST)
3298 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003299
Jiangning Liu288e1af2012-08-02 08:21:27 +00003300 if (Opt == ~0U)
3301 return MatchOperand_NoMatch;
3302
3303 Parser.Lex(); // Eat identifier token.
3304 } else if (Tok.is(AsmToken::Hash) ||
3305 Tok.is(AsmToken::Dollar) ||
3306 Tok.is(AsmToken::Integer)) {
3307 if (Parser.getTok().isNot(AsmToken::Integer))
3308 Parser.Lex(); // Eat the '#'.
3309 SMLoc Loc = Parser.getTok().getLoc();
3310
3311 const MCExpr *MemBarrierID;
3312 if (getParser().ParseExpression(MemBarrierID)) {
3313 Error(Loc, "illegal expression");
3314 return MatchOperand_ParseFail;
3315 }
3316
3317 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3318 if (!CE) {
3319 Error(Loc, "constant expression expected");
3320 return MatchOperand_ParseFail;
3321 }
3322
3323 int Val = CE->getValue();
3324 if (Val & ~0xf) {
3325 Error(Loc, "immediate value out of range");
3326 return MatchOperand_ParseFail;
3327 }
3328
3329 Opt = ARM_MB::RESERVED_0 + Val;
3330 } else
3331 return MatchOperand_ParseFail;
3332
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003333 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003334 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003335}
3336
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003337/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003338ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003339parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003340 SMLoc S = Parser.getTok().getLoc();
3341 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003342 if (!Tok.is(AsmToken::Identifier))
3343 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003344 StringRef IFlagsStr = Tok.getString();
3345
Owen Anderson10c5b122011-10-05 17:16:40 +00003346 // An iflags string of "none" is interpreted to mean that none of the AIF
3347 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003348 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003349 if (IFlagsStr != "none") {
3350 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3351 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3352 .Case("a", ARM_PROC::A)
3353 .Case("i", ARM_PROC::I)
3354 .Case("f", ARM_PROC::F)
3355 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003356
Owen Anderson10c5b122011-10-05 17:16:40 +00003357 // If some specific iflag is already set, it means that some letter is
3358 // present more than once, this is not acceptable.
3359 if (Flag == ~0U || (IFlags & Flag))
3360 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003361
Owen Anderson10c5b122011-10-05 17:16:40 +00003362 IFlags |= Flag;
3363 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003364 }
3365
3366 Parser.Lex(); // Eat identifier token.
3367 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3368 return MatchOperand_Success;
3369}
3370
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003371/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003372ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003373parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003374 SMLoc S = Parser.getTok().getLoc();
3375 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003376 if (!Tok.is(AsmToken::Identifier))
3377 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003378 StringRef Mask = Tok.getString();
3379
James Molloy21efa7d2011-09-28 14:21:38 +00003380 if (isMClass()) {
3381 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003382 std::string Name = Mask.lower();
3383 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003384 // Note: in the documentation:
3385 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3386 // for MSR APSR_nzcvq.
3387 // but we do make it an alias here. This is so to get the "mask encoding"
3388 // bits correct on MSR APSR writes.
3389 //
3390 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3391 // should really only be allowed when writing a special register. Note
3392 // they get dropped in the MRS instruction reading a special register as
3393 // the SYSm field is only 8 bits.
3394 //
3395 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3396 // includes the DSP extension but that is not checked.
3397 .Case("apsr", 0x800)
3398 .Case("apsr_nzcvq", 0x800)
3399 .Case("apsr_g", 0x400)
3400 .Case("apsr_nzcvqg", 0xc00)
3401 .Case("iapsr", 0x801)
3402 .Case("iapsr_nzcvq", 0x801)
3403 .Case("iapsr_g", 0x401)
3404 .Case("iapsr_nzcvqg", 0xc01)
3405 .Case("eapsr", 0x802)
3406 .Case("eapsr_nzcvq", 0x802)
3407 .Case("eapsr_g", 0x402)
3408 .Case("eapsr_nzcvqg", 0xc02)
3409 .Case("xpsr", 0x803)
3410 .Case("xpsr_nzcvq", 0x803)
3411 .Case("xpsr_g", 0x403)
3412 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003413 .Case("ipsr", 0x805)
3414 .Case("epsr", 0x806)
3415 .Case("iepsr", 0x807)
3416 .Case("msp", 0x808)
3417 .Case("psp", 0x809)
3418 .Case("primask", 0x810)
3419 .Case("basepri", 0x811)
3420 .Case("basepri_max", 0x812)
3421 .Case("faultmask", 0x813)
3422 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003423 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003424
James Molloy21efa7d2011-09-28 14:21:38 +00003425 if (FlagsVal == ~0U)
3426 return MatchOperand_NoMatch;
3427
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003428 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003429 // basepri, basepri_max and faultmask only valid for V7m.
3430 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003431
James Molloy21efa7d2011-09-28 14:21:38 +00003432 Parser.Lex(); // Eat identifier token.
3433 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3434 return MatchOperand_Success;
3435 }
3436
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003437 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3438 size_t Start = 0, Next = Mask.find('_');
3439 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003440 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003441 if (Next != StringRef::npos)
3442 Flags = Mask.slice(Next+1, Mask.size());
3443
3444 // FlagsVal contains the complete mask:
3445 // 3-0: Mask
3446 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3447 unsigned FlagsVal = 0;
3448
3449 if (SpecReg == "apsr") {
3450 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003451 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003452 .Case("g", 0x4) // same as CPSR_s
3453 .Case("nzcvqg", 0xc) // same as CPSR_fs
3454 .Default(~0U);
3455
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003456 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003457 if (!Flags.empty())
3458 return MatchOperand_NoMatch;
3459 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003460 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003461 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003462 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003463 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3464 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003465 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003466 for (int i = 0, e = Flags.size(); i != e; ++i) {
3467 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3468 .Case("c", 1)
3469 .Case("x", 2)
3470 .Case("s", 4)
3471 .Case("f", 8)
3472 .Default(~0U);
3473
3474 // If some specific flag is already set, it means that some letter is
3475 // present more than once, this is not acceptable.
3476 if (FlagsVal == ~0U || (FlagsVal & Flag))
3477 return MatchOperand_NoMatch;
3478 FlagsVal |= Flag;
3479 }
3480 } else // No match for special register.
3481 return MatchOperand_NoMatch;
3482
Owen Anderson03a173e2011-10-21 18:43:28 +00003483 // Special register without flags is NOT equivalent to "fc" flags.
3484 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3485 // two lines would enable gas compatibility at the expense of breaking
3486 // round-tripping.
3487 //
3488 // if (!FlagsVal)
3489 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003490
3491 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3492 if (SpecReg == "spsr")
3493 FlagsVal |= 16;
3494
3495 Parser.Lex(); // Eat identifier token.
3496 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3497 return MatchOperand_Success;
3498}
3499
Jim Grosbach27c1e252011-07-21 17:23:04 +00003500ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3501parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3502 int Low, int High) {
3503 const AsmToken &Tok = Parser.getTok();
3504 if (Tok.isNot(AsmToken::Identifier)) {
3505 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3506 return MatchOperand_ParseFail;
3507 }
3508 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003509 std::string LowerOp = Op.lower();
3510 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003511 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3512 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3513 return MatchOperand_ParseFail;
3514 }
3515 Parser.Lex(); // Eat shift type token.
3516
3517 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003518 if (Parser.getTok().isNot(AsmToken::Hash) &&
3519 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003520 Error(Parser.getTok().getLoc(), "'#' expected");
3521 return MatchOperand_ParseFail;
3522 }
3523 Parser.Lex(); // Eat hash token.
3524
3525 const MCExpr *ShiftAmount;
3526 SMLoc Loc = Parser.getTok().getLoc();
3527 if (getParser().ParseExpression(ShiftAmount)) {
3528 Error(Loc, "illegal expression");
3529 return MatchOperand_ParseFail;
3530 }
3531 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3532 if (!CE) {
3533 Error(Loc, "constant expression expected");
3534 return MatchOperand_ParseFail;
3535 }
3536 int Val = CE->getValue();
3537 if (Val < Low || Val > High) {
3538 Error(Loc, "immediate value out of range");
3539 return MatchOperand_ParseFail;
3540 }
3541
3542 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3543
3544 return MatchOperand_Success;
3545}
3546
Jim Grosbach0a547702011-07-22 17:44:50 +00003547ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3548parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3549 const AsmToken &Tok = Parser.getTok();
3550 SMLoc S = Tok.getLoc();
3551 if (Tok.isNot(AsmToken::Identifier)) {
3552 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3553 return MatchOperand_ParseFail;
3554 }
3555 int Val = StringSwitch<int>(Tok.getString())
3556 .Case("be", 1)
3557 .Case("le", 0)
3558 .Default(-1);
3559 Parser.Lex(); // Eat the token.
3560
3561 if (Val == -1) {
3562 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3563 return MatchOperand_ParseFail;
3564 }
3565 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3566 getContext()),
3567 S, Parser.getTok().getLoc()));
3568 return MatchOperand_Success;
3569}
3570
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003571/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3572/// instructions. Legal values are:
3573/// lsl #n 'n' in [0,31]
3574/// asr #n 'n' in [1,32]
3575/// n == 32 encoded as n == 0.
3576ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3577parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3578 const AsmToken &Tok = Parser.getTok();
3579 SMLoc S = Tok.getLoc();
3580 if (Tok.isNot(AsmToken::Identifier)) {
3581 Error(S, "shift operator 'asr' or 'lsl' expected");
3582 return MatchOperand_ParseFail;
3583 }
3584 StringRef ShiftName = Tok.getString();
3585 bool isASR;
3586 if (ShiftName == "lsl" || ShiftName == "LSL")
3587 isASR = false;
3588 else if (ShiftName == "asr" || ShiftName == "ASR")
3589 isASR = true;
3590 else {
3591 Error(S, "shift operator 'asr' or 'lsl' expected");
3592 return MatchOperand_ParseFail;
3593 }
3594 Parser.Lex(); // Eat the operator.
3595
3596 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003597 if (Parser.getTok().isNot(AsmToken::Hash) &&
3598 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003599 Error(Parser.getTok().getLoc(), "'#' expected");
3600 return MatchOperand_ParseFail;
3601 }
3602 Parser.Lex(); // Eat hash token.
3603
3604 const MCExpr *ShiftAmount;
3605 SMLoc E = Parser.getTok().getLoc();
3606 if (getParser().ParseExpression(ShiftAmount)) {
3607 Error(E, "malformed shift expression");
3608 return MatchOperand_ParseFail;
3609 }
3610 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3611 if (!CE) {
3612 Error(E, "shift amount must be an immediate");
3613 return MatchOperand_ParseFail;
3614 }
3615
3616 int64_t Val = CE->getValue();
3617 if (isASR) {
3618 // Shift amount must be in [1,32]
3619 if (Val < 1 || Val > 32) {
3620 Error(E, "'asr' shift amount must be in range [1,32]");
3621 return MatchOperand_ParseFail;
3622 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003623 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3624 if (isThumb() && Val == 32) {
3625 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3626 return MatchOperand_ParseFail;
3627 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003628 if (Val == 32) Val = 0;
3629 } else {
3630 // Shift amount must be in [1,32]
3631 if (Val < 0 || Val > 31) {
3632 Error(E, "'lsr' shift amount must be in range [0,31]");
3633 return MatchOperand_ParseFail;
3634 }
3635 }
3636
3637 E = Parser.getTok().getLoc();
3638 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3639
3640 return MatchOperand_Success;
3641}
3642
Jim Grosbach833b9d32011-07-27 20:15:40 +00003643/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3644/// of instructions. Legal values are:
3645/// ror #n 'n' in {0, 8, 16, 24}
3646ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3647parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3648 const AsmToken &Tok = Parser.getTok();
3649 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003650 if (Tok.isNot(AsmToken::Identifier))
3651 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003652 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003653 if (ShiftName != "ror" && ShiftName != "ROR")
3654 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003655 Parser.Lex(); // Eat the operator.
3656
3657 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003658 if (Parser.getTok().isNot(AsmToken::Hash) &&
3659 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003660 Error(Parser.getTok().getLoc(), "'#' expected");
3661 return MatchOperand_ParseFail;
3662 }
3663 Parser.Lex(); // Eat hash token.
3664
3665 const MCExpr *ShiftAmount;
3666 SMLoc E = Parser.getTok().getLoc();
3667 if (getParser().ParseExpression(ShiftAmount)) {
3668 Error(E, "malformed rotate expression");
3669 return MatchOperand_ParseFail;
3670 }
3671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3672 if (!CE) {
3673 Error(E, "rotate amount must be an immediate");
3674 return MatchOperand_ParseFail;
3675 }
3676
3677 int64_t Val = CE->getValue();
3678 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3679 // normally, zero is represented in asm by omitting the rotate operand
3680 // entirely.
3681 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3682 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3683 return MatchOperand_ParseFail;
3684 }
3685
3686 E = Parser.getTok().getLoc();
3687 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3688
3689 return MatchOperand_Success;
3690}
3691
Jim Grosbach864b6092011-07-28 21:34:26 +00003692ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3693parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3694 SMLoc S = Parser.getTok().getLoc();
3695 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003696 if (Parser.getTok().isNot(AsmToken::Hash) &&
3697 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003698 Error(Parser.getTok().getLoc(), "'#' expected");
3699 return MatchOperand_ParseFail;
3700 }
3701 Parser.Lex(); // Eat hash token.
3702
3703 const MCExpr *LSBExpr;
3704 SMLoc E = Parser.getTok().getLoc();
3705 if (getParser().ParseExpression(LSBExpr)) {
3706 Error(E, "malformed immediate expression");
3707 return MatchOperand_ParseFail;
3708 }
3709 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3710 if (!CE) {
3711 Error(E, "'lsb' operand must be an immediate");
3712 return MatchOperand_ParseFail;
3713 }
3714
3715 int64_t LSB = CE->getValue();
3716 // The LSB must be in the range [0,31]
3717 if (LSB < 0 || LSB > 31) {
3718 Error(E, "'lsb' operand must be in the range [0,31]");
3719 return MatchOperand_ParseFail;
3720 }
3721 E = Parser.getTok().getLoc();
3722
3723 // Expect another immediate operand.
3724 if (Parser.getTok().isNot(AsmToken::Comma)) {
3725 Error(Parser.getTok().getLoc(), "too few operands");
3726 return MatchOperand_ParseFail;
3727 }
3728 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003729 if (Parser.getTok().isNot(AsmToken::Hash) &&
3730 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003731 Error(Parser.getTok().getLoc(), "'#' expected");
3732 return MatchOperand_ParseFail;
3733 }
3734 Parser.Lex(); // Eat hash token.
3735
3736 const MCExpr *WidthExpr;
3737 if (getParser().ParseExpression(WidthExpr)) {
3738 Error(E, "malformed immediate expression");
3739 return MatchOperand_ParseFail;
3740 }
3741 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3742 if (!CE) {
3743 Error(E, "'width' operand must be an immediate");
3744 return MatchOperand_ParseFail;
3745 }
3746
3747 int64_t Width = CE->getValue();
3748 // The LSB must be in the range [1,32-lsb]
3749 if (Width < 1 || Width > 32 - LSB) {
3750 Error(E, "'width' operand must be in the range [1,32-lsb]");
3751 return MatchOperand_ParseFail;
3752 }
3753 E = Parser.getTok().getLoc();
3754
3755 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3756
3757 return MatchOperand_Success;
3758}
3759
Jim Grosbachd3595712011-08-03 23:50:40 +00003760ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3761parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3762 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003763 // postidx_reg := '+' register {, shift}
3764 // | '-' register {, shift}
3765 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003766
3767 // This method must return MatchOperand_NoMatch without consuming any tokens
3768 // in the case where there is no match, as other alternatives take other
3769 // parse methods.
3770 AsmToken Tok = Parser.getTok();
3771 SMLoc S = Tok.getLoc();
3772 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003773 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003774 int Reg = -1;
3775 if (Tok.is(AsmToken::Plus)) {
3776 Parser.Lex(); // Eat the '+' token.
3777 haveEaten = true;
3778 } else if (Tok.is(AsmToken::Minus)) {
3779 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003780 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003781 haveEaten = true;
3782 }
3783 if (Parser.getTok().is(AsmToken::Identifier))
3784 Reg = tryParseRegister();
3785 if (Reg == -1) {
3786 if (!haveEaten)
3787 return MatchOperand_NoMatch;
3788 Error(Parser.getTok().getLoc(), "register expected");
3789 return MatchOperand_ParseFail;
3790 }
3791 SMLoc E = Parser.getTok().getLoc();
3792
Jim Grosbachc320c852011-08-05 21:28:30 +00003793 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3794 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003795 if (Parser.getTok().is(AsmToken::Comma)) {
3796 Parser.Lex(); // Eat the ','.
3797 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3798 return MatchOperand_ParseFail;
3799 }
Jim Grosbachc320c852011-08-05 21:28:30 +00003800
3801 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3802 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00003803
3804 return MatchOperand_Success;
3805}
3806
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003807ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3808parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3809 // Check for a post-index addressing register operand. Specifically:
3810 // am3offset := '+' register
3811 // | '-' register
3812 // | register
3813 // | # imm
3814 // | # + imm
3815 // | # - imm
3816
3817 // This method must return MatchOperand_NoMatch without consuming any tokens
3818 // in the case where there is no match, as other alternatives take other
3819 // parse methods.
3820 AsmToken Tok = Parser.getTok();
3821 SMLoc S = Tok.getLoc();
3822
3823 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003824 if (Parser.getTok().is(AsmToken::Hash) ||
3825 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003826 Parser.Lex(); // Eat the '#'.
3827 // Explicitly look for a '-', as we need to encode negative zero
3828 // differently.
3829 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3830 const MCExpr *Offset;
3831 if (getParser().ParseExpression(Offset))
3832 return MatchOperand_ParseFail;
3833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3834 if (!CE) {
3835 Error(S, "constant expression expected");
3836 return MatchOperand_ParseFail;
3837 }
3838 SMLoc E = Tok.getLoc();
3839 // Negative zero is encoded as the flag value INT32_MIN.
3840 int32_t Val = CE->getValue();
3841 if (isNegative && Val == 0)
3842 Val = INT32_MIN;
3843
3844 Operands.push_back(
3845 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3846
3847 return MatchOperand_Success;
3848 }
3849
3850
3851 bool haveEaten = false;
3852 bool isAdd = true;
3853 int Reg = -1;
3854 if (Tok.is(AsmToken::Plus)) {
3855 Parser.Lex(); // Eat the '+' token.
3856 haveEaten = true;
3857 } else if (Tok.is(AsmToken::Minus)) {
3858 Parser.Lex(); // Eat the '-' token.
3859 isAdd = false;
3860 haveEaten = true;
3861 }
3862 if (Parser.getTok().is(AsmToken::Identifier))
3863 Reg = tryParseRegister();
3864 if (Reg == -1) {
3865 if (!haveEaten)
3866 return MatchOperand_NoMatch;
3867 Error(Parser.getTok().getLoc(), "register expected");
3868 return MatchOperand_ParseFail;
3869 }
3870 SMLoc E = Parser.getTok().getLoc();
3871
3872 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3873 0, S, E));
3874
3875 return MatchOperand_Success;
3876}
3877
Jim Grosbach7db8d692011-09-08 22:07:06 +00003878/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3879/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3880/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003881void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003882cvtT2LdrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003883 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3884 // Rt, Rt2
3885 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3886 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3887 // Create a writeback register dummy placeholder.
3888 Inst.addOperand(MCOperand::CreateReg(0));
3889 // addr
3890 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3891 // pred
3892 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003893}
3894
3895/// cvtT2StrdPre - Convert parsed operands to MCInst.
3896/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3897/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003898void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003899cvtT2StrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003900 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3901 // Create a writeback register dummy placeholder.
3902 Inst.addOperand(MCOperand::CreateReg(0));
3903 // Rt, Rt2
3904 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3905 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3906 // addr
3907 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3908 // pred
3909 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003910}
3911
Jim Grosbachc086f682011-09-08 00:39:19 +00003912/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3913/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3914/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003915void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003916cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +00003917 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3918 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3919
3920 // Create a writeback register dummy placeholder.
3921 Inst.addOperand(MCOperand::CreateImm(0));
3922
3923 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3924 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachc086f682011-09-08 00:39:19 +00003925}
3926
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003927/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3928/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3929/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003930void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003931cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003932 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3933 // Create a writeback register dummy placeholder.
3934 Inst.addOperand(MCOperand::CreateImm(0));
3935 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3936 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3937 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003938}
3939
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003940/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003941/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3942/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003943void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003944cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003945 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3946 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3947
3948 // Create a writeback register dummy placeholder.
3949 Inst.addOperand(MCOperand::CreateImm(0));
3950
Jim Grosbachd3595712011-08-03 23:50:40 +00003951 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003952 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003953}
3954
Owen Anderson16d33f32011-08-26 20:43:14 +00003955/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3956/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3957/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003958void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003959cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +00003960 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3961 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3962
3963 // Create a writeback register dummy placeholder.
3964 Inst.addOperand(MCOperand::CreateImm(0));
3965
3966 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3967 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson16d33f32011-08-26 20:43:14 +00003968}
3969
3970
Jim Grosbachd564bf32011-08-11 19:22:40 +00003971/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3972/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3973/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003974void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003975cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +00003976 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3977 // Create a writeback register dummy placeholder.
3978 Inst.addOperand(MCOperand::CreateImm(0));
3979 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3980 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3981 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd564bf32011-08-11 19:22:40 +00003982}
3983
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003984/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003985/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3986/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003987void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003988cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003989 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3990 // Create a writeback register dummy placeholder.
3991 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd564bf32011-08-11 19:22:40 +00003992 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3993 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3994 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00003995}
3996
Jim Grosbachd886f8c2011-08-11 21:17:22 +00003997/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3998/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3999/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004000void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004001cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004002 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4003 // Create a writeback register dummy placeholder.
4004 Inst.addOperand(MCOperand::CreateImm(0));
4005 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4006 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4007 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004008}
4009
Jim Grosbachd3595712011-08-03 23:50:40 +00004010/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4011/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4012/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004013void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004014cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004015 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4016 // Rt
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004017 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004018 // Create a writeback register dummy placeholder.
4019 Inst.addOperand(MCOperand::CreateImm(0));
4020 // addr
4021 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4022 // offset
4023 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4024 // pred
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004025 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004026}
4027
Jim Grosbachd3595712011-08-03 23:50:40 +00004028/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004029/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4030/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004031void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004032cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004033 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4034 // Rt
Owen Andersonb0e68992011-07-28 17:18:57 +00004035 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004036 // Create a writeback register dummy placeholder.
4037 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004038 // addr
4039 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4040 // offset
4041 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4042 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004043 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004044}
4045
Jim Grosbachd3595712011-08-03 23:50:40 +00004046/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004047/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4048/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004049void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004050cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004051 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004052 // Create a writeback register dummy placeholder.
4053 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004054 // Rt
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004055 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004056 // addr
4057 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4058 // offset
4059 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4060 // pred
4061 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004062}
4063
4064/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4065/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4066/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004067void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004068cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004069 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4070 // Create a writeback register dummy placeholder.
4071 Inst.addOperand(MCOperand::CreateImm(0));
4072 // Rt
4073 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4074 // addr
4075 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4076 // offset
4077 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4078 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004079 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004080}
4081
Jim Grosbach5b96b802011-08-10 20:29:19 +00004082/// cvtLdrdPre - Convert parsed operands to MCInst.
4083/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4084/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004085void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004086cvtLdrdPre(MCInst &Inst,
Jim Grosbach5b96b802011-08-10 20:29:19 +00004087 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4088 // Rt, Rt2
4089 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4090 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4091 // Create a writeback register dummy placeholder.
4092 Inst.addOperand(MCOperand::CreateImm(0));
4093 // addr
4094 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4095 // pred
4096 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach5b96b802011-08-10 20:29:19 +00004097}
4098
Jim Grosbacheb09f492011-08-11 20:28:23 +00004099/// cvtStrdPre - Convert parsed operands to MCInst.
4100/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4101/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004102void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004103cvtStrdPre(MCInst &Inst,
Jim Grosbacheb09f492011-08-11 20:28:23 +00004104 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4105 // Create a writeback register dummy placeholder.
4106 Inst.addOperand(MCOperand::CreateImm(0));
4107 // Rt, Rt2
4108 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4109 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4110 // addr
4111 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4112 // pred
4113 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheb09f492011-08-11 20:28:23 +00004114}
4115
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004116/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4117/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4118/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004119void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004120cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004121 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4122 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4123 // Create a writeback register dummy placeholder.
4124 Inst.addOperand(MCOperand::CreateImm(0));
4125 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4126 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004127}
4128
Chad Rosier5eec49f2012-08-30 23:00:00 +00004129/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach8e048492011-08-19 22:07:46 +00004130/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4131/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004132void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004133cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004134 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004135 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4136 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004137 // If we have a three-operand form, make sure to set Rn to be the operand
4138 // that isn't the same as Rd.
4139 unsigned RegOp = 4;
4140 if (Operands.size() == 6 &&
4141 ((ARMOperand*)Operands[4])->getReg() ==
4142 ((ARMOperand*)Operands[3])->getReg())
4143 RegOp = 5;
4144 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4145 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004146 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004147}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004148
Chad Rosier98cfa102012-08-31 00:03:31 +00004149void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004150cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004151 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4152 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004153 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004154 // Create a writeback register dummy placeholder.
4155 Inst.addOperand(MCOperand::CreateImm(0));
4156 // Vn
4157 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4158 // pred
4159 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004160}
4161
Chad Rosier98cfa102012-08-31 00:03:31 +00004162void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004163cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004164 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4165 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004166 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004167 // Create a writeback register dummy placeholder.
4168 Inst.addOperand(MCOperand::CreateImm(0));
4169 // Vn
4170 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4171 // Vm
4172 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4173 // pred
4174 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004175}
4176
Chad Rosier98cfa102012-08-31 00:03:31 +00004177void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004178cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004179 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4180 // Create a writeback register dummy placeholder.
4181 Inst.addOperand(MCOperand::CreateImm(0));
4182 // Vn
4183 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4184 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004185 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004186 // pred
4187 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004188}
4189
Chad Rosier98cfa102012-08-31 00:03:31 +00004190void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004191cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004192 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4193 // Create a writeback register dummy placeholder.
4194 Inst.addOperand(MCOperand::CreateImm(0));
4195 // Vn
4196 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4197 // Vm
4198 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4199 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004200 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004201 // pred
4202 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004203}
4204
Bill Wendlinge18980a2010-11-06 22:36:58 +00004205/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004206/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004207bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004208parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004209 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004210 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004211 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004212 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004213 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004214
Sean Callanan936b0d32010-01-19 21:44:56 +00004215 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004216 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004217 if (BaseRegNum == -1)
4218 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004219
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004220 // The next token must either be a comma or a closing bracket.
4221 const AsmToken &Tok = Parser.getTok();
4222 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004223 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004224
Jim Grosbachd3595712011-08-03 23:50:40 +00004225 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004226 E = Tok.getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004227 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004228
Jim Grosbachd3595712011-08-03 23:50:40 +00004229 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004230 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004231
Jim Grosbach40700e02011-09-19 18:42:21 +00004232 // If there's a pre-indexing writeback marker, '!', just add it as a token
4233 // operand. It's rather odd, but syntactically valid.
4234 if (Parser.getTok().is(AsmToken::Exclaim)) {
4235 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4236 Parser.Lex(); // Eat the '!'.
4237 }
4238
Jim Grosbachd3595712011-08-03 23:50:40 +00004239 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004240 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004241
Jim Grosbachd3595712011-08-03 23:50:40 +00004242 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4243 Parser.Lex(); // Eat the comma.
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004244
Jim Grosbacha95ec992011-10-11 17:29:55 +00004245 // If we have a ':', it's an alignment specifier.
4246 if (Parser.getTok().is(AsmToken::Colon)) {
4247 Parser.Lex(); // Eat the ':'.
4248 E = Parser.getTok().getLoc();
4249
4250 const MCExpr *Expr;
4251 if (getParser().ParseExpression(Expr))
4252 return true;
4253
4254 // The expression has to be a constant. Memory references with relocations
4255 // don't come through here, as they use the <label> forms of the relevant
4256 // instructions.
4257 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4258 if (!CE)
4259 return Error (E, "constant expression expected");
4260
4261 unsigned Align = 0;
4262 switch (CE->getValue()) {
4263 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004264 return Error(E,
4265 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4266 case 16: Align = 2; break;
4267 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004268 case 64: Align = 8; break;
4269 case 128: Align = 16; break;
4270 case 256: Align = 32; break;
4271 }
4272
4273 // Now we should have the closing ']'
4274 E = Parser.getTok().getLoc();
4275 if (Parser.getTok().isNot(AsmToken::RBrac))
4276 return Error(E, "']' expected");
4277 Parser.Lex(); // Eat right bracket token.
4278
4279 // Don't worry about range checking the value here. That's handled by
4280 // the is*() predicates.
4281 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4282 ARM_AM::no_shift, 0, Align,
4283 false, S, E));
4284
4285 // If there's a pre-indexing writeback marker, '!', just add it as a token
4286 // operand.
4287 if (Parser.getTok().is(AsmToken::Exclaim)) {
4288 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4289 Parser.Lex(); // Eat the '!'.
4290 }
4291
4292 return false;
4293 }
4294
4295 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004296 // offset. Be friendly and also accept a plain integer (without a leading
4297 // hash) for gas compatibility.
4298 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004299 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004300 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004301 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach8279c182011-11-15 22:14:41 +00004302 Parser.Lex(); // Eat the '#'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004303 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004304
Owen Anderson967674d2011-08-29 19:36:44 +00004305 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004306 const MCExpr *Offset;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004307 if (getParser().ParseExpression(Offset))
4308 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004309
4310 // The expression has to be a constant. Memory references with relocations
4311 // don't come through here, as they use the <label> forms of the relevant
4312 // instructions.
4313 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4314 if (!CE)
4315 return Error (E, "constant expression expected");
4316
Owen Anderson967674d2011-08-29 19:36:44 +00004317 // If the constant was #-0, represent it as INT32_MIN.
4318 int32_t Val = CE->getValue();
4319 if (isNegative && Val == 0)
4320 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4321
Jim Grosbachd3595712011-08-03 23:50:40 +00004322 // Now we should have the closing ']'
4323 E = Parser.getTok().getLoc();
4324 if (Parser.getTok().isNot(AsmToken::RBrac))
4325 return Error(E, "']' expected");
4326 Parser.Lex(); // Eat right bracket token.
4327
4328 // Don't worry about range checking the value here. That's handled by
4329 // the is*() predicates.
4330 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004331 ARM_AM::no_shift, 0, 0,
4332 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004333
4334 // If there's a pre-indexing writeback marker, '!', just add it as a token
4335 // operand.
4336 if (Parser.getTok().is(AsmToken::Exclaim)) {
4337 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4338 Parser.Lex(); // Eat the '!'.
4339 }
4340
4341 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004342 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004343
4344 // The register offset is optionally preceded by a '+' or '-'
4345 bool isNegative = false;
4346 if (Parser.getTok().is(AsmToken::Minus)) {
4347 isNegative = true;
4348 Parser.Lex(); // Eat the '-'.
4349 } else if (Parser.getTok().is(AsmToken::Plus)) {
4350 // Nothing to do.
4351 Parser.Lex(); // Eat the '+'.
4352 }
4353
4354 E = Parser.getTok().getLoc();
4355 int OffsetRegNum = tryParseRegister();
4356 if (OffsetRegNum == -1)
4357 return Error(E, "register expected");
4358
4359 // If there's a shift operator, handle it.
4360 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004361 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004362 if (Parser.getTok().is(AsmToken::Comma)) {
4363 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004364 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004365 return true;
4366 }
4367
4368 // Now we should have the closing ']'
4369 E = Parser.getTok().getLoc();
4370 if (Parser.getTok().isNot(AsmToken::RBrac))
4371 return Error(E, "']' expected");
4372 Parser.Lex(); // Eat right bracket token.
4373
4374 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004375 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004376 S, E));
4377
Jim Grosbachc320c852011-08-05 21:28:30 +00004378 // If there's a pre-indexing writeback marker, '!', just add it as a token
4379 // operand.
4380 if (Parser.getTok().is(AsmToken::Exclaim)) {
4381 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4382 Parser.Lex(); // Eat the '!'.
4383 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004384
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004385 return false;
4386}
4387
Jim Grosbachd3595712011-08-03 23:50:40 +00004388/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004389/// ( lsl | lsr | asr | ror ) , # shift_amount
4390/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004391/// return true if it parses a shift otherwise it returns false.
4392bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4393 unsigned &Amount) {
4394 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004395 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004396 if (Tok.isNot(AsmToken::Identifier))
4397 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004398 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004399 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4400 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004401 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004402 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004403 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004404 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004405 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004406 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004407 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004408 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004409 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004410 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004411 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004412 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004413
Jim Grosbachd3595712011-08-03 23:50:40 +00004414 // rrx stands alone.
4415 Amount = 0;
4416 if (St != ARM_AM::rrx) {
4417 Loc = Parser.getTok().getLoc();
4418 // A '#' and a shift amount.
4419 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004420 if (HashTok.isNot(AsmToken::Hash) &&
4421 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004422 return Error(HashTok.getLoc(), "'#' expected");
4423 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004424
Jim Grosbachd3595712011-08-03 23:50:40 +00004425 const MCExpr *Expr;
4426 if (getParser().ParseExpression(Expr))
4427 return true;
4428 // Range check the immediate.
4429 // lsl, ror: 0 <= imm <= 31
4430 // lsr, asr: 0 <= imm <= 32
4431 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4432 if (!CE)
4433 return Error(Loc, "shift amount must be an immediate");
4434 int64_t Imm = CE->getValue();
4435 if (Imm < 0 ||
4436 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4437 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4438 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004439 // If <ShiftTy> #0, turn it into a no_shift.
4440 if (Imm == 0)
4441 St = ARM_AM::lsl;
4442 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4443 if (Imm == 32)
4444 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004445 Amount = Imm;
4446 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004447
4448 return false;
4449}
4450
Jim Grosbache7fbce72011-10-03 23:38:36 +00004451/// parseFPImm - A floating point immediate expression operand.
4452ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4453parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004454 // Anything that can accept a floating point constant as an operand
4455 // needs to go through here, as the regular ParseExpression is
4456 // integer only.
4457 //
4458 // This routine still creates a generic Immediate operand, containing
4459 // a bitcast of the 64-bit floating point value. The various operands
4460 // that accept floats can check whether the value is valid for them
4461 // via the standard is*() predicates.
4462
Jim Grosbache7fbce72011-10-03 23:38:36 +00004463 SMLoc S = Parser.getTok().getLoc();
4464
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004465 if (Parser.getTok().isNot(AsmToken::Hash) &&
4466 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004467 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004468
4469 // Disambiguate the VMOV forms that can accept an FP immediate.
4470 // vmov.f32 <sreg>, #imm
4471 // vmov.f64 <dreg>, #imm
4472 // vmov.f32 <dreg>, #imm @ vector f32x2
4473 // vmov.f32 <qreg>, #imm @ vector f32x4
4474 //
4475 // There are also the NEON VMOV instructions which expect an
4476 // integer constant. Make sure we don't try to parse an FPImm
4477 // for these:
4478 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4479 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4480 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4481 TyOp->getToken() != ".f64"))
4482 return MatchOperand_NoMatch;
4483
Jim Grosbache7fbce72011-10-03 23:38:36 +00004484 Parser.Lex(); // Eat the '#'.
4485
4486 // Handle negation, as that still comes through as a separate token.
4487 bool isNegative = false;
4488 if (Parser.getTok().is(AsmToken::Minus)) {
4489 isNegative = true;
4490 Parser.Lex();
4491 }
4492 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004493 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004494 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004495 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004496 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4497 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004498 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004499 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004500 Operands.push_back(ARMOperand::CreateImm(
4501 MCConstantExpr::Create(IntVal, getContext()),
4502 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004503 return MatchOperand_Success;
4504 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004505 // Also handle plain integers. Instructions which allow floating point
4506 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004507 if (Tok.is(AsmToken::Integer)) {
4508 int64_t Val = Tok.getIntVal();
4509 Parser.Lex(); // Eat the token.
4510 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004511 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004512 return MatchOperand_ParseFail;
4513 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004514 double RealVal = ARM_AM::getFPImmFloat(Val);
4515 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4516 Operands.push_back(ARMOperand::CreateImm(
4517 MCConstantExpr::Create(Val, getContext()), S,
4518 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004519 return MatchOperand_Success;
4520 }
4521
Jim Grosbach235c8d22012-01-19 02:47:30 +00004522 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004523 return MatchOperand_ParseFail;
4524}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004525
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004526/// Parse a arm instruction operand. For now this parses the operand regardless
4527/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004528bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004529 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004530 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004531
4532 // Check if the current operand has a custom associated parser, if so, try to
4533 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004534 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4535 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004536 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004537 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4538 // there was a match, but an error occurred, in which case, just return that
4539 // the operand parsing failed.
4540 if (ResTy == MatchOperand_ParseFail)
4541 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004542
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004543 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004544 default:
4545 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004546 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004547 case AsmToken::Identifier: {
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004548 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling2063b842010-11-18 23:43:05 +00004549 return false;
Jim Grosbach0d6022d2011-07-26 20:41:24 +00004550 int Res = tryParseShiftRegister(Operands);
Jim Grosbachbb24c592011-07-13 18:49:30 +00004551 if (Res == 0) // success
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004552 return false;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004553 else if (Res == -1) // irrecoverable error
4554 return true;
Jim Grosbach4eda1452011-12-20 22:26:38 +00004555 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachd28888d2012-03-15 21:34:14 +00004556 if (Mnemonic == "vmrs" &&
4557 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004558 S = Parser.getTok().getLoc();
4559 Parser.Lex();
Jim Grosbachd28888d2012-03-15 21:34:14 +00004560 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004561 return false;
4562 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004563
4564 // Fall though for the Identifier case that is not a register or a
4565 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004566 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004567 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004568 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004569 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004570 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004571 // This was not a register so parse other operands that start with an
4572 // identifier (like labels) as expressions and create them as immediates.
4573 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004574 S = Parser.getTok().getLoc();
Kevin Enderby146dcf22009-10-15 20:48:48 +00004575 if (getParser().ParseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004576 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004577 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004578 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4579 return false;
4580 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004581 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004582 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004583 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004584 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004585 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004586 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004587 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004588 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004589 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004590
4591 if (Parser.getTok().isNot(AsmToken::Colon)) {
4592 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4593 const MCExpr *ImmVal;
4594 if (getParser().ParseExpression(ImmVal))
4595 return true;
4596 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4597 if (CE) {
4598 int32_t Val = CE->getValue();
4599 if (isNegative && Val == 0)
4600 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4601 }
4602 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4603 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4604 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004605 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004606 // w/ a ':' after the '#', it's just like a plain ':'.
4607 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004608 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004609 case AsmToken::Colon: {
4610 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004611 // FIXME: Check it's an expression prefix,
4612 // e.g. (FOO - :lower16:BAR) isn't legal.
4613 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004614 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004615 return true;
4616
Evan Cheng965b3c72011-01-13 07:58:56 +00004617 const MCExpr *SubExprVal;
4618 if (getParser().ParseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004619 return true;
4620
Evan Cheng965b3c72011-01-13 07:58:56 +00004621 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004622 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004623 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004624 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004625 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004626 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004627 }
4628}
4629
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004630// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004631// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004632bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004633 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004634
4635 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004636 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004637 Parser.Lex(); // Eat ':'
4638
4639 if (getLexer().isNot(AsmToken::Identifier)) {
4640 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4641 return true;
4642 }
4643
4644 StringRef IDVal = Parser.getTok().getIdentifier();
4645 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004646 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004647 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004648 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004649 } else {
4650 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4651 return true;
4652 }
4653 Parser.Lex();
4654
4655 if (getLexer().isNot(AsmToken::Colon)) {
4656 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4657 return true;
4658 }
4659 Parser.Lex(); // Eat the last ':'
4660 return false;
4661}
4662
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004663/// \brief Given a mnemonic, split out possible predication code and carry
4664/// setting letters to form a canonical mnemonic and flags.
4665//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004666// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004667// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004668StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004669 unsigned &PredicationCode,
4670 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004671 unsigned &ProcessorIMod,
4672 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004673 PredicationCode = ARMCC::AL;
4674 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004675 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004676
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004677 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004678 //
4679 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004680 if ((Mnemonic == "movs" && isThumb()) ||
4681 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4682 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4683 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4684 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4685 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4686 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004687 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4688 Mnemonic == "fmuls")
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004689 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004690
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004691 // First, split out any predication code. Ignore mnemonics we know aren't
4692 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004693 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004694 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004695 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004696 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004697 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4698 .Case("eq", ARMCC::EQ)
4699 .Case("ne", ARMCC::NE)
4700 .Case("hs", ARMCC::HS)
4701 .Case("cs", ARMCC::HS)
4702 .Case("lo", ARMCC::LO)
4703 .Case("cc", ARMCC::LO)
4704 .Case("mi", ARMCC::MI)
4705 .Case("pl", ARMCC::PL)
4706 .Case("vs", ARMCC::VS)
4707 .Case("vc", ARMCC::VC)
4708 .Case("hi", ARMCC::HI)
4709 .Case("ls", ARMCC::LS)
4710 .Case("ge", ARMCC::GE)
4711 .Case("lt", ARMCC::LT)
4712 .Case("gt", ARMCC::GT)
4713 .Case("le", ARMCC::LE)
4714 .Case("al", ARMCC::AL)
4715 .Default(~0U);
4716 if (CC != ~0U) {
4717 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4718 PredicationCode = CC;
4719 }
Bill Wendling193961b2010-10-29 23:50:21 +00004720 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004721
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004722 // Next, determine if we have a carry setting bit. We explicitly ignore all
4723 // the instructions we know end in 's'.
4724 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004725 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004726 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4727 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4728 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004729 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004730 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004731 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004732 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004733 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004734 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004735 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4736 CarrySetting = true;
4737 }
4738
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004739 // The "cps" instruction can have a interrupt mode operand which is glued into
4740 // the mnemonic. Check if this is the case, split it and parse the imod op
4741 if (Mnemonic.startswith("cps")) {
4742 // Split out any imod code.
4743 unsigned IMod =
4744 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4745 .Case("ie", ARM_PROC::IE)
4746 .Case("id", ARM_PROC::ID)
4747 .Default(~0U);
4748 if (IMod != ~0U) {
4749 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4750 ProcessorIMod = IMod;
4751 }
4752 }
4753
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004754 // The "it" instruction has the condition mask on the end of the mnemonic.
4755 if (Mnemonic.startswith("it")) {
4756 ITMask = Mnemonic.slice(2, Mnemonic.size());
4757 Mnemonic = Mnemonic.slice(0, 2);
4758 }
4759
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004760 return Mnemonic;
4761}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004762
4763/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4764/// inclusion of carry set or predication code operands.
4765//
4766// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004767void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004768getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004769 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004770 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4771 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004772 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004773 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004774 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004775 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004776 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004777 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004778 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004779 Mnemonic == "mla" || Mnemonic == "smlal" ||
4780 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004781 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004782 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004783 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004784
Daniel Dunbar09264122011-01-11 19:06:29 +00004785 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4786 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4787 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4788 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbach803898f2011-09-06 20:27:04 +00004789 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4790 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach25977222011-08-19 23:24:36 +00004791 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach93981412011-10-11 21:55:36 +00004792 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4793 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4794 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbachb9d4e372011-08-26 22:21:51 +00004795 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4796 !isThumb()) ||
Jim Grosbachb908b7a2011-09-10 00:15:36 +00004797 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004798 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004799 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004800 CanAcceptPredicationCode = true;
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004801
Jim Grosbach6c45b752011-09-16 16:39:25 +00004802 if (isThumb()) {
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004803 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbachb98ab912011-06-30 22:10:46 +00004804 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004805 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004806 }
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004807}
4808
Jim Grosbach7283da92011-08-16 21:12:37 +00004809bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4810 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004811 // FIXME: This is all horribly hacky. We really need a better way to deal
4812 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004813
4814 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4815 // another does not. Specifically, the MOVW instruction does not. So we
4816 // special case it here and remove the defaulted (non-setting) cc_out
4817 // operand if that's the instruction we're trying to match.
4818 //
4819 // We do this as post-processing of the explicit operands rather than just
4820 // conditionally adding the cc_out in the first place because we need
4821 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004822 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004823 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4824 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4825 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4826 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004827
4828 // Register-register 'add' for thumb does not have a cc_out operand
4829 // when there are only two register operands.
4830 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4831 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4832 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4833 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4834 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004835 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004836 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4837 // have to check the immediate range here since Thumb2 has a variant
4838 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004839 if (((isThumb() && Mnemonic == "add") ||
4840 (isThumbTwo() && Mnemonic == "sub")) &&
4841 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004842 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4843 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4844 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004845 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004846 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004847 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004848 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004849 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4850 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004851 // selecting via the generic "add" mnemonic, so to know that we
4852 // should remove the cc_out operand, we have to explicitly check that
4853 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004854 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4855 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004856 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4857 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4858 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4859 // Nest conditions rather than one big 'if' statement for readability.
4860 //
4861 // If either register is a high reg, it's either one of the SP
4862 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004863 // check against T3. If the second register is the PC, this is an
4864 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004865 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4866 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004867 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004868 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4869 return false;
4870 // If both registers are low, we're in an IT block, and the immediate is
4871 // in range, we should use encoding T1 instead, which has a cc_out.
4872 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004873 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004874 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4875 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4876 return false;
4877
4878 // Otherwise, we use encoding T4, which does not have a cc_out
4879 // operand.
4880 return true;
4881 }
4882
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004883 // The thumb2 multiply instruction doesn't have a CCOut register, so
4884 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4885 // use the 16-bit encoding or not.
4886 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4887 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4888 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4889 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4890 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4891 // If the registers aren't low regs, the destination reg isn't the
4892 // same as one of the source regs, or the cc_out operand is zero
4893 // outside of an IT block, we have to use the 32-bit encoding, so
4894 // remove the cc_out operand.
4895 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4896 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004897 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004898 !inITBlock() ||
4899 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4900 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4901 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4902 static_cast<ARMOperand*>(Operands[4])->getReg())))
4903 return true;
4904
Jim Grosbachefa7e952011-11-15 19:55:16 +00004905 // Also check the 'mul' syntax variant that doesn't specify an explicit
4906 // destination register.
4907 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4908 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4909 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4910 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4911 // If the registers aren't low regs or the cc_out operand is zero
4912 // outside of an IT block, we have to use the 32-bit encoding, so
4913 // remove the cc_out operand.
4914 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4915 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4916 !inITBlock()))
4917 return true;
4918
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004919
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004920
Jim Grosbach4b701af2011-08-24 21:42:27 +00004921 // Register-register 'add/sub' for thumb does not have a cc_out operand
4922 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4923 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4924 // right, this will result in better diagnostics (which operand is off)
4925 // anyway.
4926 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4927 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004928 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4929 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004930 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4931 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4932 (Operands.size() == 6 &&
4933 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004934 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004935
Jim Grosbach7283da92011-08-16 21:12:37 +00004936 return false;
4937}
4938
Jim Grosbach12952fe2011-11-11 23:08:10 +00004939static bool isDataTypeToken(StringRef Tok) {
4940 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4941 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4942 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4943 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4944 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4945 Tok == ".f" || Tok == ".d";
4946}
4947
4948// FIXME: This bit should probably be handled via an explicit match class
4949// in the .td files that matches the suffix instead of having it be
4950// a literal string token the way it is now.
4951static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4952 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4953}
4954
Jim Grosbach8be2f652011-12-09 23:34:09 +00004955static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004956/// Parse an arm instruction mnemonic followed by its operands.
4957bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4958 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004959 // Apply mnemonic aliases before doing anything else, as the destination
4960 // mnemnonic may include suffices and we want to handle them normally.
4961 // The generic tblgen'erated code does this later, at the start of
4962 // MatchInstructionImpl(), but that's too late for aliases that include
4963 // any sort of suffix.
4964 unsigned AvailableFeatures = getAvailableFeatures();
4965 applyMnemonicAliases(Name, AvailableFeatures);
4966
Jim Grosbachab5830e2011-12-14 02:16:11 +00004967 // First check for the ARM-specific .req directive.
4968 if (Parser.getTok().is(AsmToken::Identifier) &&
4969 Parser.getTok().getIdentifier() == ".req") {
4970 parseDirectiveReq(Name, NameLoc);
4971 // We always return 'error' for this, as we're done with this
4972 // statement and don't need to match the 'instruction."
4973 return true;
4974 }
4975
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004976 // Create the leading tokens for the mnemonic, split by '.' characters.
4977 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004978 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004979
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004980 // Split out the predication code and carry setting flag from the mnemonic.
4981 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004982 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004983 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004984 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004985 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004986 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004987
Jim Grosbach1c171b12011-08-25 17:23:55 +00004988 // In Thumb1, only the branch (B) instruction can be predicated.
4989 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4990 Parser.EatToEndOfStatement();
4991 return Error(NameLoc, "conditional execution not supported in Thumb1");
4992 }
4993
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004994 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4995
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004996 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4997 // is the mask as it will be for the IT encoding if the conditional
4998 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4999 // where the conditional bit0 is zero, the instruction post-processing
5000 // will adjust the mask accordingly.
5001 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005002 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5003 if (ITMask.size() > 3) {
5004 Parser.EatToEndOfStatement();
5005 return Error(Loc, "too many conditions on IT instruction");
5006 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005007 unsigned Mask = 8;
5008 for (unsigned i = ITMask.size(); i != 0; --i) {
5009 char pos = ITMask[i - 1];
5010 if (pos != 't' && pos != 'e') {
5011 Parser.EatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005012 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005013 }
5014 Mask >>= 1;
5015 if (ITMask[i - 1] == 't')
5016 Mask |= 8;
5017 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005018 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005019 }
5020
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005021 // FIXME: This is all a pretty gross hack. We should automatically handle
5022 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005023
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005024 // Next, add the CCOut and ConditionCode operands, if needed.
5025 //
5026 // For mnemonics which can ever incorporate a carry setting bit or predication
5027 // code, our matching model involves us always generating CCOut and
5028 // ConditionCode operands to match the mnemonic "as written" and then we let
5029 // the matcher deal with finding the right instruction or generating an
5030 // appropriate error.
5031 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005032 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005033
Jim Grosbach03a8a162011-07-14 22:04:21 +00005034 // If we had a carry-set on an instruction that can't do that, issue an
5035 // error.
5036 if (!CanAcceptCarrySet && CarrySetting) {
5037 Parser.EatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005038 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005039 "' can not set flags, but 's' suffix specified");
5040 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005041 // If we had a predication code on an instruction that can't do that, issue an
5042 // error.
5043 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5044 Parser.EatToEndOfStatement();
5045 return Error(NameLoc, "instruction '" + Mnemonic +
5046 "' is not predicable, but condition code specified");
5047 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005048
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005049 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005050 if (CanAcceptCarrySet) {
5051 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005052 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005053 Loc));
5054 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005055
5056 // Add the predication code operand, if necessary.
5057 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005058 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5059 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005060 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005061 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005062 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005063
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005064 // Add the processor imod operand, if necessary.
5065 if (ProcessorIMod) {
5066 Operands.push_back(ARMOperand::CreateImm(
5067 MCConstantExpr::Create(ProcessorIMod, getContext()),
5068 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005069 }
5070
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005071 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005072 while (Next != StringRef::npos) {
5073 Start = Next;
5074 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005075 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005076
Jim Grosbach12952fe2011-11-11 23:08:10 +00005077 // Some NEON instructions have an optional datatype suffix that is
5078 // completely ignored. Check for that.
5079 if (isDataTypeToken(ExtraToken) &&
5080 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5081 continue;
5082
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005083 if (ExtraToken != ".n") {
5084 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5085 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5086 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005087 }
5088
5089 // Read the remaining operands.
5090 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005091 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005092 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnera2a9d162010-09-11 16:18:25 +00005093 Parser.EatToEndOfStatement();
5094 return true;
5095 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005096
5097 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005098 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005099
5100 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005101 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnera2a9d162010-09-11 16:18:25 +00005102 Parser.EatToEndOfStatement();
5103 return true;
5104 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005105 }
5106 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005107
Chris Lattnera2a9d162010-09-11 16:18:25 +00005108 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005109 SMLoc Loc = getLexer().getLoc();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005110 Parser.EatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005111 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005112 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005113
Chris Lattner91689c12010-09-08 05:10:46 +00005114 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005115
Jim Grosbach7283da92011-08-16 21:12:37 +00005116 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5117 // do and don't have a cc_out optional-def operand. With some spot-checks
5118 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005119 // parse and adjust accordingly before actually matching. We shouldn't ever
5120 // try to remove a cc_out operand that was explicitly set on the the
5121 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5122 // table driven matcher doesn't fit well with the ARM instruction set.
5123 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005124 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5125 Operands.erase(Operands.begin() + 1);
5126 delete Op;
5127 }
5128
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005129 // ARM mode 'blx' need special handling, as the register operand version
5130 // is predicable, but the label operand version is not. So, we can't rely
5131 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005132 // a k_CondCode operand in the list. If we're trying to match the label
5133 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005134 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5135 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5136 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5137 Operands.erase(Operands.begin() + 1);
5138 delete Op;
5139 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005140
5141 // The vector-compare-to-zero instructions have a literal token "#0" at
5142 // the end that comes to here as an immediate operand. Convert it to a
5143 // token to play nicely with the matcher.
5144 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5145 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5146 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5147 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5148 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5149 if (CE && CE->getValue() == 0) {
5150 Operands.erase(Operands.begin() + 5);
5151 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5152 delete Op;
5153 }
5154 }
Jim Grosbach46b66462011-10-03 22:30:24 +00005155 // VCMP{E} does the same thing, but with a different operand count.
5156 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5157 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5158 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5159 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5160 if (CE && CE->getValue() == 0) {
5161 Operands.erase(Operands.begin() + 4);
5162 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5163 delete Op;
5164 }
5165 }
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005166 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005167 // end. Convert it to a token here. Take care not to convert those
5168 // that should hit the Thumb2 encoding.
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005169 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005170 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5171 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005172 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5173 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5174 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005175 if (CE && CE->getValue() == 0 &&
5176 (isThumbOne() ||
Jim Grosbach5ac89672011-12-13 21:06:41 +00005177 // The cc_out operand matches the IT block.
5178 ((inITBlock() != CarrySetting) &&
5179 // Neither register operand is a high register.
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005180 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach5ac89672011-12-13 21:06:41 +00005181 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005182 Operands.erase(Operands.begin() + 5);
5183 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5184 delete Op;
5185 }
5186 }
5187
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005188 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005189}
5190
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005191// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005192
5193// return 'true' if register list contains non-low GPR registers,
5194// 'false' otherwise. If Reg is in the register list or is HiReg, set
5195// 'containsReg' to true.
5196static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5197 unsigned HiReg, bool &containsReg) {
5198 containsReg = false;
5199 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5200 unsigned OpReg = Inst.getOperand(i).getReg();
5201 if (OpReg == Reg)
5202 containsReg = true;
5203 // Anything other than a low register isn't legal here.
5204 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5205 return true;
5206 }
5207 return false;
5208}
5209
Jim Grosbacha31f2232011-09-07 18:05:34 +00005210// Check if the specified regisgter is in the register list of the inst,
5211// starting at the indicated operand number.
5212static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5213 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5214 unsigned OpReg = Inst.getOperand(i).getReg();
5215 if (OpReg == Reg)
5216 return true;
5217 }
5218 return false;
5219}
5220
Jim Grosbached16ec42011-08-29 22:24:09 +00005221// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5222// the ARMInsts array) instead. Getting that here requires awkward
5223// API changes, though. Better way?
5224namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005225extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005226}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005227static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005228 return ARMInsts[Opcode];
5229}
5230
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005231// FIXME: We would really like to be able to tablegen'erate this.
5232bool ARMAsmParser::
5233validateInstruction(MCInst &Inst,
5234 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005235 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005236 SMLoc Loc = Operands[0]->getStartLoc();
5237 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005238 // NOTE: BKPT instruction has the interesting property of being
5239 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005240 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005241 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5242 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005243 unsigned bit = 1;
5244 if (ITState.FirstCond)
5245 ITState.FirstCond = false;
5246 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005247 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005248 // The instruction must be predicable.
5249 if (!MCID.isPredicable())
5250 return Error(Loc, "instructions in IT block must be predicable");
5251 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5252 unsigned ITCond = bit ? ITState.Cond :
5253 ARMCC::getOppositeCondition(ITState.Cond);
5254 if (Cond != ITCond) {
5255 // Find the condition code Operand to get its SMLoc information.
5256 SMLoc CondLoc;
5257 for (unsigned i = 1; i < Operands.size(); ++i)
5258 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5259 CondLoc = Operands[i]->getStartLoc();
5260 return Error(CondLoc, "incorrect condition in IT block; got '" +
5261 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5262 "', but expected '" +
5263 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5264 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005265 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005266 } else if (isThumbTwo() && MCID.isPredicable() &&
5267 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005268 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5269 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005270 return Error(Loc, "predicated instructions must be in IT block");
5271
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005272 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005273 case ARM::LDRD:
5274 case ARM::LDRD_PRE:
5275 case ARM::LDRD_POST:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005276 case ARM::LDREXD: {
5277 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005278 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5279 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005280 if (Rt2 != Rt + 1)
5281 return Error(Operands[3]->getStartLoc(),
5282 "destination operands must be sequential");
5283 return false;
5284 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005285 case ARM::STRD: {
5286 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005287 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5288 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005289 if (Rt2 != Rt + 1)
5290 return Error(Operands[3]->getStartLoc(),
5291 "source operands must be sequential");
5292 return false;
5293 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005294 case ARM::STRD_PRE:
5295 case ARM::STRD_POST:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005296 case ARM::STREXD: {
5297 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005298 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5299 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005300 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005301 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005302 "source operands must be sequential");
5303 return false;
5304 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005305 case ARM::SBFX:
5306 case ARM::UBFX: {
5307 // width must be in range [1, 32-lsb]
5308 unsigned lsb = Inst.getOperand(2).getImm();
5309 unsigned widthm1 = Inst.getOperand(3).getImm();
5310 if (widthm1 >= 32 - lsb)
5311 return Error(Operands[5]->getStartLoc(),
5312 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005313 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005314 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005315 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005316 // If we're parsing Thumb2, the .w variant is available and handles
5317 // most cases that are normally illegal for a Thumb1 LDM
5318 // instruction. We'll make the transformation in processInstruction()
5319 // if necessary.
5320 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005321 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005322 // in the register list.
5323 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005324 bool hasWritebackToken =
5325 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5326 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005327 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005328 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005329 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5330 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005331 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005332 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005333 return Error(Operands[2]->getStartLoc(),
5334 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005335 // If we should not have writeback, there must not be a '!'. This is
5336 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005337 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005338 return Error(Operands[3]->getStartLoc(),
5339 "writeback operator '!' not allowed when base register "
5340 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005341
5342 break;
5343 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005344 case ARM::t2LDMIA_UPD: {
5345 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5346 return Error(Operands[4]->getStartLoc(),
5347 "writeback operator '!' not allowed when base register "
5348 "in register list");
5349 break;
5350 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005351 case ARM::tMUL: {
5352 // The second source operand must be the same register as the destination
5353 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005354 //
5355 // In this case, we must directly check the parsed operands because the
5356 // cvtThumbMultiply() function is written in such a way that it guarantees
5357 // this first statement is always true for the new Inst. Essentially, the
5358 // destination is unconditionally copied into the second source operand
5359 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005360 if (Operands.size() == 6 &&
5361 (((ARMOperand*)Operands[3])->getReg() !=
5362 ((ARMOperand*)Operands[5])->getReg()) &&
5363 (((ARMOperand*)Operands[3])->getReg() !=
5364 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005365 return Error(Operands[3]->getStartLoc(),
5366 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005367 }
5368 break;
5369 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005370 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5371 // so only issue a diagnostic for thumb1. The instructions will be
5372 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005373 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005374 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005375 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5376 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005377 return Error(Operands[2]->getStartLoc(),
5378 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005379 break;
5380 }
5381 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005382 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005383 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5384 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005385 return Error(Operands[2]->getStartLoc(),
5386 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005387 break;
5388 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005389 case ARM::tSTMIA_UPD: {
5390 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005391 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005392 return Error(Operands[4]->getStartLoc(),
5393 "registers must be in range r0-r7");
5394 break;
5395 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005396 case ARM::tADDrSP: {
5397 // If the non-SP source operand and the destination operand are not the
5398 // same, we need thumb2 (for the wide encoding), or we have an error.
5399 if (!isThumbTwo() &&
5400 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5401 return Error(Operands[4]->getStartLoc(),
5402 "source register must be the same as destination");
5403 }
5404 break;
5405 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005406 }
5407
5408 return false;
5409}
5410
Jim Grosbach1a747242012-01-23 23:45:44 +00005411static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005412 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005413 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005414 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005415 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5416 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5417 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5418 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5419 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5420 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5421 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5422 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5423 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005424
5425 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005426 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5427 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5428 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5429 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5430 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005431
Jim Grosbach1e946a42012-01-24 00:43:12 +00005432 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5433 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5434 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5435 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5436 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005437
Jim Grosbach1e946a42012-01-24 00:43:12 +00005438 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5439 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5440 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5441 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5442 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005443
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005444 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005445 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5446 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5447 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5448 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5449 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5450 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5451 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5452 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5453 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5454 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5455 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5456 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5457 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5458 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5459 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005460
Jim Grosbach1a747242012-01-23 23:45:44 +00005461 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005462 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5463 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5464 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5465 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5466 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5467 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5468 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5469 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5470 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5471 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5472 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5473 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5474 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5475 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5476 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5477 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5478 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5479 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005480
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005481 // VST4LN
5482 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5483 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5484 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5485 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5486 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5487 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5488 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5489 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5490 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5491 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5492 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5493 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5494 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5495 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5496 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5497
Jim Grosbachda70eac2012-01-24 00:58:13 +00005498 // VST4
5499 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5500 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5501 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5502 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5503 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5504 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5505 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5506 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5507 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5508 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5509 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5510 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5511 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5512 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5513 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5514 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5515 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5516 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005517 }
5518}
5519
Jim Grosbach1a747242012-01-23 23:45:44 +00005520static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005521 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005522 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005523 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005524 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5525 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5526 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5527 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5528 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5529 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5530 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5531 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5532 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005533
5534 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005535 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5536 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5537 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5538 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5539 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5540 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5541 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5542 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5543 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5544 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5545 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5546 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5547 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5548 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5549 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005550
Jim Grosbachb78403c2012-01-24 23:47:04 +00005551 // VLD3DUP
5552 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5553 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5554 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5555 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5556 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5557 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5558 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5559 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5560 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5561 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5562 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5563 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5564 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5565 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5566 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5567 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5568 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5569 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5570
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005571 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005572 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5573 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5574 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5575 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5576 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5577 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5578 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5579 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5580 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5581 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5582 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5583 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5584 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5585 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5586 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005587
5588 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005589 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5590 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5591 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5592 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5593 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5594 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5595 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5596 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5597 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5598 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5599 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5600 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5601 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5602 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5603 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5604 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5605 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5606 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005607
Jim Grosbach14952a02012-01-24 18:37:25 +00005608 // VLD4LN
5609 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5610 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5611 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5612 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5613 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5614 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5615 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5616 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5617 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5618 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5619 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5620 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5621 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5622 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5623 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5624
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005625 // VLD4DUP
5626 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5627 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5628 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5629 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5630 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5631 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5632 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5633 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5634 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5635 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5636 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5637 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5638 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5639 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5640 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5641 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5642 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5643 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5644
Jim Grosbached561fc2012-01-24 00:43:17 +00005645 // VLD4
5646 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5647 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5648 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5649 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5650 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5651 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5652 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5653 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5654 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5655 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5656 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5657 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5658 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5659 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5660 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5661 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5662 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5663 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005664 }
5665}
5666
Jim Grosbachafad0532011-11-10 23:42:14 +00005667bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005668processInstruction(MCInst &Inst,
5669 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5670 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005671 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5672 case ARM::ADDri: {
5673 if (Inst.getOperand(1).getReg() != ARM::PC ||
5674 Inst.getOperand(5).getReg() != 0)
5675 return false;
5676 MCInst TmpInst;
5677 TmpInst.setOpcode(ARM::ADR);
5678 TmpInst.addOperand(Inst.getOperand(0));
5679 TmpInst.addOperand(Inst.getOperand(2));
5680 TmpInst.addOperand(Inst.getOperand(3));
5681 TmpInst.addOperand(Inst.getOperand(4));
5682 Inst = TmpInst;
5683 return true;
5684 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005685 // Aliases for alternate PC+imm syntax of LDR instructions.
5686 case ARM::t2LDRpcrel:
5687 Inst.setOpcode(ARM::t2LDRpci);
5688 return true;
5689 case ARM::t2LDRBpcrel:
5690 Inst.setOpcode(ARM::t2LDRBpci);
5691 return true;
5692 case ARM::t2LDRHpcrel:
5693 Inst.setOpcode(ARM::t2LDRHpci);
5694 return true;
5695 case ARM::t2LDRSBpcrel:
5696 Inst.setOpcode(ARM::t2LDRSBpci);
5697 return true;
5698 case ARM::t2LDRSHpcrel:
5699 Inst.setOpcode(ARM::t2LDRSHpci);
5700 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005701 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005702 case ARM::VST1LNdWB_register_Asm_8:
5703 case ARM::VST1LNdWB_register_Asm_16:
5704 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005705 MCInst TmpInst;
5706 // Shuffle the operands around so the lane index operand is in the
5707 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005708 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005709 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005710 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5711 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5712 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5713 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5714 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5715 TmpInst.addOperand(Inst.getOperand(1)); // lane
5716 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5717 TmpInst.addOperand(Inst.getOperand(6));
5718 Inst = TmpInst;
5719 return true;
5720 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005721
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005722 case ARM::VST2LNdWB_register_Asm_8:
5723 case ARM::VST2LNdWB_register_Asm_16:
5724 case ARM::VST2LNdWB_register_Asm_32:
5725 case ARM::VST2LNqWB_register_Asm_16:
5726 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005727 MCInst TmpInst;
5728 // Shuffle the operands around so the lane index operand is in the
5729 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005730 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005731 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005732 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5733 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5734 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5735 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5736 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005737 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5738 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005739 TmpInst.addOperand(Inst.getOperand(1)); // lane
5740 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5741 TmpInst.addOperand(Inst.getOperand(6));
5742 Inst = TmpInst;
5743 return true;
5744 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005745
5746 case ARM::VST3LNdWB_register_Asm_8:
5747 case ARM::VST3LNdWB_register_Asm_16:
5748 case ARM::VST3LNdWB_register_Asm_32:
5749 case ARM::VST3LNqWB_register_Asm_16:
5750 case ARM::VST3LNqWB_register_Asm_32: {
5751 MCInst TmpInst;
5752 // Shuffle the operands around so the lane index operand is in the
5753 // right place.
5754 unsigned Spacing;
5755 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5756 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5757 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5758 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5759 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5760 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5761 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5762 Spacing));
5763 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5764 Spacing * 2));
5765 TmpInst.addOperand(Inst.getOperand(1)); // lane
5766 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5767 TmpInst.addOperand(Inst.getOperand(6));
5768 Inst = TmpInst;
5769 return true;
5770 }
5771
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005772 case ARM::VST4LNdWB_register_Asm_8:
5773 case ARM::VST4LNdWB_register_Asm_16:
5774 case ARM::VST4LNdWB_register_Asm_32:
5775 case ARM::VST4LNqWB_register_Asm_16:
5776 case ARM::VST4LNqWB_register_Asm_32: {
5777 MCInst TmpInst;
5778 // Shuffle the operands around so the lane index operand is in the
5779 // right place.
5780 unsigned Spacing;
5781 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5782 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5783 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5784 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5785 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5786 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5787 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5788 Spacing));
5789 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5790 Spacing * 2));
5791 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5792 Spacing * 3));
5793 TmpInst.addOperand(Inst.getOperand(1)); // lane
5794 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5795 TmpInst.addOperand(Inst.getOperand(6));
5796 Inst = TmpInst;
5797 return true;
5798 }
5799
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005800 case ARM::VST1LNdWB_fixed_Asm_8:
5801 case ARM::VST1LNdWB_fixed_Asm_16:
5802 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005803 MCInst TmpInst;
5804 // Shuffle the operands around so the lane index operand is in the
5805 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005806 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005807 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005808 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5809 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5810 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5811 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5812 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5813 TmpInst.addOperand(Inst.getOperand(1)); // lane
5814 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5815 TmpInst.addOperand(Inst.getOperand(5));
5816 Inst = TmpInst;
5817 return true;
5818 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005819
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005820 case ARM::VST2LNdWB_fixed_Asm_8:
5821 case ARM::VST2LNdWB_fixed_Asm_16:
5822 case ARM::VST2LNdWB_fixed_Asm_32:
5823 case ARM::VST2LNqWB_fixed_Asm_16:
5824 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005825 MCInst TmpInst;
5826 // Shuffle the operands around so the lane index operand is in the
5827 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005828 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005829 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005830 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5831 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5832 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5833 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5834 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005835 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5836 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005837 TmpInst.addOperand(Inst.getOperand(1)); // lane
5838 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5839 TmpInst.addOperand(Inst.getOperand(5));
5840 Inst = TmpInst;
5841 return true;
5842 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005843
5844 case ARM::VST3LNdWB_fixed_Asm_8:
5845 case ARM::VST3LNdWB_fixed_Asm_16:
5846 case ARM::VST3LNdWB_fixed_Asm_32:
5847 case ARM::VST3LNqWB_fixed_Asm_16:
5848 case ARM::VST3LNqWB_fixed_Asm_32: {
5849 MCInst TmpInst;
5850 // Shuffle the operands around so the lane index operand is in the
5851 // right place.
5852 unsigned Spacing;
5853 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5854 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5855 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5856 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5857 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5858 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5859 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5860 Spacing));
5861 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5862 Spacing * 2));
5863 TmpInst.addOperand(Inst.getOperand(1)); // lane
5864 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5865 TmpInst.addOperand(Inst.getOperand(5));
5866 Inst = TmpInst;
5867 return true;
5868 }
5869
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005870 case ARM::VST4LNdWB_fixed_Asm_8:
5871 case ARM::VST4LNdWB_fixed_Asm_16:
5872 case ARM::VST4LNdWB_fixed_Asm_32:
5873 case ARM::VST4LNqWB_fixed_Asm_16:
5874 case ARM::VST4LNqWB_fixed_Asm_32: {
5875 MCInst TmpInst;
5876 // Shuffle the operands around so the lane index operand is in the
5877 // right place.
5878 unsigned Spacing;
5879 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5880 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5881 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5882 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5883 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5884 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5885 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5886 Spacing));
5887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5888 Spacing * 2));
5889 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5890 Spacing * 3));
5891 TmpInst.addOperand(Inst.getOperand(1)); // lane
5892 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5893 TmpInst.addOperand(Inst.getOperand(5));
5894 Inst = TmpInst;
5895 return true;
5896 }
5897
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005898 case ARM::VST1LNdAsm_8:
5899 case ARM::VST1LNdAsm_16:
5900 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005901 MCInst TmpInst;
5902 // Shuffle the operands around so the lane index operand is in the
5903 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005904 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005905 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005906 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5907 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5908 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5909 TmpInst.addOperand(Inst.getOperand(1)); // lane
5910 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5911 TmpInst.addOperand(Inst.getOperand(5));
5912 Inst = TmpInst;
5913 return true;
5914 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005915
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005916 case ARM::VST2LNdAsm_8:
5917 case ARM::VST2LNdAsm_16:
5918 case ARM::VST2LNdAsm_32:
5919 case ARM::VST2LNqAsm_16:
5920 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005921 MCInst TmpInst;
5922 // Shuffle the operands around so the lane index operand is in the
5923 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005924 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005925 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005926 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5927 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5928 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005929 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5930 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005931 TmpInst.addOperand(Inst.getOperand(1)); // lane
5932 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5933 TmpInst.addOperand(Inst.getOperand(5));
5934 Inst = TmpInst;
5935 return true;
5936 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005937
5938 case ARM::VST3LNdAsm_8:
5939 case ARM::VST3LNdAsm_16:
5940 case ARM::VST3LNdAsm_32:
5941 case ARM::VST3LNqAsm_16:
5942 case ARM::VST3LNqAsm_32: {
5943 MCInst TmpInst;
5944 // Shuffle the operands around so the lane index operand is in the
5945 // right place.
5946 unsigned Spacing;
5947 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5948 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5949 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5950 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5951 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5952 Spacing));
5953 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5954 Spacing * 2));
5955 TmpInst.addOperand(Inst.getOperand(1)); // lane
5956 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5957 TmpInst.addOperand(Inst.getOperand(5));
5958 Inst = TmpInst;
5959 return true;
5960 }
5961
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005962 case ARM::VST4LNdAsm_8:
5963 case ARM::VST4LNdAsm_16:
5964 case ARM::VST4LNdAsm_32:
5965 case ARM::VST4LNqAsm_16:
5966 case ARM::VST4LNqAsm_32: {
5967 MCInst TmpInst;
5968 // Shuffle the operands around so the lane index operand is in the
5969 // right place.
5970 unsigned Spacing;
5971 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5972 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5973 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5974 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5975 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5976 Spacing));
5977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5978 Spacing * 2));
5979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5980 Spacing * 3));
5981 TmpInst.addOperand(Inst.getOperand(1)); // lane
5982 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5983 TmpInst.addOperand(Inst.getOperand(5));
5984 Inst = TmpInst;
5985 return true;
5986 }
5987
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005988 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005989 case ARM::VLD1LNdWB_register_Asm_8:
5990 case ARM::VLD1LNdWB_register_Asm_16:
5991 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00005992 MCInst TmpInst;
5993 // Shuffle the operands around so the lane index operand is in the
5994 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005995 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005996 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00005997 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5998 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5999 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6000 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6001 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6002 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6003 TmpInst.addOperand(Inst.getOperand(1)); // lane
6004 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6005 TmpInst.addOperand(Inst.getOperand(6));
6006 Inst = TmpInst;
6007 return true;
6008 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006009
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006010 case ARM::VLD2LNdWB_register_Asm_8:
6011 case ARM::VLD2LNdWB_register_Asm_16:
6012 case ARM::VLD2LNdWB_register_Asm_32:
6013 case ARM::VLD2LNqWB_register_Asm_16:
6014 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006015 MCInst TmpInst;
6016 // Shuffle the operands around so the lane index operand is in the
6017 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006018 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006019 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006020 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006021 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6022 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006023 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6024 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6025 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6026 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6027 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006028 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6029 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006030 TmpInst.addOperand(Inst.getOperand(1)); // lane
6031 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6032 TmpInst.addOperand(Inst.getOperand(6));
6033 Inst = TmpInst;
6034 return true;
6035 }
6036
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006037 case ARM::VLD3LNdWB_register_Asm_8:
6038 case ARM::VLD3LNdWB_register_Asm_16:
6039 case ARM::VLD3LNdWB_register_Asm_32:
6040 case ARM::VLD3LNqWB_register_Asm_16:
6041 case ARM::VLD3LNqWB_register_Asm_32: {
6042 MCInst TmpInst;
6043 // Shuffle the operands around so the lane index operand is in the
6044 // right place.
6045 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006046 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006047 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6048 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6049 Spacing));
6050 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006051 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006052 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6053 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6054 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6055 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6056 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6057 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6058 Spacing));
6059 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006060 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006061 TmpInst.addOperand(Inst.getOperand(1)); // lane
6062 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6063 TmpInst.addOperand(Inst.getOperand(6));
6064 Inst = TmpInst;
6065 return true;
6066 }
6067
Jim Grosbach14952a02012-01-24 18:37:25 +00006068 case ARM::VLD4LNdWB_register_Asm_8:
6069 case ARM::VLD4LNdWB_register_Asm_16:
6070 case ARM::VLD4LNdWB_register_Asm_32:
6071 case ARM::VLD4LNqWB_register_Asm_16:
6072 case ARM::VLD4LNqWB_register_Asm_32: {
6073 MCInst TmpInst;
6074 // Shuffle the operands around so the lane index operand is in the
6075 // right place.
6076 unsigned Spacing;
6077 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6078 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6079 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6080 Spacing));
6081 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6082 Spacing * 2));
6083 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6084 Spacing * 3));
6085 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6086 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6087 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6088 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6089 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6090 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6091 Spacing));
6092 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6093 Spacing * 2));
6094 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6095 Spacing * 3));
6096 TmpInst.addOperand(Inst.getOperand(1)); // lane
6097 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6098 TmpInst.addOperand(Inst.getOperand(6));
6099 Inst = TmpInst;
6100 return true;
6101 }
6102
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006103 case ARM::VLD1LNdWB_fixed_Asm_8:
6104 case ARM::VLD1LNdWB_fixed_Asm_16:
6105 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006106 MCInst TmpInst;
6107 // Shuffle the operands around so the lane index operand is in the
6108 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006109 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006110 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006111 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6112 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6113 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6114 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6115 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6116 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6117 TmpInst.addOperand(Inst.getOperand(1)); // lane
6118 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6119 TmpInst.addOperand(Inst.getOperand(5));
6120 Inst = TmpInst;
6121 return true;
6122 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006123
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006124 case ARM::VLD2LNdWB_fixed_Asm_8:
6125 case ARM::VLD2LNdWB_fixed_Asm_16:
6126 case ARM::VLD2LNdWB_fixed_Asm_32:
6127 case ARM::VLD2LNqWB_fixed_Asm_16:
6128 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006129 MCInst TmpInst;
6130 // Shuffle the operands around so the lane index operand is in the
6131 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006132 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006133 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006134 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006135 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6136 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006137 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6138 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6139 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6140 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6141 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6143 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006144 TmpInst.addOperand(Inst.getOperand(1)); // lane
6145 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6146 TmpInst.addOperand(Inst.getOperand(5));
6147 Inst = TmpInst;
6148 return true;
6149 }
6150
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006151 case ARM::VLD3LNdWB_fixed_Asm_8:
6152 case ARM::VLD3LNdWB_fixed_Asm_16:
6153 case ARM::VLD3LNdWB_fixed_Asm_32:
6154 case ARM::VLD3LNqWB_fixed_Asm_16:
6155 case ARM::VLD3LNqWB_fixed_Asm_32: {
6156 MCInst TmpInst;
6157 // Shuffle the operands around so the lane index operand is in the
6158 // right place.
6159 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006160 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006161 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6162 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6163 Spacing));
6164 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006165 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006166 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6167 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6168 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6169 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6170 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6171 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6172 Spacing));
6173 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006174 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006175 TmpInst.addOperand(Inst.getOperand(1)); // lane
6176 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6177 TmpInst.addOperand(Inst.getOperand(5));
6178 Inst = TmpInst;
6179 return true;
6180 }
6181
Jim Grosbach14952a02012-01-24 18:37:25 +00006182 case ARM::VLD4LNdWB_fixed_Asm_8:
6183 case ARM::VLD4LNdWB_fixed_Asm_16:
6184 case ARM::VLD4LNdWB_fixed_Asm_32:
6185 case ARM::VLD4LNqWB_fixed_Asm_16:
6186 case ARM::VLD4LNqWB_fixed_Asm_32: {
6187 MCInst TmpInst;
6188 // Shuffle the operands around so the lane index operand is in the
6189 // right place.
6190 unsigned Spacing;
6191 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6192 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6193 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6194 Spacing));
6195 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6196 Spacing * 2));
6197 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6198 Spacing * 3));
6199 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6200 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6201 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6202 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6203 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6204 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6205 Spacing));
6206 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6207 Spacing * 2));
6208 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6209 Spacing * 3));
6210 TmpInst.addOperand(Inst.getOperand(1)); // lane
6211 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6212 TmpInst.addOperand(Inst.getOperand(5));
6213 Inst = TmpInst;
6214 return true;
6215 }
6216
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006217 case ARM::VLD1LNdAsm_8:
6218 case ARM::VLD1LNdAsm_16:
6219 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006220 MCInst TmpInst;
6221 // Shuffle the operands around so the lane index operand is in the
6222 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006223 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006224 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006225 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6226 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6227 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6228 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6229 TmpInst.addOperand(Inst.getOperand(1)); // lane
6230 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6231 TmpInst.addOperand(Inst.getOperand(5));
6232 Inst = TmpInst;
6233 return true;
6234 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006235
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006236 case ARM::VLD2LNdAsm_8:
6237 case ARM::VLD2LNdAsm_16:
6238 case ARM::VLD2LNdAsm_32:
6239 case ARM::VLD2LNqAsm_16:
6240 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006241 MCInst TmpInst;
6242 // Shuffle the operands around so the lane index operand is in the
6243 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006244 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006245 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006246 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6248 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006249 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6250 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6251 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006252 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006254 TmpInst.addOperand(Inst.getOperand(1)); // lane
6255 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6256 TmpInst.addOperand(Inst.getOperand(5));
6257 Inst = TmpInst;
6258 return true;
6259 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006260
6261 case ARM::VLD3LNdAsm_8:
6262 case ARM::VLD3LNdAsm_16:
6263 case ARM::VLD3LNdAsm_32:
6264 case ARM::VLD3LNqAsm_16:
6265 case ARM::VLD3LNqAsm_32: {
6266 MCInst TmpInst;
6267 // Shuffle the operands around so the lane index operand is in the
6268 // right place.
6269 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006270 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006271 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6272 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6273 Spacing));
6274 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006275 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006276 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6277 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6278 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6279 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6280 Spacing));
6281 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006282 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006283 TmpInst.addOperand(Inst.getOperand(1)); // lane
6284 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6285 TmpInst.addOperand(Inst.getOperand(5));
6286 Inst = TmpInst;
6287 return true;
6288 }
6289
Jim Grosbach14952a02012-01-24 18:37:25 +00006290 case ARM::VLD4LNdAsm_8:
6291 case ARM::VLD4LNdAsm_16:
6292 case ARM::VLD4LNdAsm_32:
6293 case ARM::VLD4LNqAsm_16:
6294 case ARM::VLD4LNqAsm_32: {
6295 MCInst TmpInst;
6296 // Shuffle the operands around so the lane index operand is in the
6297 // right place.
6298 unsigned Spacing;
6299 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6300 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6301 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 Spacing));
6303 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6304 Spacing * 2));
6305 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6306 Spacing * 3));
6307 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6308 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6309 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6310 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6311 Spacing));
6312 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6313 Spacing * 2));
6314 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6315 Spacing * 3));
6316 TmpInst.addOperand(Inst.getOperand(1)); // lane
6317 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6318 TmpInst.addOperand(Inst.getOperand(5));
6319 Inst = TmpInst;
6320 return true;
6321 }
6322
Jim Grosbachb78403c2012-01-24 23:47:04 +00006323 // VLD3DUP single 3-element structure to all lanes instructions.
6324 case ARM::VLD3DUPdAsm_8:
6325 case ARM::VLD3DUPdAsm_16:
6326 case ARM::VLD3DUPdAsm_32:
6327 case ARM::VLD3DUPqAsm_8:
6328 case ARM::VLD3DUPqAsm_16:
6329 case ARM::VLD3DUPqAsm_32: {
6330 MCInst TmpInst;
6331 unsigned Spacing;
6332 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
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)); // Rn
6339 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6340 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6341 TmpInst.addOperand(Inst.getOperand(4));
6342 Inst = TmpInst;
6343 return true;
6344 }
6345
6346 case ARM::VLD3DUPdWB_fixed_Asm_8:
6347 case ARM::VLD3DUPdWB_fixed_Asm_16:
6348 case ARM::VLD3DUPdWB_fixed_Asm_32:
6349 case ARM::VLD3DUPqWB_fixed_Asm_8:
6350 case ARM::VLD3DUPqWB_fixed_Asm_16:
6351 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6352 MCInst TmpInst;
6353 unsigned Spacing;
6354 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6355 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6356 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6357 Spacing));
6358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6359 Spacing * 2));
6360 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6361 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6362 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6363 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6364 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6365 TmpInst.addOperand(Inst.getOperand(4));
6366 Inst = TmpInst;
6367 return true;
6368 }
6369
6370 case ARM::VLD3DUPdWB_register_Asm_8:
6371 case ARM::VLD3DUPdWB_register_Asm_16:
6372 case ARM::VLD3DUPdWB_register_Asm_32:
6373 case ARM::VLD3DUPqWB_register_Asm_8:
6374 case ARM::VLD3DUPqWB_register_Asm_16:
6375 case ARM::VLD3DUPqWB_register_Asm_32: {
6376 MCInst TmpInst;
6377 unsigned Spacing;
6378 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6379 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6380 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6381 Spacing));
6382 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6383 Spacing * 2));
6384 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6385 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6386 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6387 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6388 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6389 TmpInst.addOperand(Inst.getOperand(5));
6390 Inst = TmpInst;
6391 return true;
6392 }
6393
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006394 // VLD3 multiple 3-element structure instructions.
6395 case ARM::VLD3dAsm_8:
6396 case ARM::VLD3dAsm_16:
6397 case ARM::VLD3dAsm_32:
6398 case ARM::VLD3qAsm_8:
6399 case ARM::VLD3qAsm_16:
6400 case ARM::VLD3qAsm_32: {
6401 MCInst TmpInst;
6402 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006403 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006404 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6405 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6406 Spacing));
6407 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6408 Spacing * 2));
6409 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6410 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6411 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6412 TmpInst.addOperand(Inst.getOperand(4));
6413 Inst = TmpInst;
6414 return true;
6415 }
6416
6417 case ARM::VLD3dWB_fixed_Asm_8:
6418 case ARM::VLD3dWB_fixed_Asm_16:
6419 case ARM::VLD3dWB_fixed_Asm_32:
6420 case ARM::VLD3qWB_fixed_Asm_8:
6421 case ARM::VLD3qWB_fixed_Asm_16:
6422 case ARM::VLD3qWB_fixed_Asm_32: {
6423 MCInst TmpInst;
6424 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006425 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006426 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6427 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6428 Spacing));
6429 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6430 Spacing * 2));
6431 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6432 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6433 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6434 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6435 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6436 TmpInst.addOperand(Inst.getOperand(4));
6437 Inst = TmpInst;
6438 return true;
6439 }
6440
6441 case ARM::VLD3dWB_register_Asm_8:
6442 case ARM::VLD3dWB_register_Asm_16:
6443 case ARM::VLD3dWB_register_Asm_32:
6444 case ARM::VLD3qWB_register_Asm_8:
6445 case ARM::VLD3qWB_register_Asm_16:
6446 case ARM::VLD3qWB_register_Asm_32: {
6447 MCInst TmpInst;
6448 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006449 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006450 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6451 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6452 Spacing));
6453 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6454 Spacing * 2));
6455 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6456 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6457 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6458 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6459 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6460 TmpInst.addOperand(Inst.getOperand(5));
6461 Inst = TmpInst;
6462 return true;
6463 }
6464
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006465 // VLD4DUP single 3-element structure to all lanes instructions.
6466 case ARM::VLD4DUPdAsm_8:
6467 case ARM::VLD4DUPdAsm_16:
6468 case ARM::VLD4DUPdAsm_32:
6469 case ARM::VLD4DUPqAsm_8:
6470 case ARM::VLD4DUPqAsm_16:
6471 case ARM::VLD4DUPqAsm_32: {
6472 MCInst TmpInst;
6473 unsigned Spacing;
6474 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6475 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6476 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6477 Spacing));
6478 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6479 Spacing * 2));
6480 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6481 Spacing * 3));
6482 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6483 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6484 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6485 TmpInst.addOperand(Inst.getOperand(4));
6486 Inst = TmpInst;
6487 return true;
6488 }
6489
6490 case ARM::VLD4DUPdWB_fixed_Asm_8:
6491 case ARM::VLD4DUPdWB_fixed_Asm_16:
6492 case ARM::VLD4DUPdWB_fixed_Asm_32:
6493 case ARM::VLD4DUPqWB_fixed_Asm_8:
6494 case ARM::VLD4DUPqWB_fixed_Asm_16:
6495 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6496 MCInst TmpInst;
6497 unsigned Spacing;
6498 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6499 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6500 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6501 Spacing));
6502 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6503 Spacing * 2));
6504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6505 Spacing * 3));
6506 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6507 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6508 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6509 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6510 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6511 TmpInst.addOperand(Inst.getOperand(4));
6512 Inst = TmpInst;
6513 return true;
6514 }
6515
6516 case ARM::VLD4DUPdWB_register_Asm_8:
6517 case ARM::VLD4DUPdWB_register_Asm_16:
6518 case ARM::VLD4DUPdWB_register_Asm_32:
6519 case ARM::VLD4DUPqWB_register_Asm_8:
6520 case ARM::VLD4DUPqWB_register_Asm_16:
6521 case ARM::VLD4DUPqWB_register_Asm_32: {
6522 MCInst TmpInst;
6523 unsigned Spacing;
6524 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6525 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6526 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6527 Spacing));
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6529 Spacing * 2));
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6531 Spacing * 3));
6532 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6533 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6534 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6535 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6536 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6537 TmpInst.addOperand(Inst.getOperand(5));
6538 Inst = TmpInst;
6539 return true;
6540 }
6541
6542 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006543 case ARM::VLD4dAsm_8:
6544 case ARM::VLD4dAsm_16:
6545 case ARM::VLD4dAsm_32:
6546 case ARM::VLD4qAsm_8:
6547 case ARM::VLD4qAsm_16:
6548 case ARM::VLD4qAsm_32: {
6549 MCInst TmpInst;
6550 unsigned Spacing;
6551 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6552 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6553 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6554 Spacing));
6555 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6556 Spacing * 2));
6557 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6558 Spacing * 3));
6559 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6560 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6561 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6562 TmpInst.addOperand(Inst.getOperand(4));
6563 Inst = TmpInst;
6564 return true;
6565 }
6566
6567 case ARM::VLD4dWB_fixed_Asm_8:
6568 case ARM::VLD4dWB_fixed_Asm_16:
6569 case ARM::VLD4dWB_fixed_Asm_32:
6570 case ARM::VLD4qWB_fixed_Asm_8:
6571 case ARM::VLD4qWB_fixed_Asm_16:
6572 case ARM::VLD4qWB_fixed_Asm_32: {
6573 MCInst TmpInst;
6574 unsigned Spacing;
6575 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6576 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6577 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6578 Spacing));
6579 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6580 Spacing * 2));
6581 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6582 Spacing * 3));
6583 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6584 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6585 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6586 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6587 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6588 TmpInst.addOperand(Inst.getOperand(4));
6589 Inst = TmpInst;
6590 return true;
6591 }
6592
6593 case ARM::VLD4dWB_register_Asm_8:
6594 case ARM::VLD4dWB_register_Asm_16:
6595 case ARM::VLD4dWB_register_Asm_32:
6596 case ARM::VLD4qWB_register_Asm_8:
6597 case ARM::VLD4qWB_register_Asm_16:
6598 case ARM::VLD4qWB_register_Asm_32: {
6599 MCInst TmpInst;
6600 unsigned Spacing;
6601 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6602 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6603 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6604 Spacing));
6605 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6606 Spacing * 2));
6607 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6608 Spacing * 3));
6609 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6610 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6611 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6612 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6613 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6614 TmpInst.addOperand(Inst.getOperand(5));
6615 Inst = TmpInst;
6616 return true;
6617 }
6618
Jim Grosbach1a747242012-01-23 23:45:44 +00006619 // VST3 multiple 3-element structure instructions.
6620 case ARM::VST3dAsm_8:
6621 case ARM::VST3dAsm_16:
6622 case ARM::VST3dAsm_32:
6623 case ARM::VST3qAsm_8:
6624 case ARM::VST3qAsm_16:
6625 case ARM::VST3qAsm_32: {
6626 MCInst TmpInst;
6627 unsigned Spacing;
6628 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6629 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6630 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6631 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6632 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 Spacing));
6634 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6635 Spacing * 2));
6636 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6637 TmpInst.addOperand(Inst.getOperand(4));
6638 Inst = TmpInst;
6639 return true;
6640 }
6641
6642 case ARM::VST3dWB_fixed_Asm_8:
6643 case ARM::VST3dWB_fixed_Asm_16:
6644 case ARM::VST3dWB_fixed_Asm_32:
6645 case ARM::VST3qWB_fixed_Asm_8:
6646 case ARM::VST3qWB_fixed_Asm_16:
6647 case ARM::VST3qWB_fixed_Asm_32: {
6648 MCInst TmpInst;
6649 unsigned Spacing;
6650 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6651 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6652 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6653 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6654 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6655 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6656 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6657 Spacing));
6658 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6659 Spacing * 2));
6660 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6661 TmpInst.addOperand(Inst.getOperand(4));
6662 Inst = TmpInst;
6663 return true;
6664 }
6665
6666 case ARM::VST3dWB_register_Asm_8:
6667 case ARM::VST3dWB_register_Asm_16:
6668 case ARM::VST3dWB_register_Asm_32:
6669 case ARM::VST3qWB_register_Asm_8:
6670 case ARM::VST3qWB_register_Asm_16:
6671 case ARM::VST3qWB_register_Asm_32: {
6672 MCInst TmpInst;
6673 unsigned Spacing;
6674 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6675 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6676 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6677 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6678 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6679 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6680 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6681 Spacing));
6682 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6683 Spacing * 2));
6684 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6685 TmpInst.addOperand(Inst.getOperand(5));
6686 Inst = TmpInst;
6687 return true;
6688 }
6689
Jim Grosbachda70eac2012-01-24 00:58:13 +00006690 // VST4 multiple 3-element structure instructions.
6691 case ARM::VST4dAsm_8:
6692 case ARM::VST4dAsm_16:
6693 case ARM::VST4dAsm_32:
6694 case ARM::VST4qAsm_8:
6695 case ARM::VST4qAsm_16:
6696 case ARM::VST4qAsm_32: {
6697 MCInst TmpInst;
6698 unsigned Spacing;
6699 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6700 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6701 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6702 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6703 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6704 Spacing));
6705 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6706 Spacing * 2));
6707 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6708 Spacing * 3));
6709 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6710 TmpInst.addOperand(Inst.getOperand(4));
6711 Inst = TmpInst;
6712 return true;
6713 }
6714
6715 case ARM::VST4dWB_fixed_Asm_8:
6716 case ARM::VST4dWB_fixed_Asm_16:
6717 case ARM::VST4dWB_fixed_Asm_32:
6718 case ARM::VST4qWB_fixed_Asm_8:
6719 case ARM::VST4qWB_fixed_Asm_16:
6720 case ARM::VST4qWB_fixed_Asm_32: {
6721 MCInst TmpInst;
6722 unsigned Spacing;
6723 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6724 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6725 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6726 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6727 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6728 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6729 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6730 Spacing));
6731 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6732 Spacing * 2));
6733 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6734 Spacing * 3));
6735 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6736 TmpInst.addOperand(Inst.getOperand(4));
6737 Inst = TmpInst;
6738 return true;
6739 }
6740
6741 case ARM::VST4dWB_register_Asm_8:
6742 case ARM::VST4dWB_register_Asm_16:
6743 case ARM::VST4dWB_register_Asm_32:
6744 case ARM::VST4qWB_register_Asm_8:
6745 case ARM::VST4qWB_register_Asm_16:
6746 case ARM::VST4qWB_register_Asm_32: {
6747 MCInst TmpInst;
6748 unsigned Spacing;
6749 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6750 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6751 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6752 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6753 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6754 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6756 Spacing));
6757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6758 Spacing * 2));
6759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6760 Spacing * 3));
6761 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6762 TmpInst.addOperand(Inst.getOperand(5));
6763 Inst = TmpInst;
6764 return true;
6765 }
6766
Jim Grosbachad66de12012-04-11 00:15:16 +00006767 // Handle encoding choice for the shift-immediate instructions.
6768 case ARM::t2LSLri:
6769 case ARM::t2LSRri:
6770 case ARM::t2ASRri: {
6771 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6772 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6773 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6774 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6775 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6776 unsigned NewOpc;
6777 switch (Inst.getOpcode()) {
6778 default: llvm_unreachable("unexpected opcode");
6779 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6780 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6781 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6782 }
6783 // The Thumb1 operands aren't in the same order. Awesome, eh?
6784 MCInst TmpInst;
6785 TmpInst.setOpcode(NewOpc);
6786 TmpInst.addOperand(Inst.getOperand(0));
6787 TmpInst.addOperand(Inst.getOperand(5));
6788 TmpInst.addOperand(Inst.getOperand(1));
6789 TmpInst.addOperand(Inst.getOperand(2));
6790 TmpInst.addOperand(Inst.getOperand(3));
6791 TmpInst.addOperand(Inst.getOperand(4));
6792 Inst = TmpInst;
6793 return true;
6794 }
6795 return false;
6796 }
6797
Jim Grosbach485e5622011-12-13 22:45:11 +00006798 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006799 case ARM::t2MOVsr:
6800 case ARM::t2MOVSsr: {
6801 // Which instruction to expand to depends on the CCOut operand and
6802 // whether we're in an IT block if the register operands are low
6803 // registers.
6804 bool isNarrow = false;
6805 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6806 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6807 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6808 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6809 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6810 isNarrow = true;
6811 MCInst TmpInst;
6812 unsigned newOpc;
6813 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6814 default: llvm_unreachable("unexpected opcode!");
6815 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6816 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6817 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6818 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6819 }
6820 TmpInst.setOpcode(newOpc);
6821 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6822 if (isNarrow)
6823 TmpInst.addOperand(MCOperand::CreateReg(
6824 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6825 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6826 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6827 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6828 TmpInst.addOperand(Inst.getOperand(5));
6829 if (!isNarrow)
6830 TmpInst.addOperand(MCOperand::CreateReg(
6831 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6832 Inst = TmpInst;
6833 return true;
6834 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006835 case ARM::t2MOVsi:
6836 case ARM::t2MOVSsi: {
6837 // Which instruction to expand to depends on the CCOut operand and
6838 // whether we're in an IT block if the register operands are low
6839 // registers.
6840 bool isNarrow = false;
6841 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6842 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6843 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6844 isNarrow = true;
6845 MCInst TmpInst;
6846 unsigned newOpc;
6847 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6848 default: llvm_unreachable("unexpected opcode!");
6849 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6850 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6851 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6852 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006853 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006854 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006855 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6856 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006857 TmpInst.setOpcode(newOpc);
6858 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6859 if (isNarrow)
6860 TmpInst.addOperand(MCOperand::CreateReg(
6861 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6862 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006863 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006864 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006865 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6866 TmpInst.addOperand(Inst.getOperand(4));
6867 if (!isNarrow)
6868 TmpInst.addOperand(MCOperand::CreateReg(
6869 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6870 Inst = TmpInst;
6871 return true;
6872 }
6873 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006874 case ARM::ASRr:
6875 case ARM::LSRr:
6876 case ARM::LSLr:
6877 case ARM::RORr: {
6878 ARM_AM::ShiftOpc ShiftTy;
6879 switch(Inst.getOpcode()) {
6880 default: llvm_unreachable("unexpected opcode!");
6881 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6882 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6883 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6884 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6885 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006886 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6887 MCInst TmpInst;
6888 TmpInst.setOpcode(ARM::MOVsr);
6889 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6890 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6891 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6892 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6893 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6894 TmpInst.addOperand(Inst.getOperand(4));
6895 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6896 Inst = TmpInst;
6897 return true;
6898 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006899 case ARM::ASRi:
6900 case ARM::LSRi:
6901 case ARM::LSLi:
6902 case ARM::RORi: {
6903 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006904 switch(Inst.getOpcode()) {
6905 default: llvm_unreachable("unexpected opcode!");
6906 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6907 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6908 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6909 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6910 }
6911 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006912 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00006913 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00006914 // A shift by 32 should be encoded as 0 when permitted
6915 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6916 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006917 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006918 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006919 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006920 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6921 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00006922 if (Opc == ARM::MOVsi)
6923 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00006924 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6925 TmpInst.addOperand(Inst.getOperand(4));
6926 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6927 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006928 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00006929 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006930 case ARM::RRXi: {
6931 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6932 MCInst TmpInst;
6933 TmpInst.setOpcode(ARM::MOVsi);
6934 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6935 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6936 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6937 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6938 TmpInst.addOperand(Inst.getOperand(3));
6939 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6940 Inst = TmpInst;
6941 return true;
6942 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00006943 case ARM::t2LDMIA_UPD: {
6944 // If this is a load of a single register, then we should use
6945 // a post-indexed LDR instruction instead, per the ARM ARM.
6946 if (Inst.getNumOperands() != 5)
6947 return false;
6948 MCInst TmpInst;
6949 TmpInst.setOpcode(ARM::t2LDR_POST);
6950 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6951 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6952 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6953 TmpInst.addOperand(MCOperand::CreateImm(4));
6954 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6955 TmpInst.addOperand(Inst.getOperand(3));
6956 Inst = TmpInst;
6957 return true;
6958 }
6959 case ARM::t2STMDB_UPD: {
6960 // If this is a store of a single register, then we should use
6961 // a pre-indexed STR instruction instead, per the ARM ARM.
6962 if (Inst.getNumOperands() != 5)
6963 return false;
6964 MCInst TmpInst;
6965 TmpInst.setOpcode(ARM::t2STR_PRE);
6966 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6967 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6968 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6969 TmpInst.addOperand(MCOperand::CreateImm(-4));
6970 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6971 TmpInst.addOperand(Inst.getOperand(3));
6972 Inst = TmpInst;
6973 return true;
6974 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006975 case ARM::LDMIA_UPD:
6976 // If this is a load of a single register via a 'pop', then we should use
6977 // a post-indexed LDR instruction instead, per the ARM ARM.
6978 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6979 Inst.getNumOperands() == 5) {
6980 MCInst TmpInst;
6981 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6982 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6983 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6984 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6985 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6986 TmpInst.addOperand(MCOperand::CreateImm(4));
6987 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6988 TmpInst.addOperand(Inst.getOperand(3));
6989 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006990 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006991 }
6992 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00006993 case ARM::STMDB_UPD:
6994 // If this is a store of a single register via a 'push', then we should use
6995 // a pre-indexed STR instruction instead, per the ARM ARM.
6996 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6997 Inst.getNumOperands() == 5) {
6998 MCInst TmpInst;
6999 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7000 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7001 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7002 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7003 TmpInst.addOperand(MCOperand::CreateImm(-4));
7004 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7005 TmpInst.addOperand(Inst.getOperand(3));
7006 Inst = TmpInst;
7007 }
7008 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007009 case ARM::t2ADDri12:
7010 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7011 // mnemonic was used (not "addw"), encoding T3 is preferred.
7012 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7013 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7014 break;
7015 Inst.setOpcode(ARM::t2ADDri);
7016 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7017 break;
7018 case ARM::t2SUBri12:
7019 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7020 // mnemonic was used (not "subw"), encoding T3 is preferred.
7021 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7022 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7023 break;
7024 Inst.setOpcode(ARM::t2SUBri);
7025 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7026 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007027 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007028 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007029 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7030 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7031 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007032 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007033 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007034 return true;
7035 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007036 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007037 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007038 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007039 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7040 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7041 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007042 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007043 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007044 return true;
7045 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007046 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007047 case ARM::t2ADDri:
7048 case ARM::t2SUBri: {
7049 // If the destination and first source operand are the same, and
7050 // the flags are compatible with the current IT status, use encoding T2
7051 // instead of T3. For compatibility with the system 'as'. Make sure the
7052 // wide encoding wasn't explicit.
7053 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007054 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007055 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7056 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7057 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7058 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7059 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7060 break;
7061 MCInst TmpInst;
7062 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7063 ARM::tADDi8 : ARM::tSUBi8);
7064 TmpInst.addOperand(Inst.getOperand(0));
7065 TmpInst.addOperand(Inst.getOperand(5));
7066 TmpInst.addOperand(Inst.getOperand(0));
7067 TmpInst.addOperand(Inst.getOperand(2));
7068 TmpInst.addOperand(Inst.getOperand(3));
7069 TmpInst.addOperand(Inst.getOperand(4));
7070 Inst = TmpInst;
7071 return true;
7072 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007073 case ARM::t2ADDrr: {
7074 // If the destination and first source operand are the same, and
7075 // there's no setting of the flags, use encoding T2 instead of T3.
7076 // Note that this is only for ADD, not SUB. This mirrors the system
7077 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7078 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7079 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007080 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7081 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007082 break;
7083 MCInst TmpInst;
7084 TmpInst.setOpcode(ARM::tADDhirr);
7085 TmpInst.addOperand(Inst.getOperand(0));
7086 TmpInst.addOperand(Inst.getOperand(0));
7087 TmpInst.addOperand(Inst.getOperand(2));
7088 TmpInst.addOperand(Inst.getOperand(3));
7089 TmpInst.addOperand(Inst.getOperand(4));
7090 Inst = TmpInst;
7091 return true;
7092 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007093 case ARM::tADDrSP: {
7094 // If the non-SP source operand and the destination operand are not the
7095 // same, we need to use the 32-bit encoding if it's available.
7096 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7097 Inst.setOpcode(ARM::t2ADDrr);
7098 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7099 return true;
7100 }
7101 break;
7102 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007103 case ARM::tB:
7104 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007105 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007106 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007107 return true;
7108 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007109 break;
7110 case ARM::t2B:
7111 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007112 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007113 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007114 return true;
7115 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007116 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007117 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007118 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007119 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007120 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007121 return true;
7122 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007123 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007124 case ARM::tBcc:
7125 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007126 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007127 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007128 return true;
7129 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007130 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007131 case ARM::tLDMIA: {
7132 // If the register list contains any high registers, or if the writeback
7133 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7134 // instead if we're in Thumb2. Otherwise, this should have generated
7135 // an error in validateInstruction().
7136 unsigned Rn = Inst.getOperand(0).getReg();
7137 bool hasWritebackToken =
7138 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7139 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7140 bool listContainsBase;
7141 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7142 (!listContainsBase && !hasWritebackToken) ||
7143 (listContainsBase && hasWritebackToken)) {
7144 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7145 assert (isThumbTwo());
7146 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7147 // If we're switching to the updating version, we need to insert
7148 // the writeback tied operand.
7149 if (hasWritebackToken)
7150 Inst.insert(Inst.begin(),
7151 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007152 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007153 }
7154 break;
7155 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007156 case ARM::tSTMIA_UPD: {
7157 // If the register list contains any high registers, we need to use
7158 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7159 // should have generated an error in validateInstruction().
7160 unsigned Rn = Inst.getOperand(0).getReg();
7161 bool listContainsBase;
7162 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7163 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7164 assert (isThumbTwo());
7165 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007166 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007167 }
7168 break;
7169 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007170 case ARM::tPOP: {
7171 bool listContainsBase;
7172 // If the register list contains any high registers, we need to use
7173 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7174 // should have generated an error in validateInstruction().
7175 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007176 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007177 assert (isThumbTwo());
7178 Inst.setOpcode(ARM::t2LDMIA_UPD);
7179 // Add the base register and writeback operands.
7180 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7181 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007182 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007183 }
7184 case ARM::tPUSH: {
7185 bool listContainsBase;
7186 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007187 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007188 assert (isThumbTwo());
7189 Inst.setOpcode(ARM::t2STMDB_UPD);
7190 // Add the base register and writeback operands.
7191 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7192 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007193 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007194 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007195 case ARM::t2MOVi: {
7196 // If we can use the 16-bit encoding and the user didn't explicitly
7197 // request the 32-bit variant, transform it here.
7198 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007199 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007200 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7201 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7202 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007203 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7204 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7205 // The operands aren't in the same order for tMOVi8...
7206 MCInst TmpInst;
7207 TmpInst.setOpcode(ARM::tMOVi8);
7208 TmpInst.addOperand(Inst.getOperand(0));
7209 TmpInst.addOperand(Inst.getOperand(4));
7210 TmpInst.addOperand(Inst.getOperand(1));
7211 TmpInst.addOperand(Inst.getOperand(2));
7212 TmpInst.addOperand(Inst.getOperand(3));
7213 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007214 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007215 }
7216 break;
7217 }
7218 case ARM::t2MOVr: {
7219 // If we can use the 16-bit encoding and the user didn't explicitly
7220 // request the 32-bit variant, transform it here.
7221 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7222 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7223 Inst.getOperand(2).getImm() == ARMCC::AL &&
7224 Inst.getOperand(4).getReg() == ARM::CPSR &&
7225 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7226 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7227 // The operands aren't the same for tMOV[S]r... (no cc_out)
7228 MCInst TmpInst;
7229 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7230 TmpInst.addOperand(Inst.getOperand(0));
7231 TmpInst.addOperand(Inst.getOperand(1));
7232 TmpInst.addOperand(Inst.getOperand(2));
7233 TmpInst.addOperand(Inst.getOperand(3));
7234 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007235 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007236 }
7237 break;
7238 }
Jim Grosbach82213192011-09-19 20:29:33 +00007239 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007240 case ARM::t2SXTB:
7241 case ARM::t2UXTH:
7242 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007243 // If we can use the 16-bit encoding and the user didn't explicitly
7244 // request the 32-bit variant, transform it here.
7245 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7246 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7247 Inst.getOperand(2).getImm() == 0 &&
7248 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7249 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007250 unsigned NewOpc;
7251 switch (Inst.getOpcode()) {
7252 default: llvm_unreachable("Illegal opcode!");
7253 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7254 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7255 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7256 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7257 }
Jim Grosbach82213192011-09-19 20:29:33 +00007258 // The operands aren't the same for thumb1 (no rotate operand).
7259 MCInst TmpInst;
7260 TmpInst.setOpcode(NewOpc);
7261 TmpInst.addOperand(Inst.getOperand(0));
7262 TmpInst.addOperand(Inst.getOperand(1));
7263 TmpInst.addOperand(Inst.getOperand(3));
7264 TmpInst.addOperand(Inst.getOperand(4));
7265 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007266 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007267 }
7268 break;
7269 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007270 case ARM::MOVsi: {
7271 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007272 // rrx shifts and asr/lsr of #32 is encoded as 0
7273 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7274 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007275 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7276 // Shifting by zero is accepted as a vanilla 'MOVr'
7277 MCInst TmpInst;
7278 TmpInst.setOpcode(ARM::MOVr);
7279 TmpInst.addOperand(Inst.getOperand(0));
7280 TmpInst.addOperand(Inst.getOperand(1));
7281 TmpInst.addOperand(Inst.getOperand(3));
7282 TmpInst.addOperand(Inst.getOperand(4));
7283 TmpInst.addOperand(Inst.getOperand(5));
7284 Inst = TmpInst;
7285 return true;
7286 }
7287 return false;
7288 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007289 case ARM::ANDrsi:
7290 case ARM::ORRrsi:
7291 case ARM::EORrsi:
7292 case ARM::BICrsi:
7293 case ARM::SUBrsi:
7294 case ARM::ADDrsi: {
7295 unsigned newOpc;
7296 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7297 if (SOpc == ARM_AM::rrx) return false;
7298 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007299 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007300 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7301 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7302 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7303 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7304 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7305 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7306 }
7307 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007308 // The exception is for right shifts, where 0 == 32
7309 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7310 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007311 MCInst TmpInst;
7312 TmpInst.setOpcode(newOpc);
7313 TmpInst.addOperand(Inst.getOperand(0));
7314 TmpInst.addOperand(Inst.getOperand(1));
7315 TmpInst.addOperand(Inst.getOperand(2));
7316 TmpInst.addOperand(Inst.getOperand(4));
7317 TmpInst.addOperand(Inst.getOperand(5));
7318 TmpInst.addOperand(Inst.getOperand(6));
7319 Inst = TmpInst;
7320 return true;
7321 }
7322 return false;
7323 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007324 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007325 case ARM::t2IT: {
7326 // The mask bits for all but the first condition are represented as
7327 // the low bit of the condition code value implies 't'. We currently
7328 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007329 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007330 MCOperand &MO = Inst.getOperand(1);
7331 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007332 unsigned OrigMask = Mask;
7333 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007334 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007335 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7336 for (unsigned i = 3; i != TZ; --i)
7337 Mask ^= 1 << i;
Richard Bartonf435b092012-04-27 08:42:59 +00007338 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007339 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007340
7341 // Set up the IT block state according to the IT instruction we just
7342 // matched.
7343 assert(!inITBlock() && "nested IT blocks?!");
7344 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7345 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7346 ITState.CurPosition = 0;
7347 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007348 break;
7349 }
Richard Bartona39625e2012-07-09 16:12:24 +00007350 case ARM::t2LSLrr:
7351 case ARM::t2LSRrr:
7352 case ARM::t2ASRrr:
7353 case ARM::t2SBCrr:
7354 case ARM::t2RORrr:
7355 case ARM::t2BICrr:
7356 {
Richard Bartond5660372012-07-09 16:14:28 +00007357 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007358 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7359 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7360 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007361 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7362 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007363 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7364 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7365 unsigned NewOpc;
7366 switch (Inst.getOpcode()) {
7367 default: llvm_unreachable("unexpected opcode");
7368 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7369 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7370 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7371 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7372 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7373 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7374 }
7375 MCInst TmpInst;
7376 TmpInst.setOpcode(NewOpc);
7377 TmpInst.addOperand(Inst.getOperand(0));
7378 TmpInst.addOperand(Inst.getOperand(5));
7379 TmpInst.addOperand(Inst.getOperand(1));
7380 TmpInst.addOperand(Inst.getOperand(2));
7381 TmpInst.addOperand(Inst.getOperand(3));
7382 TmpInst.addOperand(Inst.getOperand(4));
7383 Inst = TmpInst;
7384 return true;
7385 }
7386 return false;
7387 }
7388 case ARM::t2ANDrr:
7389 case ARM::t2EORrr:
7390 case ARM::t2ADCrr:
7391 case ARM::t2ORRrr:
7392 {
Richard Bartond5660372012-07-09 16:14:28 +00007393 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007394 // These instructions are special in that they are commutable, so shorter encodings
7395 // are available more often.
7396 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7397 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7398 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7399 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007400 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7401 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007402 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7403 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7404 unsigned NewOpc;
7405 switch (Inst.getOpcode()) {
7406 default: llvm_unreachable("unexpected opcode");
7407 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7408 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7409 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7410 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7411 }
7412 MCInst TmpInst;
7413 TmpInst.setOpcode(NewOpc);
7414 TmpInst.addOperand(Inst.getOperand(0));
7415 TmpInst.addOperand(Inst.getOperand(5));
7416 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7417 TmpInst.addOperand(Inst.getOperand(1));
7418 TmpInst.addOperand(Inst.getOperand(2));
7419 } else {
7420 TmpInst.addOperand(Inst.getOperand(2));
7421 TmpInst.addOperand(Inst.getOperand(1));
7422 }
7423 TmpInst.addOperand(Inst.getOperand(3));
7424 TmpInst.addOperand(Inst.getOperand(4));
7425 Inst = TmpInst;
7426 return true;
7427 }
7428 return false;
7429 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007430 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007431 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007432}
7433
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007434unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7435 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7436 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007437 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007438 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007439 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7440 assert(MCID.hasOptionalDef() &&
7441 "optionally flag setting instruction missing optional def operand");
7442 assert(MCID.NumOperands == Inst.getNumOperands() &&
7443 "operand count mismatch!");
7444 // Find the optional-def operand (cc_out).
7445 unsigned OpNo;
7446 for (OpNo = 0;
7447 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7448 ++OpNo)
7449 ;
7450 // If we're parsing Thumb1, reject it completely.
7451 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7452 return Match_MnemonicFail;
7453 // If we're parsing Thumb2, which form is legal depends on whether we're
7454 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007455 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7456 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007457 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007458 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7459 inITBlock())
7460 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007461 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007462 // Some high-register supporting Thumb1 encodings only allow both registers
7463 // to be from r0-r7 when in Thumb2.
7464 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7465 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7466 isARMLowRegister(Inst.getOperand(2).getReg()))
7467 return Match_RequiresThumb2;
7468 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007469 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007470 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7471 isARMLowRegister(Inst.getOperand(1).getReg()))
7472 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007473 return Match_Success;
7474}
7475
Jim Grosbach5117ef72012-04-24 22:40:08 +00007476static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007477bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007478MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007479 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007480 MCStreamer &Out, unsigned &ErrorInfo,
7481 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007482 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007483 unsigned MatchResult;
Chad Rosier2f480a82012-10-12 22:53:36 +00007484 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007485 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007486 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007487 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007488 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007489 // Context sensitive operand constraints aren't handled by the matcher,
7490 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007491 if (validateInstruction(Inst, Operands)) {
7492 // Still progress the IT block, otherwise one wrong condition causes
7493 // nasty cascading errors.
7494 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007495 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007496 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007497
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007498 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007499 // encoding is selected. Loop on it while changes happen so the
7500 // individual transformations can chain off each other. E.g.,
7501 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7502 while (processInstruction(Inst, Operands))
7503 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007504
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007505 // Only move forward at the very end so that everything in validate
7506 // and process gets a consistent answer about whether we're in an IT
7507 // block.
7508 forwardITPosition();
7509
Jim Grosbach82f76d12012-01-25 19:52:01 +00007510 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7511 // doesn't actually encode.
7512 if (Inst.getOpcode() == ARM::ITasm)
7513 return false;
7514
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007515 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007516 Out.EmitInstruction(Inst);
7517 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007518 case Match_MissingFeature: {
7519 assert(ErrorInfo && "Unknown missing feature!");
7520 // Special case the error message for the very common case where only
7521 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7522 std::string Msg = "instruction requires:";
7523 unsigned Mask = 1;
7524 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7525 if (ErrorInfo & Mask) {
7526 Msg += " ";
7527 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7528 }
7529 Mask <<= 1;
7530 }
7531 return Error(IDLoc, Msg);
7532 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007533 case Match_InvalidOperand: {
7534 SMLoc ErrorLoc = IDLoc;
7535 if (ErrorInfo != ~0U) {
7536 if (ErrorInfo >= Operands.size())
7537 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007538
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007539 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7540 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7541 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007542
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007543 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007544 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007545 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007546 return Error(IDLoc, "invalid instruction",
7547 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007548 case Match_RequiresNotITBlock:
7549 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007550 case Match_RequiresITBlock:
7551 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007552 case Match_RequiresV6:
7553 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7554 case Match_RequiresThumb2:
7555 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007556 case Match_ImmRange0_15: {
7557 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7558 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7559 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7560 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007561 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007562
Eric Christopher91d7b902010-10-29 09:26:59 +00007563 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007564}
7565
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007566/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007567bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7568 StringRef IDVal = DirectiveID.getIdentifier();
7569 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007570 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007571 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007572 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007573 else if (IDVal == ".arm")
7574 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007575 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007576 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007577 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007578 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007579 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007580 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007581 else if (IDVal == ".unreq")
7582 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007583 else if (IDVal == ".arch")
7584 return parseDirectiveArch(DirectiveID.getLoc());
7585 else if (IDVal == ".eabi_attribute")
7586 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyccab3172009-09-15 00:27:25 +00007587 return true;
7588}
7589
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007590/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007591/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007592bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007593 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7594 for (;;) {
7595 const MCExpr *Value;
7596 if (getParser().ParseExpression(Value))
7597 return true;
7598
Chris Lattnerc35681b2010-01-19 19:46:13 +00007599 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007600
7601 if (getLexer().is(AsmToken::EndOfStatement))
7602 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007603
Kevin Enderbyccab3172009-09-15 00:27:25 +00007604 // FIXME: Improve diagnostic.
7605 if (getLexer().isNot(AsmToken::Comma))
7606 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007607 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007608 }
7609 }
7610
Sean Callanana83fd7d2010-01-19 20:27:46 +00007611 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007612 return false;
7613}
7614
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007615/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007616/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007617bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007618 if (getLexer().isNot(AsmToken::EndOfStatement))
7619 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007620 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007621
Jim Grosbach7f882392011-12-07 18:04:19 +00007622 if (!isThumb())
7623 SwitchMode();
7624 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7625 return false;
7626}
7627
7628/// parseDirectiveARM
7629/// ::= .arm
7630bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7631 if (getLexer().isNot(AsmToken::EndOfStatement))
7632 return Error(L, "unexpected token in directive");
7633 Parser.Lex();
7634
7635 if (isThumb())
7636 SwitchMode();
7637 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007638 return false;
7639}
7640
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007641/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007642/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007643bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007644 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7645 bool isMachO = MAI.hasSubsectionsViaSymbols();
7646 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007647 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007648
Jim Grosbach1152cc02011-12-21 22:30:16 +00007649 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007650 // ELF doesn't
7651 if (isMachO) {
7652 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007653 if (Tok.isNot(AsmToken::EndOfStatement)) {
7654 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7655 return Error(L, "unexpected token in .thumb_func directive");
7656 Name = Tok.getIdentifier();
7657 Parser.Lex(); // Consume the identifier token.
7658 needFuncName = false;
7659 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007660 }
7661
Jim Grosbach1152cc02011-12-21 22:30:16 +00007662 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007663 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007664
7665 // Eat the end of statement and any blank lines that follow.
7666 while (getLexer().is(AsmToken::EndOfStatement))
7667 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007668
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007669 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007670 // We really should be checking the next symbol definition even if there's
7671 // stuff in between.
7672 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007673 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007674 }
7675
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007676 // Mark symbol as a thumb symbol.
7677 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7678 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007679 return false;
7680}
7681
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007682/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007683/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007684bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007685 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007686 if (Tok.isNot(AsmToken::Identifier))
7687 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007688 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007689 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007690 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007691 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007692 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007693 else
7694 return Error(L, "unrecognized syntax mode in .syntax directive");
7695
7696 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007697 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007698 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007699
7700 // TODO tell the MC streamer the mode
7701 // getParser().getStreamer().Emit???();
7702 return false;
7703}
7704
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007705/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007706/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007707bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007708 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007709 if (Tok.isNot(AsmToken::Integer))
7710 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007711 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007712 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007713 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007714 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007715 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007716 else
7717 return Error(L, "invalid operand to .code directive");
7718
7719 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007720 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007721 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007722
Evan Cheng284b4672011-07-08 22:36:29 +00007723 if (Val == 16) {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007724 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007725 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007726 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007727 } else {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007728 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007729 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007730 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007731 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007732
Kevin Enderby146dcf22009-10-15 20:48:48 +00007733 return false;
7734}
7735
Jim Grosbachab5830e2011-12-14 02:16:11 +00007736/// parseDirectiveReq
7737/// ::= name .req registername
7738bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7739 Parser.Lex(); // Eat the '.req' token.
7740 unsigned Reg;
7741 SMLoc SRegLoc, ERegLoc;
7742 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7743 Parser.EatToEndOfStatement();
7744 return Error(SRegLoc, "register name expected");
7745 }
7746
7747 // Shouldn't be anything else.
7748 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7749 Parser.EatToEndOfStatement();
7750 return Error(Parser.getTok().getLoc(),
7751 "unexpected input in .req directive.");
7752 }
7753
7754 Parser.Lex(); // Consume the EndOfStatement
7755
7756 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7757 return Error(SRegLoc, "redefinition of '" + Name +
7758 "' does not match original.");
7759
7760 return false;
7761}
7762
7763/// parseDirectiveUneq
7764/// ::= .unreq registername
7765bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7766 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7767 Parser.EatToEndOfStatement();
7768 return Error(L, "unexpected input in .unreq directive.");
7769 }
7770 RegisterReqs.erase(Parser.getTok().getIdentifier());
7771 Parser.Lex(); // Eat the identifier.
7772 return false;
7773}
7774
Jason W Kim135d2442011-12-20 17:38:12 +00007775/// parseDirectiveArch
7776/// ::= .arch token
7777bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7778 return true;
7779}
7780
7781/// parseDirectiveEabiAttr
7782/// ::= .eabi_attribute int, int
7783bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7784 return true;
7785}
7786
Sean Callanan643a5572010-04-07 20:29:34 +00007787extern "C" void LLVMInitializeARMAsmLexer();
7788
Kevin Enderby8be42bd2009-10-30 22:55:57 +00007789/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00007790extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00007791 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7792 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan643a5572010-04-07 20:29:34 +00007793 LLVMInitializeARMAsmLexer();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007794}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007795
Chris Lattner3e4582a2010-09-06 19:11:01 +00007796#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00007797#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00007798#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007799#include "ARMGenAsmMatcher.inc"