blob: 93e5eca62526c944ef41872ce956bf68dd5a6370 [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
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000262 bool MatchAndEmitInstruction(SMLoc IDLoc,
263 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
264 MCStreamer &Out);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000265};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000266} // end anonymous namespace
267
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000268namespace {
269
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000270/// ARMOperand - Instances of this class represent a parsed ARM machine
271/// instruction.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000272class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000273 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000274 k_CondCode,
275 k_CCOut,
276 k_ITCondMask,
277 k_CoprocNum,
278 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000279 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000280 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000281 k_MemBarrierOpt,
282 k_Memory,
283 k_PostIndexRegister,
284 k_MSRMask,
285 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000286 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000287 k_Register,
288 k_RegisterList,
289 k_DPRRegisterList,
290 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000291 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000292 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000293 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000294 k_ShiftedRegister,
295 k_ShiftedImmediate,
296 k_ShifterImmediate,
297 k_RotateImmediate,
298 k_BitfieldDescriptor,
299 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000300 } Kind;
301
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000302 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000303 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000304
305 union {
306 struct {
Daniel Dunbard8042b72010-08-11 06:36:53 +0000307 ARMCC::CondCodes Val;
308 } CC;
309
310 struct {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000311 unsigned Val;
312 } Cop;
313
314 struct {
Jim Grosbach48399582011-10-12 17:34:41 +0000315 unsigned Val;
316 } CoprocOption;
317
318 struct {
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000319 unsigned Mask:4;
320 } ITMask;
321
322 struct {
323 ARM_MB::MemBOpt Val;
324 } MBOpt;
325
326 struct {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000327 ARM_PROC::IFlags Val;
328 } IFlags;
329
330 struct {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000331 unsigned Val;
332 } MMask;
333
334 struct {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000335 const char *Data;
336 unsigned Length;
337 } Tok;
338
339 struct {
340 unsigned RegNum;
341 } Reg;
342
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000343 // A vector register list is a sequential list of 1 to 4 registers.
344 struct {
345 unsigned RegNum;
346 unsigned Count;
Jim Grosbach04945c42011-12-02 00:35:16 +0000347 unsigned LaneIndex;
Jim Grosbach2f50e922011-12-15 21:44:33 +0000348 bool isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000349 } VectorList;
350
Bill Wendlingb884a8e2010-11-06 22:19:43 +0000351 struct {
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000352 unsigned Val;
353 } VectorIndex;
354
355 struct {
Kevin Enderbyf5079942009-10-13 22:19:02 +0000356 const MCExpr *Val;
357 } Imm;
Jim Grosbach624bcc72010-10-29 14:46:02 +0000358
Daniel Dunbar2be732a2011-01-10 15:26:21 +0000359 /// Combined record for all forms of ARM address expressions.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000360 struct {
361 unsigned BaseRegNum;
Jim Grosbachd3595712011-08-03 23:50:40 +0000362 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
363 // was specified.
364 const MCConstantExpr *OffsetImm; // Offset immediate value
365 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
366 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbacha95ec992011-10-11 17:29:55 +0000367 unsigned ShiftImm; // shift for OffsetReg.
368 unsigned Alignment; // 0 = no alignment specified
Jim Grosbachcef98cd2011-12-19 18:31:43 +0000369 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbachd3595712011-08-03 23:50:40 +0000370 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbach871dff72011-10-11 15:59:20 +0000371 } Memory;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000372
373 struct {
Jim Grosbachd3595712011-08-03 23:50:40 +0000374 unsigned RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +0000375 bool isAdd;
376 ARM_AM::ShiftOpc ShiftTy;
377 unsigned ShiftImm;
Jim Grosbachd3595712011-08-03 23:50:40 +0000378 } PostIdxReg;
379
380 struct {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000381 bool isASR;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000382 unsigned Imm;
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000383 } ShifterImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000384 struct {
385 ARM_AM::ShiftOpc ShiftTy;
386 unsigned SrcReg;
387 unsigned ShiftReg;
388 unsigned ShiftImm;
Jim Grosbachac798e12011-07-25 20:49:51 +0000389 } RegShiftedReg;
Owen Andersonb595ed02011-07-21 18:54:16 +0000390 struct {
391 ARM_AM::ShiftOpc ShiftTy;
392 unsigned SrcReg;
393 unsigned ShiftImm;
Jim Grosbachac798e12011-07-25 20:49:51 +0000394 } RegShiftedImm;
Jim Grosbach833b9d32011-07-27 20:15:40 +0000395 struct {
396 unsigned Imm;
397 } RotImm;
Jim Grosbach864b6092011-07-28 21:34:26 +0000398 struct {
399 unsigned LSB;
400 unsigned Width;
401 } Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000402 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000403
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000404 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
405public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000406 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
407 Kind = o.Kind;
408 StartLoc = o.StartLoc;
409 EndLoc = o.EndLoc;
410 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000411 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000412 CC = o.CC;
413 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000414 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000415 ITMask = o.ITMask;
416 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000417 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000418 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000419 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000420 case k_CCOut:
421 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000422 Reg = o.Reg;
423 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000424 case k_RegisterList:
425 case k_DPRRegisterList:
426 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000427 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000428 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000429 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000430 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000431 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000432 VectorList = o.VectorList;
433 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000434 case k_CoprocNum:
435 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000436 Cop = o.Cop;
437 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000438 case k_CoprocOption:
439 CoprocOption = o.CoprocOption;
440 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000441 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000442 Imm = o.Imm;
443 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000444 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000445 MBOpt = o.MBOpt;
446 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000447 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000448 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000449 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000450 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000451 PostIdxReg = o.PostIdxReg;
452 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000453 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000454 MMask = o.MMask;
455 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000456 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000457 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000458 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000459 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000460 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000461 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000462 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000463 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000464 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000465 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000466 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000467 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000468 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000469 RotImm = o.RotImm;
470 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000471 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000472 Bitfield = o.Bitfield;
473 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000474 case k_VectorIndex:
475 VectorIndex = o.VectorIndex;
476 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000477 }
478 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000479
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000480 /// getStartLoc - Get the location of the first token of this operand.
481 SMLoc getStartLoc() const { return StartLoc; }
482 /// getEndLoc - Get the location of the last token of this operand.
483 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000484 /// getLocRange - Get the range between the first and last token of this
485 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000486 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
487
Daniel Dunbard8042b72010-08-11 06:36:53 +0000488 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000489 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000490 return CC.Val;
491 }
492
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000493 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000494 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000495 return Cop.Val;
496 }
497
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000498 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000499 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000500 return StringRef(Tok.Data, Tok.Length);
501 }
502
503 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000504 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000505 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000506 }
507
Bill Wendlingbed94652010-11-09 23:28:44 +0000508 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000509 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
510 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000511 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000512 }
513
Kevin Enderbyf5079942009-10-13 22:19:02 +0000514 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000515 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000516 return Imm.Val;
517 }
518
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000519 unsigned getVectorIndex() const {
520 assert(Kind == k_VectorIndex && "Invalid access!");
521 return VectorIndex.Val;
522 }
523
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000524 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000525 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000526 return MBOpt.Val;
527 }
528
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000529 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000530 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000531 return IFlags.Val;
532 }
533
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000534 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000535 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000536 return MMask.Val;
537 }
538
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000539 bool isCoprocNum() const { return Kind == k_CoprocNum; }
540 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000541 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000542 bool isCondCode() const { return Kind == k_CondCode; }
543 bool isCCOut() const { return Kind == k_CCOut; }
544 bool isITMask() const { return Kind == k_ITCondMask; }
545 bool isITCondCode() const { return Kind == k_CondCode; }
546 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000547 bool isFPImm() const {
548 if (!isImm()) return false;
549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
550 if (!CE) return false;
551 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
552 return Val != -1;
553 }
Jim Grosbachea231912011-12-22 22:19:05 +0000554 bool isFBits16() const {
555 if (!isImm()) return false;
556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
557 if (!CE) return false;
558 int64_t Value = CE->getValue();
559 return Value >= 0 && Value <= 16;
560 }
561 bool isFBits32() const {
562 if (!isImm()) return false;
563 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
564 if (!CE) return false;
565 int64_t Value = CE->getValue();
566 return Value >= 1 && Value <= 32;
567 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000568 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000569 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
571 if (!CE) return false;
572 int64_t Value = CE->getValue();
573 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
574 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000575 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000576 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000577 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
578 if (!CE) return false;
579 int64_t Value = CE->getValue();
580 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
581 }
582 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000583 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000584 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
585 if (!CE) return false;
586 int64_t Value = CE->getValue();
587 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
588 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000589 bool isImm0_508s4Neg() const {
590 if (!isImm()) return false;
591 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
592 if (!CE) return false;
593 int64_t Value = -CE->getValue();
594 // explicitly exclude zero. we want that to use the normal 0_508 version.
595 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
596 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000597 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000598 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000599 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
600 if (!CE) return false;
601 int64_t Value = CE->getValue();
602 return Value >= 0 && Value < 256;
603 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000604 bool isImm0_4095() const {
605 if (!isImm()) return false;
606 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
607 if (!CE) return false;
608 int64_t Value = CE->getValue();
609 return Value >= 0 && Value < 4096;
610 }
611 bool isImm0_4095Neg() const {
612 if (!isImm()) return false;
613 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
614 if (!CE) return false;
615 int64_t Value = -CE->getValue();
616 return Value > 0 && Value < 4096;
617 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000618 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000619 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
621 if (!CE) return false;
622 int64_t Value = CE->getValue();
623 return Value >= 0 && Value < 2;
624 }
625 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000626 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000627 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
628 if (!CE) return false;
629 int64_t Value = CE->getValue();
630 return Value >= 0 && Value < 4;
631 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000632 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000633 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000634 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
635 if (!CE) return false;
636 int64_t Value = CE->getValue();
637 return Value >= 0 && Value < 8;
638 }
639 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000640 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
642 if (!CE) return false;
643 int64_t Value = CE->getValue();
644 return Value >= 0 && Value < 16;
645 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000646 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000647 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
649 if (!CE) return false;
650 int64_t Value = CE->getValue();
651 return Value >= 0 && Value < 32;
652 }
Jim Grosbach00326402011-12-08 01:30:04 +0000653 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000654 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000655 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
656 if (!CE) return false;
657 int64_t Value = CE->getValue();
658 return Value >= 0 && Value < 64;
659 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000660 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000661 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
663 if (!CE) return false;
664 int64_t Value = CE->getValue();
665 return Value == 8;
666 }
667 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000668 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
670 if (!CE) return false;
671 int64_t Value = CE->getValue();
672 return Value == 16;
673 }
674 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000675 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
677 if (!CE) return false;
678 int64_t Value = CE->getValue();
679 return Value == 32;
680 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000681 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000682 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
684 if (!CE) return false;
685 int64_t Value = CE->getValue();
686 return Value > 0 && Value <= 8;
687 }
688 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000689 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
691 if (!CE) return false;
692 int64_t Value = CE->getValue();
693 return Value > 0 && Value <= 16;
694 }
695 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000696 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
698 if (!CE) return false;
699 int64_t Value = CE->getValue();
700 return Value > 0 && Value <= 32;
701 }
702 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000703 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
705 if (!CE) return false;
706 int64_t Value = CE->getValue();
707 return Value > 0 && Value <= 64;
708 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000709 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000710 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
712 if (!CE) return false;
713 int64_t Value = CE->getValue();
714 return Value > 0 && Value < 8;
715 }
716 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000717 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000718 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
719 if (!CE) return false;
720 int64_t Value = CE->getValue();
721 return Value > 0 && Value < 16;
722 }
723 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000724 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
726 if (!CE) return false;
727 int64_t Value = CE->getValue();
728 return Value > 0 && Value < 32;
729 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000730 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000731 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
733 if (!CE) return false;
734 int64_t Value = CE->getValue();
735 return Value > 0 && Value < 17;
736 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000737 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000738 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
740 if (!CE) return false;
741 int64_t Value = CE->getValue();
742 return Value > 0 && Value < 33;
743 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000744 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000745 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
747 if (!CE) return false;
748 int64_t Value = CE->getValue();
749 return Value >= 0 && Value < 33;
750 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000751 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000752 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
754 if (!CE) return false;
755 int64_t Value = CE->getValue();
756 return Value >= 0 && Value < 65536;
757 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000758 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000759 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
761 // If it's not a constant expression, it'll generate a fixup and be
762 // handled later.
763 if (!CE) return true;
764 int64_t Value = CE->getValue();
765 return Value >= 0 && Value < 65536;
766 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000767 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000768 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
770 if (!CE) return false;
771 int64_t Value = CE->getValue();
772 return Value >= 0 && Value <= 0xffffff;
773 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000774 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000775 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
777 if (!CE) return false;
778 int64_t Value = CE->getValue();
779 return Value > 0 && Value < 33;
780 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000781 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000782 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
784 if (!CE) return false;
785 int64_t Value = CE->getValue();
786 return Value >= 0 && Value < 32;
787 }
788 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000789 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
791 if (!CE) return false;
792 int64_t Value = CE->getValue();
793 return Value > 0 && Value <= 32;
794 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000795 bool isAdrLabel() const {
796 // If we have an immediate that's not a constant, treat it as a label
797 // reference needing a fixup. If it is a constant, but it can't fit
798 // into shift immediate encoding, we reject it.
799 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
800 else return (isARMSOImm() || isARMSOImmNeg());
801 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000802 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000803 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
805 if (!CE) return false;
806 int64_t Value = CE->getValue();
807 return ARM_AM::getSOImmVal(Value) != -1;
808 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000809 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000810 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
812 if (!CE) return false;
813 int64_t Value = CE->getValue();
814 return ARM_AM::getSOImmVal(~Value) != -1;
815 }
Jim Grosbach30506252011-12-08 00:31:07 +0000816 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000817 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
819 if (!CE) return false;
820 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000821 // Only use this when not representable as a plain so_imm.
822 return ARM_AM::getSOImmVal(Value) == -1 &&
823 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000824 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000825 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000826 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
828 if (!CE) return false;
829 int64_t Value = CE->getValue();
830 return ARM_AM::getT2SOImmVal(Value) != -1;
831 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000832 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000833 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
835 if (!CE) return false;
836 int64_t Value = CE->getValue();
837 return ARM_AM::getT2SOImmVal(~Value) != -1;
838 }
Jim Grosbach30506252011-12-08 00:31:07 +0000839 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000840 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000844 // Only use this when not representable as a plain so_imm.
845 return ARM_AM::getT2SOImmVal(Value) == -1 &&
846 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000847 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000848 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000849 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
851 if (!CE) return false;
852 int64_t Value = CE->getValue();
853 return Value == 1 || Value == 0;
854 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000855 bool isReg() const { return Kind == k_Register; }
856 bool isRegList() const { return Kind == k_RegisterList; }
857 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
858 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
859 bool isToken() const { return Kind == k_Token; }
860 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000861 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000862 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
863 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
864 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
865 bool isRotImm() const { return Kind == k_RotateImmediate; }
866 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
867 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000868 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000869 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000870 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000871 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000872 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000873 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000874 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000875 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
876 (alignOK || Memory.Alignment == 0);
877 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000878 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000879 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000880 return false;
881 // Base register must be PC.
882 if (Memory.BaseRegNum != ARM::PC)
883 return false;
884 // Immediate offset in range [-4095, 4095].
885 if (!Memory.OffsetImm) return true;
886 int64_t Val = Memory.OffsetImm->getValue();
887 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
888 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000889 bool isAlignedMemory() const {
890 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000891 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000892 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000893 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000894 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000895 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000896 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000897 if (!Memory.OffsetImm) return true;
898 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000899 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000900 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000901 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000902 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000903 // Immediate offset in range [-4095, 4095].
904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
905 if (!CE) return false;
906 int64_t Val = CE->getValue();
907 return Val > -4096 && Val < 4096;
908 }
Jim Grosbach5b96b802011-08-10 20:29:19 +0000909 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +0000910 // If we have an immediate that's not a constant, treat it as a label
911 // reference needing a fixup. If it is a constant, it's something else
912 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000913 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +0000914 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000915 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000916 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +0000917 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000918 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000919 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000920 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +0000921 if (!Memory.OffsetImm) return true;
922 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +0000923 // The #-0 offset is encoded as INT32_MIN, and we have to check
924 // for this too.
925 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000926 }
927 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000928 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000929 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000930 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +0000931 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
932 // Immediate offset in range [-255, 255].
933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
934 if (!CE) return false;
935 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000936 // Special case, #-0 is INT32_MIN.
937 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +0000938 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000939 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000940 // If we have an immediate that's not a constant, treat it as a label
941 // reference needing a fixup. If it is a constant, it's something else
942 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000943 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000944 return true;
Chad Rosier41099832012-09-11 23:02:35 +0000945 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000946 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000947 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000948 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +0000949 if (!Memory.OffsetImm) return true;
950 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +0000951 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +0000952 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +0000953 }
Jim Grosbach05541f42011-09-19 22:21:13 +0000954 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +0000955 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000956 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +0000957 return false;
958 return true;
959 }
960 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +0000961 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000962 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
963 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +0000964 return false;
965 return true;
966 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000967 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +0000968 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +0000969 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +0000970 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000971 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000972 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +0000973 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000974 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000975 return false;
976 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +0000977 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000978 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +0000979 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +0000980 return false;
981 return true;
982 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000983 bool isMemThumbRR() const {
984 // Thumb reg+reg addressing is simple. Just two registers, a base and
985 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +0000986 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000987 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +0000988 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +0000989 return isARMLowRegister(Memory.BaseRegNum) &&
990 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000991 }
992 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +0000993 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +0000994 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000995 return false;
996 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +0000997 if (!Memory.OffsetImm) return true;
998 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +0000999 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1000 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001001 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001002 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001003 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001004 return false;
1005 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001006 if (!Memory.OffsetImm) return true;
1007 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001008 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1009 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001010 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001011 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001012 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001013 return false;
1014 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001015 if (!Memory.OffsetImm) return true;
1016 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001017 return Val >= 0 && Val <= 31;
1018 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001019 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001020 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001021 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001022 return false;
1023 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001024 if (!Memory.OffsetImm) return true;
1025 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001026 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001027 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001028 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001029 // If we have an immediate that's not a constant, treat it as a label
1030 // reference needing a fixup. If it is a constant, it's something else
1031 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001032 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001033 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001034 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001035 return false;
1036 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001037 if (!Memory.OffsetImm) return true;
1038 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001039 // Special case, #-0 is INT32_MIN.
1040 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001041 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001042 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001043 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001044 return false;
1045 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001046 if (!Memory.OffsetImm) return true;
1047 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001048 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1049 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001050 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001051 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001052 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001053 // Base reg of PC isn't allowed for these encodings.
1054 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001055 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001056 if (!Memory.OffsetImm) return true;
1057 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001058 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001059 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001060 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001061 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001062 return false;
1063 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001064 if (!Memory.OffsetImm) return true;
1065 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001066 return Val >= 0 && Val < 256;
1067 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001068 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001069 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001070 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001071 // Base reg of PC isn't allowed for these encodings.
1072 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001073 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001074 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001075 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001076 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001077 }
1078 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001079 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001080 return false;
1081 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001082 if (!Memory.OffsetImm) return true;
1083 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001084 return (Val >= 0 && Val < 4096);
1085 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001086 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001087 // If we have an immediate that's not a constant, treat it as a label
1088 // reference needing a fixup. If it is a constant, it's something else
1089 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001090 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001091 return true;
1092
Chad Rosier41099832012-09-11 23:02:35 +00001093 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001094 return false;
1095 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001096 if (!Memory.OffsetImm) return true;
1097 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001098 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001099 }
1100 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001101 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001102 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1103 if (!CE) return false;
1104 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001105 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001106 }
Jim Grosbach93981412011-10-11 21:55:36 +00001107 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001108 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001109 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1110 if (!CE) return false;
1111 int64_t Val = CE->getValue();
1112 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1113 (Val == INT32_MIN);
1114 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001115
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001116 bool isMSRMask() const { return Kind == k_MSRMask; }
1117 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001118
Jim Grosbach741cd732011-10-17 22:26:03 +00001119 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001120 bool isSingleSpacedVectorList() const {
1121 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1122 }
1123 bool isDoubleSpacedVectorList() const {
1124 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1125 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001126 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001127 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001128 return VectorList.Count == 1;
1129 }
1130
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001131 bool isVecListDPair() const {
1132 if (!isSingleSpacedVectorList()) return false;
1133 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1134 .contains(VectorList.RegNum));
1135 }
1136
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001137 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001138 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001139 return VectorList.Count == 3;
1140 }
1141
Jim Grosbach846bcff2011-10-21 20:35:01 +00001142 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001143 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001144 return VectorList.Count == 4;
1145 }
1146
Jim Grosbache5307f92012-03-05 21:43:40 +00001147 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001148 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001149 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1150 .contains(VectorList.RegNum));
1151 }
1152
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001153 bool isVecListThreeQ() const {
1154 if (!isDoubleSpacedVectorList()) return false;
1155 return VectorList.Count == 3;
1156 }
1157
Jim Grosbach1e946a42012-01-24 00:43:12 +00001158 bool isVecListFourQ() const {
1159 if (!isDoubleSpacedVectorList()) return false;
1160 return VectorList.Count == 4;
1161 }
1162
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001163 bool isSingleSpacedVectorAllLanes() const {
1164 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1165 }
1166 bool isDoubleSpacedVectorAllLanes() const {
1167 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1168 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001169 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001170 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001171 return VectorList.Count == 1;
1172 }
1173
Jim Grosbach13a292c2012-03-06 22:01:44 +00001174 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001175 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001176 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1177 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001178 }
1179
Jim Grosbached428bc2012-03-06 23:10:38 +00001180 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001181 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001182 return VectorList.Count == 2;
1183 }
1184
Jim Grosbachb78403c2012-01-24 23:47:04 +00001185 bool isVecListThreeDAllLanes() const {
1186 if (!isSingleSpacedVectorAllLanes()) return false;
1187 return VectorList.Count == 3;
1188 }
1189
1190 bool isVecListThreeQAllLanes() const {
1191 if (!isDoubleSpacedVectorAllLanes()) return false;
1192 return VectorList.Count == 3;
1193 }
1194
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001195 bool isVecListFourDAllLanes() const {
1196 if (!isSingleSpacedVectorAllLanes()) return false;
1197 return VectorList.Count == 4;
1198 }
1199
1200 bool isVecListFourQAllLanes() const {
1201 if (!isDoubleSpacedVectorAllLanes()) return false;
1202 return VectorList.Count == 4;
1203 }
1204
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001205 bool isSingleSpacedVectorIndexed() const {
1206 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1207 }
1208 bool isDoubleSpacedVectorIndexed() const {
1209 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1210 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001211 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001212 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001213 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1214 }
1215
Jim Grosbachda511042011-12-14 23:35:06 +00001216 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001217 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001218 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1219 }
1220
1221 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001222 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001223 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1224 }
1225
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001226 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001227 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001228 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1229 }
1230
Jim Grosbachda511042011-12-14 23:35:06 +00001231 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001232 if (!isSingleSpacedVectorIndexed()) return false;
1233 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1234 }
1235
1236 bool isVecListTwoQWordIndexed() const {
1237 if (!isDoubleSpacedVectorIndexed()) return false;
1238 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1239 }
1240
1241 bool isVecListTwoQHWordIndexed() const {
1242 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001243 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1244 }
1245
1246 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001247 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001248 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1249 }
1250
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001251 bool isVecListThreeDByteIndexed() const {
1252 if (!isSingleSpacedVectorIndexed()) return false;
1253 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1254 }
1255
1256 bool isVecListThreeDHWordIndexed() const {
1257 if (!isSingleSpacedVectorIndexed()) return false;
1258 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1259 }
1260
1261 bool isVecListThreeQWordIndexed() const {
1262 if (!isDoubleSpacedVectorIndexed()) return false;
1263 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1264 }
1265
1266 bool isVecListThreeQHWordIndexed() const {
1267 if (!isDoubleSpacedVectorIndexed()) return false;
1268 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1269 }
1270
1271 bool isVecListThreeDWordIndexed() const {
1272 if (!isSingleSpacedVectorIndexed()) return false;
1273 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1274 }
1275
Jim Grosbach14952a02012-01-24 18:37:25 +00001276 bool isVecListFourDByteIndexed() const {
1277 if (!isSingleSpacedVectorIndexed()) return false;
1278 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1279 }
1280
1281 bool isVecListFourDHWordIndexed() const {
1282 if (!isSingleSpacedVectorIndexed()) return false;
1283 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1284 }
1285
1286 bool isVecListFourQWordIndexed() const {
1287 if (!isDoubleSpacedVectorIndexed()) return false;
1288 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1289 }
1290
1291 bool isVecListFourQHWordIndexed() const {
1292 if (!isDoubleSpacedVectorIndexed()) return false;
1293 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1294 }
1295
1296 bool isVecListFourDWordIndexed() const {
1297 if (!isSingleSpacedVectorIndexed()) return false;
1298 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1299 }
1300
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001301 bool isVectorIndex8() const {
1302 if (Kind != k_VectorIndex) return false;
1303 return VectorIndex.Val < 8;
1304 }
1305 bool isVectorIndex16() const {
1306 if (Kind != k_VectorIndex) return false;
1307 return VectorIndex.Val < 4;
1308 }
1309 bool isVectorIndex32() const {
1310 if (Kind != k_VectorIndex) return false;
1311 return VectorIndex.Val < 2;
1312 }
1313
Jim Grosbach741cd732011-10-17 22:26:03 +00001314 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001315 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001316 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1317 // Must be a constant.
1318 if (!CE) return false;
1319 int64_t Value = CE->getValue();
1320 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1321 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001322 return Value >= 0 && Value < 256;
1323 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001324
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001325 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001326 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001327 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1328 // Must be a constant.
1329 if (!CE) return false;
1330 int64_t Value = CE->getValue();
1331 // i16 value in the range [0,255] or [0x0100, 0xff00]
1332 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1333 }
1334
Jim Grosbach8211c052011-10-18 00:22:00 +00001335 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001336 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001337 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1338 // Must be a constant.
1339 if (!CE) return false;
1340 int64_t Value = CE->getValue();
1341 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1342 return (Value >= 0 && Value < 256) ||
1343 (Value >= 0x0100 && Value <= 0xff00) ||
1344 (Value >= 0x010000 && Value <= 0xff0000) ||
1345 (Value >= 0x01000000 && Value <= 0xff000000);
1346 }
1347
1348 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001349 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001350 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1351 // Must be a constant.
1352 if (!CE) return false;
1353 int64_t Value = CE->getValue();
1354 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1355 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1356 return (Value >= 0 && Value < 256) ||
1357 (Value >= 0x0100 && Value <= 0xff00) ||
1358 (Value >= 0x010000 && Value <= 0xff0000) ||
1359 (Value >= 0x01000000 && Value <= 0xff000000) ||
1360 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1361 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1362 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001363 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001364 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001365 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1366 // Must be a constant.
1367 if (!CE) return false;
1368 int64_t Value = ~CE->getValue();
1369 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1370 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1371 return (Value >= 0 && Value < 256) ||
1372 (Value >= 0x0100 && Value <= 0xff00) ||
1373 (Value >= 0x010000 && Value <= 0xff0000) ||
1374 (Value >= 0x01000000 && Value <= 0xff000000) ||
1375 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1376 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1377 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001378
Jim Grosbache4454e02011-10-18 16:18:11 +00001379 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001380 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001381 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1382 // Must be a constant.
1383 if (!CE) return false;
1384 uint64_t Value = CE->getValue();
1385 // i64 value with each byte being either 0 or 0xff.
1386 for (unsigned i = 0; i < 8; ++i)
1387 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1388 return true;
1389 }
1390
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001391 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001392 // Add as immediates when possible. Null MCExpr = 0.
1393 if (Expr == 0)
1394 Inst.addOperand(MCOperand::CreateImm(0));
1395 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001396 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1397 else
1398 Inst.addOperand(MCOperand::CreateExpr(Expr));
1399 }
1400
Daniel Dunbard8042b72010-08-11 06:36:53 +00001401 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001402 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001403 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001404 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1405 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001406 }
1407
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001408 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1409 assert(N == 1 && "Invalid number of operands!");
1410 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1411 }
1412
Jim Grosbach48399582011-10-12 17:34:41 +00001413 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1414 assert(N == 1 && "Invalid number of operands!");
1415 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1416 }
1417
1418 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1419 assert(N == 1 && "Invalid number of operands!");
1420 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1421 }
1422
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001423 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1424 assert(N == 1 && "Invalid number of operands!");
1425 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1426 }
1427
1428 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1429 assert(N == 1 && "Invalid number of operands!");
1430 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1431 }
1432
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001433 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1434 assert(N == 1 && "Invalid number of operands!");
1435 Inst.addOperand(MCOperand::CreateReg(getReg()));
1436 }
1437
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001438 void addRegOperands(MCInst &Inst, unsigned N) const {
1439 assert(N == 1 && "Invalid number of operands!");
1440 Inst.addOperand(MCOperand::CreateReg(getReg()));
1441 }
1442
Jim Grosbachac798e12011-07-25 20:49:51 +00001443 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001444 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001445 assert(isRegShiftedReg() &&
1446 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001447 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1448 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001449 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001450 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001451 }
1452
Jim Grosbachac798e12011-07-25 20:49:51 +00001453 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001454 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001455 assert(isRegShiftedImm() &&
1456 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001457 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001458 // Shift of #32 is encoded as 0 where permitted
1459 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001460 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001461 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001462 }
1463
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001464 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001465 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001466 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1467 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001468 }
1469
Bill Wendling8d2aa032010-11-08 23:49:57 +00001470 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001471 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001472 const SmallVectorImpl<unsigned> &RegList = getRegList();
1473 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001474 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1475 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001476 }
1477
Bill Wendling9898ac92010-11-17 04:32:08 +00001478 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1479 addRegListOperands(Inst, N);
1480 }
1481
1482 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1483 addRegListOperands(Inst, N);
1484 }
1485
Jim Grosbach833b9d32011-07-27 20:15:40 +00001486 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1487 assert(N == 1 && "Invalid number of operands!");
1488 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1489 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1490 }
1491
Jim Grosbach864b6092011-07-28 21:34:26 +00001492 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1493 assert(N == 1 && "Invalid number of operands!");
1494 // Munge the lsb/width into a bitfield mask.
1495 unsigned lsb = Bitfield.LSB;
1496 unsigned width = Bitfield.Width;
1497 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1498 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1499 (32 - (lsb + width)));
1500 Inst.addOperand(MCOperand::CreateImm(Mask));
1501 }
1502
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001503 void addImmOperands(MCInst &Inst, unsigned N) const {
1504 assert(N == 1 && "Invalid number of operands!");
1505 addExpr(Inst, getImm());
1506 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001507
Jim Grosbachea231912011-12-22 22:19:05 +00001508 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1509 assert(N == 1 && "Invalid number of operands!");
1510 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1511 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1512 }
1513
1514 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1515 assert(N == 1 && "Invalid number of operands!");
1516 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1517 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1518 }
1519
Jim Grosbache7fbce72011-10-03 23:38:36 +00001520 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1521 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001522 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1523 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1524 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001525 }
1526
Jim Grosbach7db8d692011-09-08 22:07:06 +00001527 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1528 assert(N == 1 && "Invalid number of operands!");
1529 // FIXME: We really want to scale the value here, but the LDRD/STRD
1530 // instruction don't encode operands that way yet.
1531 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1532 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1533 }
1534
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001535 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1536 assert(N == 1 && "Invalid number of operands!");
1537 // The immediate is scaled by four in the encoding and is stored
1538 // in the MCInst as such. Lop off the low two bits here.
1539 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1540 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1541 }
1542
Jim Grosbach930f2f62012-04-05 20:57:13 +00001543 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1544 assert(N == 1 && "Invalid number of operands!");
1545 // The immediate is scaled by four in the encoding and is stored
1546 // in the MCInst as such. Lop off the low two bits here.
1547 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1548 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1549 }
1550
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001551 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1552 assert(N == 1 && "Invalid number of operands!");
1553 // The immediate is scaled by four in the encoding and is stored
1554 // in the MCInst as such. Lop off the low two bits here.
1555 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1556 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1557 }
1558
Jim Grosbach475c6db2011-07-25 23:09:14 +00001559 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1560 assert(N == 1 && "Invalid number of operands!");
1561 // The constant encodes as the immediate-1, and we store in the instruction
1562 // the bits as encoded, so subtract off one here.
1563 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1564 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1565 }
1566
Jim Grosbach801e0a32011-07-22 23:16:18 +00001567 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1568 assert(N == 1 && "Invalid number of operands!");
1569 // The constant encodes as the immediate-1, and we store in the instruction
1570 // the bits as encoded, so subtract off one here.
1571 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1572 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1573 }
1574
Jim Grosbach46dd4132011-08-17 21:51:27 +00001575 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1576 assert(N == 1 && "Invalid number of operands!");
1577 // The constant encodes as the immediate, except for 32, which encodes as
1578 // zero.
1579 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1580 unsigned Imm = CE->getValue();
1581 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1582 }
1583
Jim Grosbach27c1e252011-07-21 17:23:04 +00001584 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1585 assert(N == 1 && "Invalid number of operands!");
1586 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1587 // the instruction as well.
1588 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1589 int Val = CE->getValue();
1590 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1591 }
1592
Jim Grosbachb009a872011-10-28 22:36:30 +00001593 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1594 assert(N == 1 && "Invalid number of operands!");
1595 // The operand is actually a t2_so_imm, but we have its bitwise
1596 // negation in the assembly source, so twiddle it here.
1597 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1598 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1599 }
1600
Jim Grosbach30506252011-12-08 00:31:07 +00001601 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1602 assert(N == 1 && "Invalid number of operands!");
1603 // The operand is actually a t2_so_imm, but we have its
1604 // negation in the assembly source, so twiddle it here.
1605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1606 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1607 }
1608
Jim Grosbach930f2f62012-04-05 20:57:13 +00001609 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1610 assert(N == 1 && "Invalid number of operands!");
1611 // The operand is actually an imm0_4095, but we have its
1612 // negation in the assembly source, so twiddle it here.
1613 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1614 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1615 }
1616
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001617 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1618 assert(N == 1 && "Invalid number of operands!");
1619 // The operand is actually a so_imm, but we have its bitwise
1620 // negation in the assembly source, so twiddle it here.
1621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1622 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1623 }
1624
Jim Grosbach30506252011-12-08 00:31:07 +00001625 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1626 assert(N == 1 && "Invalid number of operands!");
1627 // The operand is actually a so_imm, but we have its
1628 // negation in the assembly source, so twiddle it here.
1629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1630 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1631 }
1632
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001633 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1634 assert(N == 1 && "Invalid number of operands!");
1635 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1636 }
1637
Jim Grosbachd3595712011-08-03 23:50:40 +00001638 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1639 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001640 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001641 }
1642
Jim Grosbach94298a92012-01-18 22:46:46 +00001643 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1644 assert(N == 1 && "Invalid number of operands!");
1645 int32_t Imm = Memory.OffsetImm->getValue();
1646 // FIXME: Handle #-0
1647 if (Imm == INT32_MIN) Imm = 0;
1648 Inst.addOperand(MCOperand::CreateImm(Imm));
1649 }
1650
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001651 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1652 assert(N == 1 && "Invalid number of operands!");
1653 assert(isImm() && "Not an immediate!");
1654
1655 // If we have an immediate that's not a constant, treat it as a label
1656 // reference needing a fixup.
1657 if (!isa<MCConstantExpr>(getImm())) {
1658 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1659 return;
1660 }
1661
1662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 int Val = CE->getValue();
1664 Inst.addOperand(MCOperand::CreateImm(Val));
1665 }
1666
Jim Grosbacha95ec992011-10-11 17:29:55 +00001667 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1668 assert(N == 2 && "Invalid number of operands!");
1669 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1670 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1671 }
1672
Jim Grosbachd3595712011-08-03 23:50:40 +00001673 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1674 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001675 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1676 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001677 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1678 // Special case for #-0
1679 if (Val == INT32_MIN) Val = 0;
1680 if (Val < 0) Val = -Val;
1681 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1682 } else {
1683 // For register offset, we encode the shift type and negation flag
1684 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001685 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1686 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001687 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001688 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1689 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001690 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001691 }
1692
Jim Grosbachcd17c122011-08-04 23:01:30 +00001693 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1694 assert(N == 2 && "Invalid number of operands!");
1695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1696 assert(CE && "non-constant AM2OffsetImm operand!");
1697 int32_t Val = CE->getValue();
1698 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1699 // Special case for #-0
1700 if (Val == INT32_MIN) Val = 0;
1701 if (Val < 0) Val = -Val;
1702 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1703 Inst.addOperand(MCOperand::CreateReg(0));
1704 Inst.addOperand(MCOperand::CreateImm(Val));
1705 }
1706
Jim Grosbach5b96b802011-08-10 20:29:19 +00001707 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1708 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001709 // If we have an immediate that's not a constant, treat it as a label
1710 // reference needing a fixup. If it is a constant, it's something else
1711 // and we reject it.
1712 if (isImm()) {
1713 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1714 Inst.addOperand(MCOperand::CreateReg(0));
1715 Inst.addOperand(MCOperand::CreateImm(0));
1716 return;
1717 }
1718
Jim Grosbach871dff72011-10-11 15:59:20 +00001719 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1720 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001721 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1722 // Special case for #-0
1723 if (Val == INT32_MIN) Val = 0;
1724 if (Val < 0) Val = -Val;
1725 Val = ARM_AM::getAM3Opc(AddSub, Val);
1726 } else {
1727 // For register offset, we encode the shift type and negation flag
1728 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001729 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001730 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001731 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1732 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001733 Inst.addOperand(MCOperand::CreateImm(Val));
1734 }
1735
1736 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1737 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001738 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001739 int32_t Val =
1740 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1741 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1742 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001743 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001744 }
1745
1746 // Constant offset.
1747 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1748 int32_t Val = CE->getValue();
1749 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1750 // Special case for #-0
1751 if (Val == INT32_MIN) Val = 0;
1752 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001753 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001754 Inst.addOperand(MCOperand::CreateReg(0));
1755 Inst.addOperand(MCOperand::CreateImm(Val));
1756 }
1757
Jim Grosbachd3595712011-08-03 23:50:40 +00001758 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1759 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001760 // If we have an immediate that's not a constant, treat it as a label
1761 // reference needing a fixup. If it is a constant, it's something else
1762 // and we reject it.
1763 if (isImm()) {
1764 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1765 Inst.addOperand(MCOperand::CreateImm(0));
1766 return;
1767 }
1768
Jim Grosbachd3595712011-08-03 23:50:40 +00001769 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001770 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001771 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1772 // Special case for #-0
1773 if (Val == INT32_MIN) Val = 0;
1774 if (Val < 0) Val = -Val;
1775 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001776 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001777 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001778 }
1779
Jim Grosbach7db8d692011-09-08 22:07:06 +00001780 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1781 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001782 // If we have an immediate that's not a constant, treat it as a label
1783 // reference needing a fixup. If it is a constant, it's something else
1784 // and we reject it.
1785 if (isImm()) {
1786 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1787 Inst.addOperand(MCOperand::CreateImm(0));
1788 return;
1789 }
1790
Jim Grosbach871dff72011-10-11 15:59:20 +00001791 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1792 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001793 Inst.addOperand(MCOperand::CreateImm(Val));
1794 }
1795
Jim Grosbacha05627e2011-09-09 18:37:27 +00001796 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1797 assert(N == 2 && "Invalid number of operands!");
1798 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001799 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1800 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001801 Inst.addOperand(MCOperand::CreateImm(Val));
1802 }
1803
Jim Grosbachd3595712011-08-03 23:50:40 +00001804 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1805 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001806 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1807 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001808 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001809 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001810
Jim Grosbach2392c532011-09-07 23:39:14 +00001811 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1812 addMemImm8OffsetOperands(Inst, N);
1813 }
1814
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001815 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001816 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001817 }
1818
1819 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1820 assert(N == 2 && "Invalid number of operands!");
1821 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001822 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001823 addExpr(Inst, getImm());
1824 Inst.addOperand(MCOperand::CreateImm(0));
1825 return;
1826 }
1827
1828 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001829 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1830 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001831 Inst.addOperand(MCOperand::CreateImm(Val));
1832 }
1833
Jim Grosbachd3595712011-08-03 23:50:40 +00001834 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1835 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001836 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001837 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001838 addExpr(Inst, getImm());
1839 Inst.addOperand(MCOperand::CreateImm(0));
1840 return;
1841 }
1842
1843 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001844 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1845 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001846 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001847 }
Bill Wendling811c9362010-11-30 07:44:32 +00001848
Jim Grosbach05541f42011-09-19 22:21:13 +00001849 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1850 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001851 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1852 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001853 }
1854
1855 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1856 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001857 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1858 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001859 }
1860
Jim Grosbachd3595712011-08-03 23:50:40 +00001861 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1862 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001863 unsigned Val =
1864 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1865 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001866 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1867 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001868 Inst.addOperand(MCOperand::CreateImm(Val));
1869 }
1870
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001871 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1872 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001873 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1874 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1875 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001876 }
1877
Jim Grosbachd3595712011-08-03 23:50:40 +00001878 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1879 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001880 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1881 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001882 }
1883
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001884 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1885 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001886 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1887 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001888 Inst.addOperand(MCOperand::CreateImm(Val));
1889 }
1890
Jim Grosbach26d35872011-08-19 18:55:51 +00001891 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1892 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001893 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1894 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00001895 Inst.addOperand(MCOperand::CreateImm(Val));
1896 }
1897
Jim Grosbacha32c7532011-08-19 18:49:59 +00001898 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1899 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001900 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1901 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00001902 Inst.addOperand(MCOperand::CreateImm(Val));
1903 }
1904
Jim Grosbach23983d62011-08-19 18:13:48 +00001905 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1906 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001907 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1908 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00001909 Inst.addOperand(MCOperand::CreateImm(Val));
1910 }
1911
Jim Grosbachd3595712011-08-03 23:50:40 +00001912 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1913 assert(N == 1 && "Invalid number of operands!");
1914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1915 assert(CE && "non-constant post-idx-imm8 operand!");
1916 int Imm = CE->getValue();
1917 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00001918 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001919 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1920 Inst.addOperand(MCOperand::CreateImm(Imm));
1921 }
1922
Jim Grosbach93981412011-10-11 21:55:36 +00001923 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1924 assert(N == 1 && "Invalid number of operands!");
1925 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1926 assert(CE && "non-constant post-idx-imm8s4 operand!");
1927 int Imm = CE->getValue();
1928 bool isAdd = Imm >= 0;
1929 if (Imm == INT32_MIN) Imm = 0;
1930 // Immediate is scaled by 4.
1931 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1932 Inst.addOperand(MCOperand::CreateImm(Imm));
1933 }
1934
Jim Grosbachd3595712011-08-03 23:50:40 +00001935 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1936 assert(N == 2 && "Invalid number of operands!");
1937 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00001938 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1939 }
1940
1941 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1942 assert(N == 2 && "Invalid number of operands!");
1943 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1944 // The sign, shift type, and shift amount are encoded in a single operand
1945 // using the AM2 encoding helpers.
1946 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1947 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1948 PostIdxReg.ShiftTy);
1949 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00001950 }
1951
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00001952 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1953 assert(N == 1 && "Invalid number of operands!");
1954 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1955 }
1956
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00001957 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1958 assert(N == 1 && "Invalid number of operands!");
1959 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1960 }
1961
Jim Grosbach182b6a02011-11-29 23:51:09 +00001962 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001963 assert(N == 1 && "Invalid number of operands!");
1964 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1965 }
1966
Jim Grosbach04945c42011-12-02 00:35:16 +00001967 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1968 assert(N == 2 && "Invalid number of operands!");
1969 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1970 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1971 }
1972
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001973 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1974 assert(N == 1 && "Invalid number of operands!");
1975 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1976 }
1977
1978 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1979 assert(N == 1 && "Invalid number of operands!");
1980 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1981 }
1982
1983 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1984 assert(N == 1 && "Invalid number of operands!");
1985 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1986 }
1987
Jim Grosbach741cd732011-10-17 22:26:03 +00001988 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1989 assert(N == 1 && "Invalid number of operands!");
1990 // The immediate encodes the type of constant as well as the value.
1991 // Mask in that this is an i8 splat.
1992 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1993 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1994 }
1995
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001996 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1997 assert(N == 1 && "Invalid number of operands!");
1998 // The immediate encodes the type of constant as well as the value.
1999 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2000 unsigned Value = CE->getValue();
2001 if (Value >= 256)
2002 Value = (Value >> 8) | 0xa00;
2003 else
2004 Value |= 0x800;
2005 Inst.addOperand(MCOperand::CreateImm(Value));
2006 }
2007
Jim Grosbach8211c052011-10-18 00:22:00 +00002008 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 1 && "Invalid number of operands!");
2010 // The immediate encodes the type of constant as well as the value.
2011 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2012 unsigned Value = CE->getValue();
2013 if (Value >= 256 && Value <= 0xff00)
2014 Value = (Value >> 8) | 0x200;
2015 else if (Value > 0xffff && Value <= 0xff0000)
2016 Value = (Value >> 16) | 0x400;
2017 else if (Value > 0xffffff)
2018 Value = (Value >> 24) | 0x600;
2019 Inst.addOperand(MCOperand::CreateImm(Value));
2020 }
2021
2022 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2023 assert(N == 1 && "Invalid number of operands!");
2024 // The immediate encodes the type of constant as well as the value.
2025 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2026 unsigned Value = CE->getValue();
2027 if (Value >= 256 && Value <= 0xffff)
2028 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2029 else if (Value > 0xffff && Value <= 0xffffff)
2030 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2031 else if (Value > 0xffffff)
2032 Value = (Value >> 24) | 0x600;
2033 Inst.addOperand(MCOperand::CreateImm(Value));
2034 }
2035
Jim Grosbach045b6c72011-12-19 23:51:07 +00002036 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2037 assert(N == 1 && "Invalid number of operands!");
2038 // The immediate encodes the type of constant as well as the value.
2039 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2040 unsigned Value = ~CE->getValue();
2041 if (Value >= 256 && Value <= 0xffff)
2042 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2043 else if (Value > 0xffff && Value <= 0xffffff)
2044 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2045 else if (Value > 0xffffff)
2046 Value = (Value >> 24) | 0x600;
2047 Inst.addOperand(MCOperand::CreateImm(Value));
2048 }
2049
Jim Grosbache4454e02011-10-18 16:18:11 +00002050 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2051 assert(N == 1 && "Invalid number of operands!");
2052 // The immediate encodes the type of constant as well as the value.
2053 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2054 uint64_t Value = CE->getValue();
2055 unsigned Imm = 0;
2056 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2057 Imm |= (Value & 1) << i;
2058 }
2059 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2060 }
2061
Jim Grosbach602aa902011-07-13 15:34:57 +00002062 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002063
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002064 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002065 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002066 Op->ITMask.Mask = Mask;
2067 Op->StartLoc = S;
2068 Op->EndLoc = S;
2069 return Op;
2070 }
2071
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002072 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002073 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002074 Op->CC.Val = CC;
2075 Op->StartLoc = S;
2076 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002077 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002078 }
2079
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002080 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002081 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002082 Op->Cop.Val = CopVal;
2083 Op->StartLoc = S;
2084 Op->EndLoc = S;
2085 return Op;
2086 }
2087
2088 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002089 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002090 Op->Cop.Val = CopVal;
2091 Op->StartLoc = S;
2092 Op->EndLoc = S;
2093 return Op;
2094 }
2095
Jim Grosbach48399582011-10-12 17:34:41 +00002096 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2097 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2098 Op->Cop.Val = Val;
2099 Op->StartLoc = S;
2100 Op->EndLoc = E;
2101 return Op;
2102 }
2103
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002104 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002105 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002106 Op->Reg.RegNum = RegNum;
2107 Op->StartLoc = S;
2108 Op->EndLoc = S;
2109 return Op;
2110 }
2111
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002112 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002113 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002114 Op->Tok.Data = Str.data();
2115 Op->Tok.Length = Str.size();
2116 Op->StartLoc = S;
2117 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002118 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002119 }
2120
Bill Wendling2063b842010-11-18 23:43:05 +00002121 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002122 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002123 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002124 Op->StartLoc = S;
2125 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002126 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002127 }
2128
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002129 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2130 unsigned SrcReg,
2131 unsigned ShiftReg,
2132 unsigned ShiftImm,
2133 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002134 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002135 Op->RegShiftedReg.ShiftTy = ShTy;
2136 Op->RegShiftedReg.SrcReg = SrcReg;
2137 Op->RegShiftedReg.ShiftReg = ShiftReg;
2138 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002139 Op->StartLoc = S;
2140 Op->EndLoc = E;
2141 return Op;
2142 }
2143
Owen Andersonb595ed02011-07-21 18:54:16 +00002144 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2145 unsigned SrcReg,
2146 unsigned ShiftImm,
2147 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002148 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002149 Op->RegShiftedImm.ShiftTy = ShTy;
2150 Op->RegShiftedImm.SrcReg = SrcReg;
2151 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002152 Op->StartLoc = S;
2153 Op->EndLoc = E;
2154 return Op;
2155 }
2156
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002157 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002158 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002159 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002160 Op->ShifterImm.isASR = isASR;
2161 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002162 Op->StartLoc = S;
2163 Op->EndLoc = E;
2164 return Op;
2165 }
2166
Jim Grosbach833b9d32011-07-27 20:15:40 +00002167 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002168 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002169 Op->RotImm.Imm = Imm;
2170 Op->StartLoc = S;
2171 Op->EndLoc = E;
2172 return Op;
2173 }
2174
Jim Grosbach864b6092011-07-28 21:34:26 +00002175 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2176 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002177 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002178 Op->Bitfield.LSB = LSB;
2179 Op->Bitfield.Width = Width;
2180 Op->StartLoc = S;
2181 Op->EndLoc = E;
2182 return Op;
2183 }
2184
Bill Wendling2cae3272010-11-09 22:44:22 +00002185 static ARMOperand *
Bill Wendlingbed94652010-11-09 23:28:44 +00002186 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002187 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002188 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002189
Jim Grosbach75461af2011-09-13 22:56:44 +00002190 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002191 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002192 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng9eec7642011-07-25 21:32:49 +00002193 contains(Regs.front().first))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002194 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002195
2196 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendlingbed94652010-11-09 23:28:44 +00002197 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002198 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling0ab0f672010-11-18 21:50:54 +00002199 Op->Registers.push_back(I->first);
Bill Wendling20b5ea982010-11-19 00:38:19 +00002200 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002201 Op->StartLoc = StartLoc;
2202 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002203 return Op;
2204 }
2205
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002206 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002207 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002208 ARMOperand *Op = new ARMOperand(k_VectorList);
2209 Op->VectorList.RegNum = RegNum;
2210 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002211 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002212 Op->StartLoc = S;
2213 Op->EndLoc = E;
2214 return Op;
2215 }
2216
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002217 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002218 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002219 SMLoc S, SMLoc E) {
2220 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2221 Op->VectorList.RegNum = RegNum;
2222 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002223 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002224 Op->StartLoc = S;
2225 Op->EndLoc = E;
2226 return Op;
2227 }
2228
Jim Grosbach04945c42011-12-02 00:35:16 +00002229 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002230 unsigned Index,
2231 bool isDoubleSpaced,
2232 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002233 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2234 Op->VectorList.RegNum = RegNum;
2235 Op->VectorList.Count = Count;
2236 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002237 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002238 Op->StartLoc = S;
2239 Op->EndLoc = E;
2240 return Op;
2241 }
2242
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002243 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2244 MCContext &Ctx) {
2245 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2246 Op->VectorIndex.Val = Idx;
2247 Op->StartLoc = S;
2248 Op->EndLoc = E;
2249 return Op;
2250 }
2251
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002252 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002253 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002254 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002255 Op->StartLoc = S;
2256 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002257 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002258 }
2259
Jim Grosbachd3595712011-08-03 23:50:40 +00002260 static ARMOperand *CreateMem(unsigned BaseRegNum,
2261 const MCConstantExpr *OffsetImm,
2262 unsigned OffsetRegNum,
2263 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002264 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002265 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002266 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002267 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002268 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002269 Op->Memory.BaseRegNum = BaseRegNum;
2270 Op->Memory.OffsetImm = OffsetImm;
2271 Op->Memory.OffsetRegNum = OffsetRegNum;
2272 Op->Memory.ShiftType = ShiftType;
2273 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002274 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002275 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002276 Op->StartLoc = S;
2277 Op->EndLoc = E;
2278 return Op;
2279 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002280
Jim Grosbachc320c852011-08-05 21:28:30 +00002281 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2282 ARM_AM::ShiftOpc ShiftTy,
2283 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002284 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002285 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002286 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002287 Op->PostIdxReg.isAdd = isAdd;
2288 Op->PostIdxReg.ShiftTy = ShiftTy;
2289 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002290 Op->StartLoc = S;
2291 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002292 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002293 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002294
2295 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002296 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002297 Op->MBOpt.Val = Opt;
2298 Op->StartLoc = S;
2299 Op->EndLoc = S;
2300 return Op;
2301 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002302
2303 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002304 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002305 Op->IFlags.Val = IFlags;
2306 Op->StartLoc = S;
2307 Op->EndLoc = S;
2308 return Op;
2309 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002310
2311 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002312 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002313 Op->MMask.Val = MMask;
2314 Op->StartLoc = S;
2315 Op->EndLoc = S;
2316 return Op;
2317 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002318};
2319
2320} // end anonymous namespace.
2321
Jim Grosbach602aa902011-07-13 15:34:57 +00002322void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002323 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002324 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002325 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002326 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002327 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002328 OS << "<ccout " << getReg() << ">";
2329 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002330 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002331 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002332 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2333 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2334 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002335 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2336 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2337 break;
2338 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002339 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002340 OS << "<coprocessor number: " << getCoproc() << ">";
2341 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002342 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002343 OS << "<coprocessor register: " << getCoproc() << ">";
2344 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002345 case k_CoprocOption:
2346 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2347 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002348 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002349 OS << "<mask: " << getMSRMask() << ">";
2350 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002351 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002352 getImm()->print(OS);
2353 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002354 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002355 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2356 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002357 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002358 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002359 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002360 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002361 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002362 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002363 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2364 << PostIdxReg.RegNum;
2365 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2366 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2367 << PostIdxReg.ShiftImm;
2368 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002369 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002370 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002371 OS << "<ARM_PROC::";
2372 unsigned IFlags = getProcIFlags();
2373 for (int i=2; i >= 0; --i)
2374 if (IFlags & (1 << i))
2375 OS << ARM_PROC::IFlagsToString(1 << i);
2376 OS << ">";
2377 break;
2378 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002379 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002380 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002381 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002382 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002383 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2384 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002385 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002386 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002387 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002388 << RegShiftedReg.SrcReg << " "
2389 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2390 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002391 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002392 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002393 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002394 << RegShiftedImm.SrcReg << " "
2395 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2396 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002397 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002398 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002399 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2400 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002401 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002402 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2403 << ", width: " << Bitfield.Width << ">";
2404 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002405 case k_RegisterList:
2406 case k_DPRRegisterList:
2407 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002408 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002409
Bill Wendlingbed94652010-11-09 23:28:44 +00002410 const SmallVectorImpl<unsigned> &RegList = getRegList();
2411 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002412 I = RegList.begin(), E = RegList.end(); I != E; ) {
2413 OS << *I;
2414 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002415 }
2416
2417 OS << ">";
2418 break;
2419 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002420 case k_VectorList:
2421 OS << "<vector_list " << VectorList.Count << " * "
2422 << VectorList.RegNum << ">";
2423 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002424 case k_VectorListAllLanes:
2425 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2426 << VectorList.RegNum << ">";
2427 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002428 case k_VectorListIndexed:
2429 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2430 << VectorList.Count << " * " << VectorList.RegNum << ">";
2431 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002432 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002433 OS << "'" << getToken() << "'";
2434 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002435 case k_VectorIndex:
2436 OS << "<vectorindex " << getVectorIndex() << ">";
2437 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002438 }
2439}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002440
2441/// @name Auto-generated Match Functions
2442/// {
2443
2444static unsigned MatchRegisterName(StringRef Name);
2445
2446/// }
2447
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002448bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2449 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002450 StartLoc = Parser.getTok().getLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002451 RegNo = tryParseRegister();
Jim Grosbachab5830e2011-12-14 02:16:11 +00002452 EndLoc = Parser.getTok().getLoc();
Roman Divacky36b1b472011-01-27 17:14:22 +00002453
2454 return (RegNo == (unsigned)-1);
2455}
2456
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002457/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002458/// and if it is a register name the token is eaten and the register number is
2459/// returned. Otherwise return -1.
2460///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002461int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002462 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002463 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002464
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002465 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002466 unsigned RegNum = MatchRegisterName(lowerCase);
2467 if (!RegNum) {
2468 RegNum = StringSwitch<unsigned>(lowerCase)
2469 .Case("r13", ARM::SP)
2470 .Case("r14", ARM::LR)
2471 .Case("r15", ARM::PC)
2472 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002473 // Additional register name aliases for 'gas' compatibility.
2474 .Case("a1", ARM::R0)
2475 .Case("a2", ARM::R1)
2476 .Case("a3", ARM::R2)
2477 .Case("a4", ARM::R3)
2478 .Case("v1", ARM::R4)
2479 .Case("v2", ARM::R5)
2480 .Case("v3", ARM::R6)
2481 .Case("v4", ARM::R7)
2482 .Case("v5", ARM::R8)
2483 .Case("v6", ARM::R9)
2484 .Case("v7", ARM::R10)
2485 .Case("v8", ARM::R11)
2486 .Case("sb", ARM::R9)
2487 .Case("sl", ARM::R10)
2488 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002489 .Default(0);
2490 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002491 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002492 // Check for aliases registered via .req. Canonicalize to lower case.
2493 // That's more consistent since register names are case insensitive, and
2494 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2495 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002496 // If no match, return failure.
2497 if (Entry == RegisterReqs.end())
2498 return -1;
2499 Parser.Lex(); // Eat identifier token.
2500 return Entry->getValue();
2501 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002502
Chris Lattner44e5981c2010-10-30 04:09:10 +00002503 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002504
Chris Lattner44e5981c2010-10-30 04:09:10 +00002505 return RegNum;
2506}
Jim Grosbach99710a82010-11-01 16:44:21 +00002507
Jim Grosbachbb24c592011-07-13 18:49:30 +00002508// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2509// If a recoverable error occurs, return 1. If an irrecoverable error
2510// occurs, return -1. An irrecoverable error is one where tokens have been
2511// consumed in the process of trying to parse the shifter (i.e., when it is
2512// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002513int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002514 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2515 SMLoc S = Parser.getTok().getLoc();
2516 const AsmToken &Tok = Parser.getTok();
2517 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2518
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002519 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002520 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002521 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002522 .Case("lsl", ARM_AM::lsl)
2523 .Case("lsr", ARM_AM::lsr)
2524 .Case("asr", ARM_AM::asr)
2525 .Case("ror", ARM_AM::ror)
2526 .Case("rrx", ARM_AM::rrx)
2527 .Default(ARM_AM::no_shift);
2528
2529 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002530 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002531
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002532 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002533
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002534 // The source register for the shift has already been added to the
2535 // operand list, so we need to pop it off and combine it into the shifted
2536 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002537 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002538 if (!PrevOp->isReg())
2539 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2540 int SrcReg = PrevOp->getReg();
2541 int64_t Imm = 0;
2542 int ShiftReg = 0;
2543 if (ShiftTy == ARM_AM::rrx) {
2544 // RRX Doesn't have an explicit shift amount. The encoder expects
2545 // the shift register to be the same as the source register. Seems odd,
2546 // but OK.
2547 ShiftReg = SrcReg;
2548 } else {
2549 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002550 if (Parser.getTok().is(AsmToken::Hash) ||
2551 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002552 Parser.Lex(); // Eat hash.
2553 SMLoc ImmLoc = Parser.getTok().getLoc();
2554 const MCExpr *ShiftExpr = 0;
Jim Grosbachbb24c592011-07-13 18:49:30 +00002555 if (getParser().ParseExpression(ShiftExpr)) {
2556 Error(ImmLoc, "invalid immediate shift value");
2557 return -1;
2558 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002559 // The expression must be evaluatable as an immediate.
2560 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002561 if (!CE) {
2562 Error(ImmLoc, "invalid immediate shift value");
2563 return -1;
2564 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002565 // Range check the immediate.
2566 // lsl, ror: 0 <= imm <= 31
2567 // lsr, asr: 0 <= imm <= 32
2568 Imm = CE->getValue();
2569 if (Imm < 0 ||
2570 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2571 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002572 Error(ImmLoc, "immediate shift value out of range");
2573 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002574 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002575 // shift by zero is a nop. Always send it through as lsl.
2576 // ('as' compatibility)
2577 if (Imm == 0)
2578 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002579 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002580 ShiftReg = tryParseRegister();
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002581 SMLoc L = Parser.getTok().getLoc();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002582 if (ShiftReg == -1) {
2583 Error (L, "expected immediate or register in shift operand");
2584 return -1;
2585 }
2586 } else {
2587 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002588 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002589 return -1;
2590 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002591 }
2592
Owen Andersonb595ed02011-07-21 18:54:16 +00002593 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2594 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002595 ShiftReg, Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002596 S, Parser.getTok().getLoc()));
Owen Andersonb595ed02011-07-21 18:54:16 +00002597 else
2598 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2599 S, Parser.getTok().getLoc()));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002600
Jim Grosbachbb24c592011-07-13 18:49:30 +00002601 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002602}
2603
2604
Bill Wendling2063b842010-11-18 23:43:05 +00002605/// Try to parse a register name. The token must be an Identifier when called.
2606/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2607/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002608///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002609/// TODO this is likely to change to allow different register types and or to
2610/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002611bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002612tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002613 SMLoc S = Parser.getTok().getLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002614 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002615 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002616 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002617
Bill Wendling2063b842010-11-18 23:43:05 +00002618 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002619
Chris Lattner44e5981c2010-10-30 04:09:10 +00002620 const AsmToken &ExclaimTok = Parser.getTok();
2621 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002622 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2623 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002624 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002625 return false;
2626 }
2627
2628 // Also check for an index operand. This is only legal for vector registers,
2629 // but that'll get caught OK in operand matching, so we don't need to
2630 // explicitly filter everything else out here.
2631 if (Parser.getTok().is(AsmToken::LBrac)) {
2632 SMLoc SIdx = Parser.getTok().getLoc();
2633 Parser.Lex(); // Eat left bracket token.
2634
2635 const MCExpr *ImmVal;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002636 if (getParser().ParseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002637 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002638 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002639 if (!MCE)
2640 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002641
2642 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002643 if (Parser.getTok().isNot(AsmToken::RBrac))
2644 return Error(E, "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002645
2646 Parser.Lex(); // Eat right bracket token.
2647
2648 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2649 SIdx, E,
2650 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002651 }
2652
Bill Wendling2063b842010-11-18 23:43:05 +00002653 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002654}
2655
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002656/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2657/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2658/// "c5", ...
2659static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002660 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2661 // but efficient.
2662 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002663 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002664 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002665 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002666 return -1;
2667 switch (Name[1]) {
2668 default: return -1;
2669 case '0': return 0;
2670 case '1': return 1;
2671 case '2': return 2;
2672 case '3': return 3;
2673 case '4': return 4;
2674 case '5': return 5;
2675 case '6': return 6;
2676 case '7': return 7;
2677 case '8': return 8;
2678 case '9': return 9;
2679 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002680 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002681 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002682 return -1;
2683 switch (Name[2]) {
2684 default: return -1;
2685 case '0': return 10;
2686 case '1': return 11;
2687 case '2': return 12;
2688 case '3': return 13;
2689 case '4': return 14;
2690 case '5': return 15;
2691 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002692 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002693}
2694
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002695/// parseITCondCode - Try to parse a condition code for an IT instruction.
2696ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2697parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2698 SMLoc S = Parser.getTok().getLoc();
2699 const AsmToken &Tok = Parser.getTok();
2700 if (!Tok.is(AsmToken::Identifier))
2701 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002702 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002703 .Case("eq", ARMCC::EQ)
2704 .Case("ne", ARMCC::NE)
2705 .Case("hs", ARMCC::HS)
2706 .Case("cs", ARMCC::HS)
2707 .Case("lo", ARMCC::LO)
2708 .Case("cc", ARMCC::LO)
2709 .Case("mi", ARMCC::MI)
2710 .Case("pl", ARMCC::PL)
2711 .Case("vs", ARMCC::VS)
2712 .Case("vc", ARMCC::VC)
2713 .Case("hi", ARMCC::HI)
2714 .Case("ls", ARMCC::LS)
2715 .Case("ge", ARMCC::GE)
2716 .Case("lt", ARMCC::LT)
2717 .Case("gt", ARMCC::GT)
2718 .Case("le", ARMCC::LE)
2719 .Case("al", ARMCC::AL)
2720 .Default(~0U);
2721 if (CC == ~0U)
2722 return MatchOperand_NoMatch;
2723 Parser.Lex(); // Eat the token.
2724
2725 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2726
2727 return MatchOperand_Success;
2728}
2729
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002730/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002731/// token must be an Identifier when called, and if it is a coprocessor
2732/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002733ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002734parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002735 SMLoc S = Parser.getTok().getLoc();
2736 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002737 if (Tok.isNot(AsmToken::Identifier))
2738 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002739
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002740 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002741 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002742 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002743
2744 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002745 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002746 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002747}
2748
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002749/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002750/// token must be an Identifier when called, and if it is a coprocessor
2751/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002752ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002753parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002754 SMLoc S = Parser.getTok().getLoc();
2755 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002756 if (Tok.isNot(AsmToken::Identifier))
2757 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002758
2759 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2760 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002761 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002762
2763 Parser.Lex(); // Eat identifier token.
2764 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002765 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002766}
2767
Jim Grosbach48399582011-10-12 17:34:41 +00002768/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2769/// coproc_option : '{' imm0_255 '}'
2770ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2771parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2772 SMLoc S = Parser.getTok().getLoc();
2773
2774 // If this isn't a '{', this isn't a coprocessor immediate operand.
2775 if (Parser.getTok().isNot(AsmToken::LCurly))
2776 return MatchOperand_NoMatch;
2777 Parser.Lex(); // Eat the '{'
2778
2779 const MCExpr *Expr;
2780 SMLoc Loc = Parser.getTok().getLoc();
2781 if (getParser().ParseExpression(Expr)) {
2782 Error(Loc, "illegal expression");
2783 return MatchOperand_ParseFail;
2784 }
2785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2786 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2787 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2788 return MatchOperand_ParseFail;
2789 }
2790 int Val = CE->getValue();
2791
2792 // Check for and consume the closing '}'
2793 if (Parser.getTok().isNot(AsmToken::RCurly))
2794 return MatchOperand_ParseFail;
2795 SMLoc E = Parser.getTok().getLoc();
2796 Parser.Lex(); // Eat the '}'
2797
2798 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2799 return MatchOperand_Success;
2800}
2801
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002802// For register list parsing, we need to map from raw GPR register numbering
2803// to the enumeration values. The enumeration values aren't sorted by
2804// register number due to our using "sp", "lr" and "pc" as canonical names.
2805static unsigned getNextRegister(unsigned Reg) {
2806 // If this is a GPR, we need to do it manually, otherwise we can rely
2807 // on the sort ordering of the enumeration since the other reg-classes
2808 // are sane.
2809 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2810 return Reg + 1;
2811 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002812 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002813 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2814 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2815 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2816 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2817 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2818 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2819 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2820 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2821 }
2822}
2823
Jim Grosbach85a23432011-11-11 21:27:40 +00002824// Return the low-subreg of a given Q register.
2825static unsigned getDRegFromQReg(unsigned QReg) {
2826 switch (QReg) {
2827 default: llvm_unreachable("expected a Q register!");
2828 case ARM::Q0: return ARM::D0;
2829 case ARM::Q1: return ARM::D2;
2830 case ARM::Q2: return ARM::D4;
2831 case ARM::Q3: return ARM::D6;
2832 case ARM::Q4: return ARM::D8;
2833 case ARM::Q5: return ARM::D10;
2834 case ARM::Q6: return ARM::D12;
2835 case ARM::Q7: return ARM::D14;
2836 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002837 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002838 case ARM::Q10: return ARM::D20;
2839 case ARM::Q11: return ARM::D22;
2840 case ARM::Q12: return ARM::D24;
2841 case ARM::Q13: return ARM::D26;
2842 case ARM::Q14: return ARM::D28;
2843 case ARM::Q15: return ARM::D30;
2844 }
2845}
2846
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002847/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002848bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002849parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002850 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00002851 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00002852 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002853 Parser.Lex(); // Eat '{' token.
2854 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00002855
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002856 // Check the first register in the list to see what register class
2857 // this is a list of.
2858 int Reg = tryParseRegister();
2859 if (Reg == -1)
2860 return Error(RegLoc, "register expected");
2861
Jim Grosbach85a23432011-11-11 21:27:40 +00002862 // The reglist instructions have at most 16 registers, so reserve
2863 // space for that many.
2864 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2865
2866 // Allow Q regs and just interpret them as the two D sub-registers.
2867 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2868 Reg = getDRegFromQReg(Reg);
2869 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2870 ++Reg;
2871 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002872 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002873 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2874 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2875 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2876 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2877 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2878 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2879 else
2880 return Error(RegLoc, "invalid register in register list");
2881
Jim Grosbach85a23432011-11-11 21:27:40 +00002882 // Store the register.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002883 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbya2b99102009-10-09 21:12:28 +00002884
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002885 // This starts immediately after the first register token in the list,
2886 // so we can see either a comma or a minus (range separator) as a legal
2887 // next token.
2888 while (Parser.getTok().is(AsmToken::Comma) ||
2889 Parser.getTok().is(AsmToken::Minus)) {
2890 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00002891 Parser.Lex(); // Eat the minus.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002892 SMLoc EndLoc = Parser.getTok().getLoc();
2893 int EndReg = tryParseRegister();
2894 if (EndReg == -1)
2895 return Error(EndLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002896 // Allow Q regs and just interpret them as the two D sub-registers.
2897 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2898 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002899 // If the register is the same as the start reg, there's nothing
2900 // more to do.
2901 if (Reg == EndReg)
2902 continue;
2903 // The register must be in the same register class as the first.
2904 if (!RC->contains(EndReg))
2905 return Error(EndLoc, "invalid register in register list");
2906 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002907 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002908 return Error(EndLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00002909
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002910 // Add all the registers in the range to the register list.
2911 while (Reg != EndReg) {
2912 Reg = getNextRegister(Reg);
2913 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2914 }
2915 continue;
2916 }
2917 Parser.Lex(); // Eat the comma.
2918 RegLoc = Parser.getTok().getLoc();
2919 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00002920 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002921 Reg = tryParseRegister();
2922 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00002923 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00002924 // Allow Q regs and just interpret them as the two D sub-registers.
2925 bool isQReg = false;
2926 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2927 Reg = getDRegFromQReg(Reg);
2928 isQReg = true;
2929 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002930 // The register must be in the same register class as the first.
2931 if (!RC->contains(Reg))
2932 return Error(RegLoc, "invalid register in register list");
2933 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00002934 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00002935 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2936 Warning(RegLoc, "register list not in ascending order");
2937 else
2938 return Error(RegLoc, "register list not in ascending order");
2939 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00002940 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00002941 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2942 ") in register list");
2943 continue;
2944 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002945 // VFP register lists must also be contiguous.
2946 // It's OK to use the enumeration values directly here rather, as the
2947 // VFP register classes have the enum sorted properly.
2948 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2949 Reg != OldReg + 1)
2950 return Error(RegLoc, "non-contiguous register range");
2951 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbach85a23432011-11-11 21:27:40 +00002952 if (isQReg)
2953 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge18980a2010-11-06 22:36:58 +00002954 }
2955
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002956 SMLoc E = Parser.getTok().getLoc();
2957 if (Parser.getTok().isNot(AsmToken::RCurly))
2958 return Error(E, "'}' expected");
2959 Parser.Lex(); // Eat '}' token.
2960
Jim Grosbach18bf3632011-12-13 21:48:29 +00002961 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00002962 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00002963
2964 // The ARM system instruction variants for LDM/STM have a '^' token here.
2965 if (Parser.getTok().is(AsmToken::Caret)) {
2966 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2967 Parser.Lex(); // Eat '^' token.
2968 }
2969
Bill Wendling2063b842010-11-18 23:43:05 +00002970 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00002971}
2972
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002973// Helper function to parse the lane index for vector lists.
2974ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach04945c42011-12-02 00:35:16 +00002975parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2976 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002977 if (Parser.getTok().is(AsmToken::LBrac)) {
2978 Parser.Lex(); // Eat the '['.
2979 if (Parser.getTok().is(AsmToken::RBrac)) {
2980 // "Dn[]" is the 'all lanes' syntax.
2981 LaneKind = AllLanes;
2982 Parser.Lex(); // Eat the ']'.
2983 return MatchOperand_Success;
2984 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00002985
2986 // There's an optional '#' token here. Normally there wouldn't be, but
2987 // inline assemble puts one in, and it's friendly to accept that.
2988 if (Parser.getTok().is(AsmToken::Hash))
2989 Parser.Lex(); // Eat the '#'
2990
Jim Grosbach7de7ab82011-12-21 01:19:23 +00002991 const MCExpr *LaneIndex;
2992 SMLoc Loc = Parser.getTok().getLoc();
2993 if (getParser().ParseExpression(LaneIndex)) {
2994 Error(Loc, "illegal expression");
2995 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00002996 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00002997 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2998 if (!CE) {
2999 Error(Loc, "lane index must be empty or an integer");
3000 return MatchOperand_ParseFail;
3001 }
3002 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3003 Error(Parser.getTok().getLoc(), "']' expected");
3004 return MatchOperand_ParseFail;
3005 }
3006 Parser.Lex(); // Eat the ']'.
3007 int64_t Val = CE->getValue();
3008
3009 // FIXME: Make this range check context sensitive for .8, .16, .32.
3010 if (Val < 0 || Val > 7) {
3011 Error(Parser.getTok().getLoc(), "lane index out of range");
3012 return MatchOperand_ParseFail;
3013 }
3014 Index = Val;
3015 LaneKind = IndexedLane;
3016 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003017 }
3018 LaneKind = NoLanes;
3019 return MatchOperand_Success;
3020}
3021
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003022// parse a vector register list
3023ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3024parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003025 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003026 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003027 SMLoc S = Parser.getTok().getLoc();
3028 // As an extension (to match gas), support a plain D register or Q register
3029 // (without encosing curly braces) as a single or double entry list,
3030 // respectively.
3031 if (Parser.getTok().is(AsmToken::Identifier)) {
3032 int Reg = tryParseRegister();
3033 if (Reg == -1)
3034 return MatchOperand_NoMatch;
3035 SMLoc E = Parser.getTok().getLoc();
3036 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003037 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003038 if (Res != MatchOperand_Success)
3039 return Res;
3040 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003041 case NoLanes:
3042 E = Parser.getTok().getLoc();
Jim Grosbach2f50e922011-12-15 21:44:33 +00003043 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003044 break;
3045 case AllLanes:
3046 E = Parser.getTok().getLoc();
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003047 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3048 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003049 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003050 case IndexedLane:
3051 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003052 LaneIndex,
3053 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003054 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003055 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003056 return MatchOperand_Success;
3057 }
3058 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3059 Reg = getDRegFromQReg(Reg);
Jim Grosbach04945c42011-12-02 00:35:16 +00003060 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003061 if (Res != MatchOperand_Success)
3062 return Res;
3063 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003064 case NoLanes:
3065 E = Parser.getTok().getLoc();
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003066 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003067 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003068 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003069 break;
3070 case AllLanes:
3071 E = Parser.getTok().getLoc();
Jim Grosbach13a292c2012-03-06 22:01:44 +00003072 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3073 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003074 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3075 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003076 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003077 case IndexedLane:
3078 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003079 LaneIndex,
3080 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003081 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003082 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003083 return MatchOperand_Success;
3084 }
3085 Error(S, "vector register expected");
3086 return MatchOperand_ParseFail;
3087 }
3088
3089 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003090 return MatchOperand_NoMatch;
3091
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003092 Parser.Lex(); // Eat '{' token.
3093 SMLoc RegLoc = Parser.getTok().getLoc();
3094
3095 int Reg = tryParseRegister();
3096 if (Reg == -1) {
3097 Error(RegLoc, "register expected");
3098 return MatchOperand_ParseFail;
3099 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003100 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003101 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003102 unsigned FirstReg = Reg;
3103 // The list is of D registers, but we also allow Q regs and just interpret
3104 // them as the two D sub-registers.
3105 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3106 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003107 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3108 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003109 ++Reg;
3110 ++Count;
3111 }
Jim Grosbach04945c42011-12-02 00:35:16 +00003112 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003113 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003114
Jim Grosbache891fe82011-11-15 23:19:15 +00003115 while (Parser.getTok().is(AsmToken::Comma) ||
3116 Parser.getTok().is(AsmToken::Minus)) {
3117 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003118 if (!Spacing)
3119 Spacing = 1; // Register range implies a single spaced list.
3120 else if (Spacing == 2) {
3121 Error(Parser.getTok().getLoc(),
3122 "sequential registers in double spaced list");
3123 return MatchOperand_ParseFail;
3124 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003125 Parser.Lex(); // Eat the minus.
3126 SMLoc EndLoc = Parser.getTok().getLoc();
3127 int EndReg = tryParseRegister();
3128 if (EndReg == -1) {
3129 Error(EndLoc, "register expected");
3130 return MatchOperand_ParseFail;
3131 }
3132 // Allow Q regs and just interpret them as the two D sub-registers.
3133 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3134 EndReg = getDRegFromQReg(EndReg) + 1;
3135 // If the register is the same as the start reg, there's nothing
3136 // more to do.
3137 if (Reg == EndReg)
3138 continue;
3139 // The register must be in the same register class as the first.
3140 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3141 Error(EndLoc, "invalid register in register list");
3142 return MatchOperand_ParseFail;
3143 }
3144 // Ranges must go from low to high.
3145 if (Reg > EndReg) {
3146 Error(EndLoc, "bad range in register list");
3147 return MatchOperand_ParseFail;
3148 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003149 // Parse the lane specifier if present.
3150 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003151 unsigned NextLaneIndex;
3152 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003153 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003154 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003155 Error(EndLoc, "mismatched lane index in register list");
3156 return MatchOperand_ParseFail;
3157 }
3158 EndLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003159
3160 // Add all the registers in the range to the register list.
3161 Count += EndReg - Reg;
3162 Reg = EndReg;
3163 continue;
3164 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003165 Parser.Lex(); // Eat the comma.
3166 RegLoc = Parser.getTok().getLoc();
3167 int OldReg = Reg;
3168 Reg = tryParseRegister();
3169 if (Reg == -1) {
3170 Error(RegLoc, "register expected");
3171 return MatchOperand_ParseFail;
3172 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003173 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003174 // It's OK to use the enumeration values directly here rather, as the
3175 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003176 //
3177 // The list is of D registers, but we also allow Q regs and just interpret
3178 // them as the two D sub-registers.
3179 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003180 if (!Spacing)
3181 Spacing = 1; // Register range implies a single spaced list.
3182 else if (Spacing == 2) {
3183 Error(RegLoc,
3184 "invalid register in double-spaced list (must be 'D' register')");
3185 return MatchOperand_ParseFail;
3186 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003187 Reg = getDRegFromQReg(Reg);
3188 if (Reg != OldReg + 1) {
3189 Error(RegLoc, "non-contiguous register range");
3190 return MatchOperand_ParseFail;
3191 }
3192 ++Reg;
3193 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003194 // Parse the lane specifier if present.
3195 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003196 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003197 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach04945c42011-12-02 00:35:16 +00003198 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003199 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003200 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003201 Error(EndLoc, "mismatched lane index in register list");
3202 return MatchOperand_ParseFail;
3203 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003204 continue;
3205 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003206 // Normal D register.
3207 // Figure out the register spacing (single or double) of the list if
3208 // we don't know it already.
3209 if (!Spacing)
3210 Spacing = 1 + (Reg == OldReg + 2);
3211
3212 // Just check that it's contiguous and keep going.
3213 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003214 Error(RegLoc, "non-contiguous register range");
3215 return MatchOperand_ParseFail;
3216 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003217 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003218 // Parse the lane specifier if present.
3219 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003220 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003221 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach04945c42011-12-02 00:35:16 +00003222 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003223 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003224 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003225 Error(EndLoc, "mismatched lane index in register list");
3226 return MatchOperand_ParseFail;
3227 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003228 }
3229
3230 SMLoc E = Parser.getTok().getLoc();
3231 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3232 Error(E, "'}' expected");
3233 return MatchOperand_ParseFail;
3234 }
3235 Parser.Lex(); // Eat '}' token.
3236
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003237 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003238 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003239 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003240 // composite register classes.
3241 if (Count == 2) {
3242 const MCRegisterClass *RC = (Spacing == 1) ?
3243 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3244 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3245 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3246 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003247
Jim Grosbach2f50e922011-12-15 21:44:33 +00003248 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3249 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003250 break;
3251 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003252 // Two-register operands have been converted to the
3253 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003254 if (Count == 2) {
3255 const MCRegisterClass *RC = (Spacing == 1) ?
3256 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3257 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003258 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3259 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003260 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003261 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003262 S, E));
3263 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003264 case IndexedLane:
3265 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003266 LaneIndex,
3267 (Spacing == 2),
3268 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003269 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003270 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003271 return MatchOperand_Success;
3272}
3273
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003274/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003275ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003276parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003277 SMLoc S = Parser.getTok().getLoc();
3278 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003279 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003280
Jiangning Liu288e1af2012-08-02 08:21:27 +00003281 if (Tok.is(AsmToken::Identifier)) {
3282 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003283
Jiangning Liu288e1af2012-08-02 08:21:27 +00003284 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3285 .Case("sy", ARM_MB::SY)
3286 .Case("st", ARM_MB::ST)
3287 .Case("sh", ARM_MB::ISH)
3288 .Case("ish", ARM_MB::ISH)
3289 .Case("shst", ARM_MB::ISHST)
3290 .Case("ishst", ARM_MB::ISHST)
3291 .Case("nsh", ARM_MB::NSH)
3292 .Case("un", ARM_MB::NSH)
3293 .Case("nshst", ARM_MB::NSHST)
3294 .Case("unst", ARM_MB::NSHST)
3295 .Case("osh", ARM_MB::OSH)
3296 .Case("oshst", ARM_MB::OSHST)
3297 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003298
Jiangning Liu288e1af2012-08-02 08:21:27 +00003299 if (Opt == ~0U)
3300 return MatchOperand_NoMatch;
3301
3302 Parser.Lex(); // Eat identifier token.
3303 } else if (Tok.is(AsmToken::Hash) ||
3304 Tok.is(AsmToken::Dollar) ||
3305 Tok.is(AsmToken::Integer)) {
3306 if (Parser.getTok().isNot(AsmToken::Integer))
3307 Parser.Lex(); // Eat the '#'.
3308 SMLoc Loc = Parser.getTok().getLoc();
3309
3310 const MCExpr *MemBarrierID;
3311 if (getParser().ParseExpression(MemBarrierID)) {
3312 Error(Loc, "illegal expression");
3313 return MatchOperand_ParseFail;
3314 }
3315
3316 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3317 if (!CE) {
3318 Error(Loc, "constant expression expected");
3319 return MatchOperand_ParseFail;
3320 }
3321
3322 int Val = CE->getValue();
3323 if (Val & ~0xf) {
3324 Error(Loc, "immediate value out of range");
3325 return MatchOperand_ParseFail;
3326 }
3327
3328 Opt = ARM_MB::RESERVED_0 + Val;
3329 } else
3330 return MatchOperand_ParseFail;
3331
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003332 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003333 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003334}
3335
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003336/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003337ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003338parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003339 SMLoc S = Parser.getTok().getLoc();
3340 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003341 if (!Tok.is(AsmToken::Identifier))
3342 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003343 StringRef IFlagsStr = Tok.getString();
3344
Owen Anderson10c5b122011-10-05 17:16:40 +00003345 // An iflags string of "none" is interpreted to mean that none of the AIF
3346 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003347 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003348 if (IFlagsStr != "none") {
3349 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3350 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3351 .Case("a", ARM_PROC::A)
3352 .Case("i", ARM_PROC::I)
3353 .Case("f", ARM_PROC::F)
3354 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003355
Owen Anderson10c5b122011-10-05 17:16:40 +00003356 // If some specific iflag is already set, it means that some letter is
3357 // present more than once, this is not acceptable.
3358 if (Flag == ~0U || (IFlags & Flag))
3359 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003360
Owen Anderson10c5b122011-10-05 17:16:40 +00003361 IFlags |= Flag;
3362 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003363 }
3364
3365 Parser.Lex(); // Eat identifier token.
3366 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3367 return MatchOperand_Success;
3368}
3369
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003370/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003371ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003372parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003373 SMLoc S = Parser.getTok().getLoc();
3374 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003375 if (!Tok.is(AsmToken::Identifier))
3376 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003377 StringRef Mask = Tok.getString();
3378
James Molloy21efa7d2011-09-28 14:21:38 +00003379 if (isMClass()) {
3380 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003381 std::string Name = Mask.lower();
3382 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003383 // Note: in the documentation:
3384 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3385 // for MSR APSR_nzcvq.
3386 // but we do make it an alias here. This is so to get the "mask encoding"
3387 // bits correct on MSR APSR writes.
3388 //
3389 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3390 // should really only be allowed when writing a special register. Note
3391 // they get dropped in the MRS instruction reading a special register as
3392 // the SYSm field is only 8 bits.
3393 //
3394 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3395 // includes the DSP extension but that is not checked.
3396 .Case("apsr", 0x800)
3397 .Case("apsr_nzcvq", 0x800)
3398 .Case("apsr_g", 0x400)
3399 .Case("apsr_nzcvqg", 0xc00)
3400 .Case("iapsr", 0x801)
3401 .Case("iapsr_nzcvq", 0x801)
3402 .Case("iapsr_g", 0x401)
3403 .Case("iapsr_nzcvqg", 0xc01)
3404 .Case("eapsr", 0x802)
3405 .Case("eapsr_nzcvq", 0x802)
3406 .Case("eapsr_g", 0x402)
3407 .Case("eapsr_nzcvqg", 0xc02)
3408 .Case("xpsr", 0x803)
3409 .Case("xpsr_nzcvq", 0x803)
3410 .Case("xpsr_g", 0x403)
3411 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003412 .Case("ipsr", 0x805)
3413 .Case("epsr", 0x806)
3414 .Case("iepsr", 0x807)
3415 .Case("msp", 0x808)
3416 .Case("psp", 0x809)
3417 .Case("primask", 0x810)
3418 .Case("basepri", 0x811)
3419 .Case("basepri_max", 0x812)
3420 .Case("faultmask", 0x813)
3421 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003422 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003423
James Molloy21efa7d2011-09-28 14:21:38 +00003424 if (FlagsVal == ~0U)
3425 return MatchOperand_NoMatch;
3426
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003427 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003428 // basepri, basepri_max and faultmask only valid for V7m.
3429 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003430
James Molloy21efa7d2011-09-28 14:21:38 +00003431 Parser.Lex(); // Eat identifier token.
3432 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3433 return MatchOperand_Success;
3434 }
3435
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003436 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3437 size_t Start = 0, Next = Mask.find('_');
3438 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003439 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003440 if (Next != StringRef::npos)
3441 Flags = Mask.slice(Next+1, Mask.size());
3442
3443 // FlagsVal contains the complete mask:
3444 // 3-0: Mask
3445 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3446 unsigned FlagsVal = 0;
3447
3448 if (SpecReg == "apsr") {
3449 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003450 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003451 .Case("g", 0x4) // same as CPSR_s
3452 .Case("nzcvqg", 0xc) // same as CPSR_fs
3453 .Default(~0U);
3454
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003455 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003456 if (!Flags.empty())
3457 return MatchOperand_NoMatch;
3458 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003459 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003460 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003461 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003462 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3463 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003464 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003465 for (int i = 0, e = Flags.size(); i != e; ++i) {
3466 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3467 .Case("c", 1)
3468 .Case("x", 2)
3469 .Case("s", 4)
3470 .Case("f", 8)
3471 .Default(~0U);
3472
3473 // If some specific flag is already set, it means that some letter is
3474 // present more than once, this is not acceptable.
3475 if (FlagsVal == ~0U || (FlagsVal & Flag))
3476 return MatchOperand_NoMatch;
3477 FlagsVal |= Flag;
3478 }
3479 } else // No match for special register.
3480 return MatchOperand_NoMatch;
3481
Owen Anderson03a173e2011-10-21 18:43:28 +00003482 // Special register without flags is NOT equivalent to "fc" flags.
3483 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3484 // two lines would enable gas compatibility at the expense of breaking
3485 // round-tripping.
3486 //
3487 // if (!FlagsVal)
3488 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003489
3490 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3491 if (SpecReg == "spsr")
3492 FlagsVal |= 16;
3493
3494 Parser.Lex(); // Eat identifier token.
3495 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3496 return MatchOperand_Success;
3497}
3498
Jim Grosbach27c1e252011-07-21 17:23:04 +00003499ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3500parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3501 int Low, int High) {
3502 const AsmToken &Tok = Parser.getTok();
3503 if (Tok.isNot(AsmToken::Identifier)) {
3504 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3505 return MatchOperand_ParseFail;
3506 }
3507 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003508 std::string LowerOp = Op.lower();
3509 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003510 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3511 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3512 return MatchOperand_ParseFail;
3513 }
3514 Parser.Lex(); // Eat shift type token.
3515
3516 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003517 if (Parser.getTok().isNot(AsmToken::Hash) &&
3518 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003519 Error(Parser.getTok().getLoc(), "'#' expected");
3520 return MatchOperand_ParseFail;
3521 }
3522 Parser.Lex(); // Eat hash token.
3523
3524 const MCExpr *ShiftAmount;
3525 SMLoc Loc = Parser.getTok().getLoc();
3526 if (getParser().ParseExpression(ShiftAmount)) {
3527 Error(Loc, "illegal expression");
3528 return MatchOperand_ParseFail;
3529 }
3530 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3531 if (!CE) {
3532 Error(Loc, "constant expression expected");
3533 return MatchOperand_ParseFail;
3534 }
3535 int Val = CE->getValue();
3536 if (Val < Low || Val > High) {
3537 Error(Loc, "immediate value out of range");
3538 return MatchOperand_ParseFail;
3539 }
3540
3541 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3542
3543 return MatchOperand_Success;
3544}
3545
Jim Grosbach0a547702011-07-22 17:44:50 +00003546ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3547parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3548 const AsmToken &Tok = Parser.getTok();
3549 SMLoc S = Tok.getLoc();
3550 if (Tok.isNot(AsmToken::Identifier)) {
3551 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3552 return MatchOperand_ParseFail;
3553 }
3554 int Val = StringSwitch<int>(Tok.getString())
3555 .Case("be", 1)
3556 .Case("le", 0)
3557 .Default(-1);
3558 Parser.Lex(); // Eat the token.
3559
3560 if (Val == -1) {
3561 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3562 return MatchOperand_ParseFail;
3563 }
3564 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3565 getContext()),
3566 S, Parser.getTok().getLoc()));
3567 return MatchOperand_Success;
3568}
3569
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003570/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3571/// instructions. Legal values are:
3572/// lsl #n 'n' in [0,31]
3573/// asr #n 'n' in [1,32]
3574/// n == 32 encoded as n == 0.
3575ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3576parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3577 const AsmToken &Tok = Parser.getTok();
3578 SMLoc S = Tok.getLoc();
3579 if (Tok.isNot(AsmToken::Identifier)) {
3580 Error(S, "shift operator 'asr' or 'lsl' expected");
3581 return MatchOperand_ParseFail;
3582 }
3583 StringRef ShiftName = Tok.getString();
3584 bool isASR;
3585 if (ShiftName == "lsl" || ShiftName == "LSL")
3586 isASR = false;
3587 else if (ShiftName == "asr" || ShiftName == "ASR")
3588 isASR = true;
3589 else {
3590 Error(S, "shift operator 'asr' or 'lsl' expected");
3591 return MatchOperand_ParseFail;
3592 }
3593 Parser.Lex(); // Eat the operator.
3594
3595 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003596 if (Parser.getTok().isNot(AsmToken::Hash) &&
3597 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003598 Error(Parser.getTok().getLoc(), "'#' expected");
3599 return MatchOperand_ParseFail;
3600 }
3601 Parser.Lex(); // Eat hash token.
3602
3603 const MCExpr *ShiftAmount;
3604 SMLoc E = Parser.getTok().getLoc();
3605 if (getParser().ParseExpression(ShiftAmount)) {
3606 Error(E, "malformed shift expression");
3607 return MatchOperand_ParseFail;
3608 }
3609 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3610 if (!CE) {
3611 Error(E, "shift amount must be an immediate");
3612 return MatchOperand_ParseFail;
3613 }
3614
3615 int64_t Val = CE->getValue();
3616 if (isASR) {
3617 // Shift amount must be in [1,32]
3618 if (Val < 1 || Val > 32) {
3619 Error(E, "'asr' shift amount must be in range [1,32]");
3620 return MatchOperand_ParseFail;
3621 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003622 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3623 if (isThumb() && Val == 32) {
3624 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3625 return MatchOperand_ParseFail;
3626 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003627 if (Val == 32) Val = 0;
3628 } else {
3629 // Shift amount must be in [1,32]
3630 if (Val < 0 || Val > 31) {
3631 Error(E, "'lsr' shift amount must be in range [0,31]");
3632 return MatchOperand_ParseFail;
3633 }
3634 }
3635
3636 E = Parser.getTok().getLoc();
3637 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3638
3639 return MatchOperand_Success;
3640}
3641
Jim Grosbach833b9d32011-07-27 20:15:40 +00003642/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3643/// of instructions. Legal values are:
3644/// ror #n 'n' in {0, 8, 16, 24}
3645ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3646parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3647 const AsmToken &Tok = Parser.getTok();
3648 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003649 if (Tok.isNot(AsmToken::Identifier))
3650 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003651 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003652 if (ShiftName != "ror" && ShiftName != "ROR")
3653 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003654 Parser.Lex(); // Eat the operator.
3655
3656 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003657 if (Parser.getTok().isNot(AsmToken::Hash) &&
3658 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003659 Error(Parser.getTok().getLoc(), "'#' expected");
3660 return MatchOperand_ParseFail;
3661 }
3662 Parser.Lex(); // Eat hash token.
3663
3664 const MCExpr *ShiftAmount;
3665 SMLoc E = Parser.getTok().getLoc();
3666 if (getParser().ParseExpression(ShiftAmount)) {
3667 Error(E, "malformed rotate expression");
3668 return MatchOperand_ParseFail;
3669 }
3670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3671 if (!CE) {
3672 Error(E, "rotate amount must be an immediate");
3673 return MatchOperand_ParseFail;
3674 }
3675
3676 int64_t Val = CE->getValue();
3677 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3678 // normally, zero is represented in asm by omitting the rotate operand
3679 // entirely.
3680 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3681 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3682 return MatchOperand_ParseFail;
3683 }
3684
3685 E = Parser.getTok().getLoc();
3686 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3687
3688 return MatchOperand_Success;
3689}
3690
Jim Grosbach864b6092011-07-28 21:34:26 +00003691ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3692parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3693 SMLoc S = Parser.getTok().getLoc();
3694 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003695 if (Parser.getTok().isNot(AsmToken::Hash) &&
3696 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003697 Error(Parser.getTok().getLoc(), "'#' expected");
3698 return MatchOperand_ParseFail;
3699 }
3700 Parser.Lex(); // Eat hash token.
3701
3702 const MCExpr *LSBExpr;
3703 SMLoc E = Parser.getTok().getLoc();
3704 if (getParser().ParseExpression(LSBExpr)) {
3705 Error(E, "malformed immediate expression");
3706 return MatchOperand_ParseFail;
3707 }
3708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3709 if (!CE) {
3710 Error(E, "'lsb' operand must be an immediate");
3711 return MatchOperand_ParseFail;
3712 }
3713
3714 int64_t LSB = CE->getValue();
3715 // The LSB must be in the range [0,31]
3716 if (LSB < 0 || LSB > 31) {
3717 Error(E, "'lsb' operand must be in the range [0,31]");
3718 return MatchOperand_ParseFail;
3719 }
3720 E = Parser.getTok().getLoc();
3721
3722 // Expect another immediate operand.
3723 if (Parser.getTok().isNot(AsmToken::Comma)) {
3724 Error(Parser.getTok().getLoc(), "too few operands");
3725 return MatchOperand_ParseFail;
3726 }
3727 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003728 if (Parser.getTok().isNot(AsmToken::Hash) &&
3729 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003730 Error(Parser.getTok().getLoc(), "'#' expected");
3731 return MatchOperand_ParseFail;
3732 }
3733 Parser.Lex(); // Eat hash token.
3734
3735 const MCExpr *WidthExpr;
3736 if (getParser().ParseExpression(WidthExpr)) {
3737 Error(E, "malformed immediate expression");
3738 return MatchOperand_ParseFail;
3739 }
3740 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3741 if (!CE) {
3742 Error(E, "'width' operand must be an immediate");
3743 return MatchOperand_ParseFail;
3744 }
3745
3746 int64_t Width = CE->getValue();
3747 // The LSB must be in the range [1,32-lsb]
3748 if (Width < 1 || Width > 32 - LSB) {
3749 Error(E, "'width' operand must be in the range [1,32-lsb]");
3750 return MatchOperand_ParseFail;
3751 }
3752 E = Parser.getTok().getLoc();
3753
3754 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3755
3756 return MatchOperand_Success;
3757}
3758
Jim Grosbachd3595712011-08-03 23:50:40 +00003759ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3760parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3761 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003762 // postidx_reg := '+' register {, shift}
3763 // | '-' register {, shift}
3764 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003765
3766 // This method must return MatchOperand_NoMatch without consuming any tokens
3767 // in the case where there is no match, as other alternatives take other
3768 // parse methods.
3769 AsmToken Tok = Parser.getTok();
3770 SMLoc S = Tok.getLoc();
3771 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003772 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003773 int Reg = -1;
3774 if (Tok.is(AsmToken::Plus)) {
3775 Parser.Lex(); // Eat the '+' token.
3776 haveEaten = true;
3777 } else if (Tok.is(AsmToken::Minus)) {
3778 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003779 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003780 haveEaten = true;
3781 }
3782 if (Parser.getTok().is(AsmToken::Identifier))
3783 Reg = tryParseRegister();
3784 if (Reg == -1) {
3785 if (!haveEaten)
3786 return MatchOperand_NoMatch;
3787 Error(Parser.getTok().getLoc(), "register expected");
3788 return MatchOperand_ParseFail;
3789 }
3790 SMLoc E = Parser.getTok().getLoc();
3791
Jim Grosbachc320c852011-08-05 21:28:30 +00003792 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3793 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00003794 if (Parser.getTok().is(AsmToken::Comma)) {
3795 Parser.Lex(); // Eat the ','.
3796 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3797 return MatchOperand_ParseFail;
3798 }
Jim Grosbachc320c852011-08-05 21:28:30 +00003799
3800 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3801 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00003802
3803 return MatchOperand_Success;
3804}
3805
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003806ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3807parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3808 // Check for a post-index addressing register operand. Specifically:
3809 // am3offset := '+' register
3810 // | '-' register
3811 // | register
3812 // | # imm
3813 // | # + imm
3814 // | # - imm
3815
3816 // This method must return MatchOperand_NoMatch without consuming any tokens
3817 // in the case where there is no match, as other alternatives take other
3818 // parse methods.
3819 AsmToken Tok = Parser.getTok();
3820 SMLoc S = Tok.getLoc();
3821
3822 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003823 if (Parser.getTok().is(AsmToken::Hash) ||
3824 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00003825 Parser.Lex(); // Eat the '#'.
3826 // Explicitly look for a '-', as we need to encode negative zero
3827 // differently.
3828 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3829 const MCExpr *Offset;
3830 if (getParser().ParseExpression(Offset))
3831 return MatchOperand_ParseFail;
3832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3833 if (!CE) {
3834 Error(S, "constant expression expected");
3835 return MatchOperand_ParseFail;
3836 }
3837 SMLoc E = Tok.getLoc();
3838 // Negative zero is encoded as the flag value INT32_MIN.
3839 int32_t Val = CE->getValue();
3840 if (isNegative && Val == 0)
3841 Val = INT32_MIN;
3842
3843 Operands.push_back(
3844 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3845
3846 return MatchOperand_Success;
3847 }
3848
3849
3850 bool haveEaten = false;
3851 bool isAdd = true;
3852 int Reg = -1;
3853 if (Tok.is(AsmToken::Plus)) {
3854 Parser.Lex(); // Eat the '+' token.
3855 haveEaten = true;
3856 } else if (Tok.is(AsmToken::Minus)) {
3857 Parser.Lex(); // Eat the '-' token.
3858 isAdd = false;
3859 haveEaten = true;
3860 }
3861 if (Parser.getTok().is(AsmToken::Identifier))
3862 Reg = tryParseRegister();
3863 if (Reg == -1) {
3864 if (!haveEaten)
3865 return MatchOperand_NoMatch;
3866 Error(Parser.getTok().getLoc(), "register expected");
3867 return MatchOperand_ParseFail;
3868 }
3869 SMLoc E = Parser.getTok().getLoc();
3870
3871 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3872 0, S, E));
3873
3874 return MatchOperand_Success;
3875}
3876
Jim Grosbach7db8d692011-09-08 22:07:06 +00003877/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3878/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3879/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003880void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003881cvtT2LdrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003882 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3883 // Rt, Rt2
3884 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3885 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3886 // Create a writeback register dummy placeholder.
3887 Inst.addOperand(MCOperand::CreateReg(0));
3888 // addr
3889 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3890 // pred
3891 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003892}
3893
3894/// cvtT2StrdPre - Convert parsed operands to MCInst.
3895/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3896/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003897void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003898cvtT2StrdPre(MCInst &Inst,
Jim Grosbach7db8d692011-09-08 22:07:06 +00003899 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3900 // Create a writeback register dummy placeholder.
3901 Inst.addOperand(MCOperand::CreateReg(0));
3902 // Rt, Rt2
3903 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3904 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3905 // addr
3906 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3907 // pred
3908 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7db8d692011-09-08 22:07:06 +00003909}
3910
Jim Grosbachc086f682011-09-08 00:39:19 +00003911/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3912/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3913/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003914void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003915cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachc086f682011-09-08 00:39:19 +00003916 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3917 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3918
3919 // Create a writeback register dummy placeholder.
3920 Inst.addOperand(MCOperand::CreateImm(0));
3921
3922 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3923 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachc086f682011-09-08 00:39:19 +00003924}
3925
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003926/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3927/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3928/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003929void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003930cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003931 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3932 // Create a writeback register dummy placeholder.
3933 Inst.addOperand(MCOperand::CreateImm(0));
3934 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3935 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3936 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach9c0b86a2011-09-16 21:55:56 +00003937}
3938
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003939/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003940/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3941/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003942void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003943cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003944 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3945 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3946
3947 // Create a writeback register dummy placeholder.
3948 Inst.addOperand(MCOperand::CreateImm(0));
3949
Jim Grosbachd3595712011-08-03 23:50:40 +00003950 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003951 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003952}
3953
Owen Anderson16d33f32011-08-26 20:43:14 +00003954/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3955/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3956/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003957void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003958cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson16d33f32011-08-26 20:43:14 +00003959 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3960 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3961
3962 // Create a writeback register dummy placeholder.
3963 Inst.addOperand(MCOperand::CreateImm(0));
3964
3965 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3966 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson16d33f32011-08-26 20:43:14 +00003967}
3968
3969
Jim Grosbachd564bf32011-08-11 19:22:40 +00003970/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3971/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3972/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003973void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003974cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbachd564bf32011-08-11 19:22:40 +00003975 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3976 // Create a writeback register dummy placeholder.
3977 Inst.addOperand(MCOperand::CreateImm(0));
3978 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3979 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3980 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd564bf32011-08-11 19:22:40 +00003981}
3982
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003983/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003984/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3985/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003986void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00003987cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00003988 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3989 // Create a writeback register dummy placeholder.
3990 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd564bf32011-08-11 19:22:40 +00003991 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3992 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3993 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00003994}
3995
Jim Grosbachd886f8c2011-08-11 21:17:22 +00003996/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3997/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3998/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00003999void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004000cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004001 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4002 // Create a writeback register dummy placeholder.
4003 Inst.addOperand(MCOperand::CreateImm(0));
4004 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4005 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4006 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd886f8c2011-08-11 21:17:22 +00004007}
4008
Jim Grosbachd3595712011-08-03 23:50:40 +00004009/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4010/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4011/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004012void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004013cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004014 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4015 // Rt
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004016 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004017 // Create a writeback register dummy placeholder.
4018 Inst.addOperand(MCOperand::CreateImm(0));
4019 // addr
4020 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4021 // offset
4022 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4023 // pred
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004024 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00004025}
4026
Jim Grosbachd3595712011-08-03 23:50:40 +00004027/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004028/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4029/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004030void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004031cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004032 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4033 // Rt
Owen Andersonb0e68992011-07-28 17:18:57 +00004034 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004035 // Create a writeback register dummy placeholder.
4036 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004037 // addr
4038 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4039 // offset
4040 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4041 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004042 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004043}
4044
Jim Grosbachd3595712011-08-03 23:50:40 +00004045/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004046/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4047/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004048void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004049cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004050 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004051 // Create a writeback register dummy placeholder.
4052 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbachd3595712011-08-03 23:50:40 +00004053 // Rt
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004054 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbachd3595712011-08-03 23:50:40 +00004055 // addr
4056 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4057 // offset
4058 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4059 // pred
4060 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachd3595712011-08-03 23:50:40 +00004061}
4062
4063/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4064/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4065/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004066void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004067cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbachd3595712011-08-03 23:50:40 +00004068 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4069 // Create a writeback register dummy placeholder.
4070 Inst.addOperand(MCOperand::CreateImm(0));
4071 // Rt
4072 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4073 // addr
4074 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4075 // offset
4076 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4077 // pred
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004078 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00004079}
4080
Jim Grosbach5b96b802011-08-10 20:29:19 +00004081/// cvtLdrdPre - Convert parsed operands to MCInst.
4082/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4083/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004084void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004085cvtLdrdPre(MCInst &Inst,
Jim Grosbach5b96b802011-08-10 20:29:19 +00004086 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4087 // Rt, Rt2
4088 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4089 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4090 // Create a writeback register dummy placeholder.
4091 Inst.addOperand(MCOperand::CreateImm(0));
4092 // addr
4093 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4094 // pred
4095 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach5b96b802011-08-10 20:29:19 +00004096}
4097
Jim Grosbacheb09f492011-08-11 20:28:23 +00004098/// cvtStrdPre - Convert parsed operands to MCInst.
4099/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4100/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004101void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004102cvtStrdPre(MCInst &Inst,
Jim Grosbacheb09f492011-08-11 20:28:23 +00004103 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4104 // Create a writeback register dummy placeholder.
4105 Inst.addOperand(MCOperand::CreateImm(0));
4106 // Rt, Rt2
4107 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4108 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4109 // addr
4110 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4111 // pred
4112 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheb09f492011-08-11 20:28:23 +00004113}
4114
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004115/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4116/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4117/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004118void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004119cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004120 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4121 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4122 // Create a writeback register dummy placeholder.
4123 Inst.addOperand(MCOperand::CreateImm(0));
4124 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4125 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004126}
4127
Chad Rosier5eec49f2012-08-30 23:00:00 +00004128/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach8e048492011-08-19 22:07:46 +00004129/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4130/// when they refer multiple MIOperands inside a single one.
Chad Rosier98cfa102012-08-31 00:03:31 +00004131void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004132cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004133 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004134 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4135 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004136 // If we have a three-operand form, make sure to set Rn to be the operand
4137 // that isn't the same as Rd.
4138 unsigned RegOp = 4;
4139 if (Operands.size() == 6 &&
4140 ((ARMOperand*)Operands[4])->getReg() ==
4141 ((ARMOperand*)Operands[3])->getReg())
4142 RegOp = 5;
4143 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4144 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004145 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004146}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004147
Chad Rosier98cfa102012-08-31 00:03:31 +00004148void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004149cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004150 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4151 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004152 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004153 // Create a writeback register dummy placeholder.
4154 Inst.addOperand(MCOperand::CreateImm(0));
4155 // Vn
4156 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4157 // pred
4158 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004159}
4160
Chad Rosier98cfa102012-08-31 00:03:31 +00004161void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004162cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach3ea06572011-10-24 22:16:58 +00004163 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4164 // Vd
Jim Grosbach182b6a02011-11-29 23:51:09 +00004165 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004166 // Create a writeback register dummy placeholder.
4167 Inst.addOperand(MCOperand::CreateImm(0));
4168 // Vn
4169 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4170 // Vm
4171 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4172 // pred
4173 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach3ea06572011-10-24 22:16:58 +00004174}
4175
Chad Rosier98cfa102012-08-31 00:03:31 +00004176void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004177cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004178 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4179 // Create a writeback register dummy placeholder.
4180 Inst.addOperand(MCOperand::CreateImm(0));
4181 // Vn
4182 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4183 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004184 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004185 // pred
4186 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004187}
4188
Chad Rosier98cfa102012-08-31 00:03:31 +00004189void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004190cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach05df4602011-10-31 21:50:31 +00004191 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4192 // Create a writeback register dummy placeholder.
4193 Inst.addOperand(MCOperand::CreateImm(0));
4194 // Vn
4195 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4196 // Vm
4197 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4198 // Vt
Jim Grosbach182b6a02011-11-29 23:51:09 +00004199 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach05df4602011-10-31 21:50:31 +00004200 // pred
4201 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach05df4602011-10-31 21:50:31 +00004202}
4203
Bill Wendlinge18980a2010-11-06 22:36:58 +00004204/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004205/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004206bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004207parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004208 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004209 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004210 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004211 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004212 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004213
Sean Callanan936b0d32010-01-19 21:44:56 +00004214 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004215 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004216 if (BaseRegNum == -1)
4217 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004218
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004219 // The next token must either be a comma or a closing bracket.
4220 const AsmToken &Tok = Parser.getTok();
4221 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004222 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004223
Jim Grosbachd3595712011-08-03 23:50:40 +00004224 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004225 E = Tok.getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004226 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004227
Jim Grosbachd3595712011-08-03 23:50:40 +00004228 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004229 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004230
Jim Grosbach40700e02011-09-19 18:42:21 +00004231 // If there's a pre-indexing writeback marker, '!', just add it as a token
4232 // operand. It's rather odd, but syntactically valid.
4233 if (Parser.getTok().is(AsmToken::Exclaim)) {
4234 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4235 Parser.Lex(); // Eat the '!'.
4236 }
4237
Jim Grosbachd3595712011-08-03 23:50:40 +00004238 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004239 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004240
Jim Grosbachd3595712011-08-03 23:50:40 +00004241 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4242 Parser.Lex(); // Eat the comma.
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004243
Jim Grosbacha95ec992011-10-11 17:29:55 +00004244 // If we have a ':', it's an alignment specifier.
4245 if (Parser.getTok().is(AsmToken::Colon)) {
4246 Parser.Lex(); // Eat the ':'.
4247 E = Parser.getTok().getLoc();
4248
4249 const MCExpr *Expr;
4250 if (getParser().ParseExpression(Expr))
4251 return true;
4252
4253 // The expression has to be a constant. Memory references with relocations
4254 // don't come through here, as they use the <label> forms of the relevant
4255 // instructions.
4256 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4257 if (!CE)
4258 return Error (E, "constant expression expected");
4259
4260 unsigned Align = 0;
4261 switch (CE->getValue()) {
4262 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004263 return Error(E,
4264 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4265 case 16: Align = 2; break;
4266 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004267 case 64: Align = 8; break;
4268 case 128: Align = 16; break;
4269 case 256: Align = 32; break;
4270 }
4271
4272 // Now we should have the closing ']'
4273 E = Parser.getTok().getLoc();
4274 if (Parser.getTok().isNot(AsmToken::RBrac))
4275 return Error(E, "']' expected");
4276 Parser.Lex(); // Eat right bracket token.
4277
4278 // Don't worry about range checking the value here. That's handled by
4279 // the is*() predicates.
4280 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4281 ARM_AM::no_shift, 0, Align,
4282 false, S, E));
4283
4284 // If there's a pre-indexing writeback marker, '!', just add it as a token
4285 // operand.
4286 if (Parser.getTok().is(AsmToken::Exclaim)) {
4287 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4288 Parser.Lex(); // Eat the '!'.
4289 }
4290
4291 return false;
4292 }
4293
4294 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004295 // offset. Be friendly and also accept a plain integer (without a leading
4296 // hash) for gas compatibility.
4297 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004298 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004299 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004300 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach8279c182011-11-15 22:14:41 +00004301 Parser.Lex(); // Eat the '#'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004302 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004303
Owen Anderson967674d2011-08-29 19:36:44 +00004304 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004305 const MCExpr *Offset;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004306 if (getParser().ParseExpression(Offset))
4307 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004308
4309 // The expression has to be a constant. Memory references with relocations
4310 // don't come through here, as they use the <label> forms of the relevant
4311 // instructions.
4312 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4313 if (!CE)
4314 return Error (E, "constant expression expected");
4315
Owen Anderson967674d2011-08-29 19:36:44 +00004316 // If the constant was #-0, represent it as INT32_MIN.
4317 int32_t Val = CE->getValue();
4318 if (isNegative && Val == 0)
4319 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4320
Jim Grosbachd3595712011-08-03 23:50:40 +00004321 // Now we should have the closing ']'
4322 E = Parser.getTok().getLoc();
4323 if (Parser.getTok().isNot(AsmToken::RBrac))
4324 return Error(E, "']' expected");
4325 Parser.Lex(); // Eat right bracket token.
4326
4327 // Don't worry about range checking the value here. That's handled by
4328 // the is*() predicates.
4329 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004330 ARM_AM::no_shift, 0, 0,
4331 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004332
4333 // If there's a pre-indexing writeback marker, '!', just add it as a token
4334 // operand.
4335 if (Parser.getTok().is(AsmToken::Exclaim)) {
4336 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4337 Parser.Lex(); // Eat the '!'.
4338 }
4339
4340 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004341 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004342
4343 // The register offset is optionally preceded by a '+' or '-'
4344 bool isNegative = false;
4345 if (Parser.getTok().is(AsmToken::Minus)) {
4346 isNegative = true;
4347 Parser.Lex(); // Eat the '-'.
4348 } else if (Parser.getTok().is(AsmToken::Plus)) {
4349 // Nothing to do.
4350 Parser.Lex(); // Eat the '+'.
4351 }
4352
4353 E = Parser.getTok().getLoc();
4354 int OffsetRegNum = tryParseRegister();
4355 if (OffsetRegNum == -1)
4356 return Error(E, "register expected");
4357
4358 // If there's a shift operator, handle it.
4359 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004360 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004361 if (Parser.getTok().is(AsmToken::Comma)) {
4362 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004363 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004364 return true;
4365 }
4366
4367 // Now we should have the closing ']'
4368 E = Parser.getTok().getLoc();
4369 if (Parser.getTok().isNot(AsmToken::RBrac))
4370 return Error(E, "']' expected");
4371 Parser.Lex(); // Eat right bracket token.
4372
4373 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004374 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004375 S, E));
4376
Jim Grosbachc320c852011-08-05 21:28:30 +00004377 // If there's a pre-indexing writeback marker, '!', just add it as a token
4378 // operand.
4379 if (Parser.getTok().is(AsmToken::Exclaim)) {
4380 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4381 Parser.Lex(); // Eat the '!'.
4382 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004383
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004384 return false;
4385}
4386
Jim Grosbachd3595712011-08-03 23:50:40 +00004387/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004388/// ( lsl | lsr | asr | ror ) , # shift_amount
4389/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004390/// return true if it parses a shift otherwise it returns false.
4391bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4392 unsigned &Amount) {
4393 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004394 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004395 if (Tok.isNot(AsmToken::Identifier))
4396 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004397 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004398 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4399 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004400 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004401 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004402 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004403 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004404 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004405 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004406 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004407 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004408 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004409 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004410 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004411 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004412
Jim Grosbachd3595712011-08-03 23:50:40 +00004413 // rrx stands alone.
4414 Amount = 0;
4415 if (St != ARM_AM::rrx) {
4416 Loc = Parser.getTok().getLoc();
4417 // A '#' and a shift amount.
4418 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004419 if (HashTok.isNot(AsmToken::Hash) &&
4420 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004421 return Error(HashTok.getLoc(), "'#' expected");
4422 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004423
Jim Grosbachd3595712011-08-03 23:50:40 +00004424 const MCExpr *Expr;
4425 if (getParser().ParseExpression(Expr))
4426 return true;
4427 // Range check the immediate.
4428 // lsl, ror: 0 <= imm <= 31
4429 // lsr, asr: 0 <= imm <= 32
4430 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4431 if (!CE)
4432 return Error(Loc, "shift amount must be an immediate");
4433 int64_t Imm = CE->getValue();
4434 if (Imm < 0 ||
4435 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4436 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4437 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004438 // If <ShiftTy> #0, turn it into a no_shift.
4439 if (Imm == 0)
4440 St = ARM_AM::lsl;
4441 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4442 if (Imm == 32)
4443 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004444 Amount = Imm;
4445 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004446
4447 return false;
4448}
4449
Jim Grosbache7fbce72011-10-03 23:38:36 +00004450/// parseFPImm - A floating point immediate expression operand.
4451ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4452parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004453 // Anything that can accept a floating point constant as an operand
4454 // needs to go through here, as the regular ParseExpression is
4455 // integer only.
4456 //
4457 // This routine still creates a generic Immediate operand, containing
4458 // a bitcast of the 64-bit floating point value. The various operands
4459 // that accept floats can check whether the value is valid for them
4460 // via the standard is*() predicates.
4461
Jim Grosbache7fbce72011-10-03 23:38:36 +00004462 SMLoc S = Parser.getTok().getLoc();
4463
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004464 if (Parser.getTok().isNot(AsmToken::Hash) &&
4465 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004466 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004467
4468 // Disambiguate the VMOV forms that can accept an FP immediate.
4469 // vmov.f32 <sreg>, #imm
4470 // vmov.f64 <dreg>, #imm
4471 // vmov.f32 <dreg>, #imm @ vector f32x2
4472 // vmov.f32 <qreg>, #imm @ vector f32x4
4473 //
4474 // There are also the NEON VMOV instructions which expect an
4475 // integer constant. Make sure we don't try to parse an FPImm
4476 // for these:
4477 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4478 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4479 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4480 TyOp->getToken() != ".f64"))
4481 return MatchOperand_NoMatch;
4482
Jim Grosbache7fbce72011-10-03 23:38:36 +00004483 Parser.Lex(); // Eat the '#'.
4484
4485 // Handle negation, as that still comes through as a separate token.
4486 bool isNegative = false;
4487 if (Parser.getTok().is(AsmToken::Minus)) {
4488 isNegative = true;
4489 Parser.Lex();
4490 }
4491 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004492 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004493 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004494 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004495 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4496 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004497 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004498 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004499 Operands.push_back(ARMOperand::CreateImm(
4500 MCConstantExpr::Create(IntVal, getContext()),
4501 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004502 return MatchOperand_Success;
4503 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004504 // Also handle plain integers. Instructions which allow floating point
4505 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004506 if (Tok.is(AsmToken::Integer)) {
4507 int64_t Val = Tok.getIntVal();
4508 Parser.Lex(); // Eat the token.
4509 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004510 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004511 return MatchOperand_ParseFail;
4512 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004513 double RealVal = ARM_AM::getFPImmFloat(Val);
4514 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4515 Operands.push_back(ARMOperand::CreateImm(
4516 MCConstantExpr::Create(Val, getContext()), S,
4517 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004518 return MatchOperand_Success;
4519 }
4520
Jim Grosbach235c8d22012-01-19 02:47:30 +00004521 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004522 return MatchOperand_ParseFail;
4523}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004524
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004525/// Parse a arm instruction operand. For now this parses the operand regardless
4526/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004527bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004528 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004529 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004530
4531 // Check if the current operand has a custom associated parser, if so, try to
4532 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004533 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4534 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004535 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004536 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4537 // there was a match, but an error occurred, in which case, just return that
4538 // the operand parsing failed.
4539 if (ResTy == MatchOperand_ParseFail)
4540 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004541
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004542 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004543 default:
4544 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004545 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004546 case AsmToken::Identifier: {
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004547 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling2063b842010-11-18 23:43:05 +00004548 return false;
Jim Grosbach0d6022d2011-07-26 20:41:24 +00004549 int Res = tryParseShiftRegister(Operands);
Jim Grosbachbb24c592011-07-13 18:49:30 +00004550 if (Res == 0) // success
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004551 return false;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004552 else if (Res == -1) // irrecoverable error
4553 return true;
Jim Grosbach4eda1452011-12-20 22:26:38 +00004554 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachd28888d2012-03-15 21:34:14 +00004555 if (Mnemonic == "vmrs" &&
4556 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004557 S = Parser.getTok().getLoc();
4558 Parser.Lex();
Jim Grosbachd28888d2012-03-15 21:34:14 +00004559 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004560 return false;
4561 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004562
4563 // Fall though for the Identifier case that is not a register or a
4564 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004565 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004566 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004567 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004568 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004569 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004570 // This was not a register so parse other operands that start with an
4571 // identifier (like labels) as expressions and create them as immediates.
4572 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004573 S = Parser.getTok().getLoc();
Kevin Enderby146dcf22009-10-15 20:48:48 +00004574 if (getParser().ParseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004575 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004576 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004577 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4578 return false;
4579 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004580 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004581 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004582 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004583 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004584 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004585 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004586 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004587 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004588 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004589
4590 if (Parser.getTok().isNot(AsmToken::Colon)) {
4591 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4592 const MCExpr *ImmVal;
4593 if (getParser().ParseExpression(ImmVal))
4594 return true;
4595 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4596 if (CE) {
4597 int32_t Val = CE->getValue();
4598 if (isNegative && Val == 0)
4599 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4600 }
4601 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4602 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4603 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004604 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004605 // w/ a ':' after the '#', it's just like a plain ':'.
4606 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004607 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004608 case AsmToken::Colon: {
4609 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004610 // FIXME: Check it's an expression prefix,
4611 // e.g. (FOO - :lower16:BAR) isn't legal.
4612 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004613 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004614 return true;
4615
Evan Cheng965b3c72011-01-13 07:58:56 +00004616 const MCExpr *SubExprVal;
4617 if (getParser().ParseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004618 return true;
4619
Evan Cheng965b3c72011-01-13 07:58:56 +00004620 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004621 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004622 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004623 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004624 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004625 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004626 }
4627}
4628
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004629// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004630// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004631bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004632 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004633
4634 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004635 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004636 Parser.Lex(); // Eat ':'
4637
4638 if (getLexer().isNot(AsmToken::Identifier)) {
4639 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4640 return true;
4641 }
4642
4643 StringRef IDVal = Parser.getTok().getIdentifier();
4644 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004645 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004646 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004647 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004648 } else {
4649 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4650 return true;
4651 }
4652 Parser.Lex();
4653
4654 if (getLexer().isNot(AsmToken::Colon)) {
4655 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4656 return true;
4657 }
4658 Parser.Lex(); // Eat the last ':'
4659 return false;
4660}
4661
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004662/// \brief Given a mnemonic, split out possible predication code and carry
4663/// setting letters to form a canonical mnemonic and flags.
4664//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004665// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004666// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004667StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004668 unsigned &PredicationCode,
4669 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004670 unsigned &ProcessorIMod,
4671 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004672 PredicationCode = ARMCC::AL;
4673 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004674 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004675
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004676 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004677 //
4678 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004679 if ((Mnemonic == "movs" && isThumb()) ||
4680 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4681 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4682 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4683 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4684 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4685 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004686 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4687 Mnemonic == "fmuls")
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004688 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004689
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004690 // First, split out any predication code. Ignore mnemonics we know aren't
4691 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004692 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004693 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004694 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004695 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004696 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4697 .Case("eq", ARMCC::EQ)
4698 .Case("ne", ARMCC::NE)
4699 .Case("hs", ARMCC::HS)
4700 .Case("cs", ARMCC::HS)
4701 .Case("lo", ARMCC::LO)
4702 .Case("cc", ARMCC::LO)
4703 .Case("mi", ARMCC::MI)
4704 .Case("pl", ARMCC::PL)
4705 .Case("vs", ARMCC::VS)
4706 .Case("vc", ARMCC::VC)
4707 .Case("hi", ARMCC::HI)
4708 .Case("ls", ARMCC::LS)
4709 .Case("ge", ARMCC::GE)
4710 .Case("lt", ARMCC::LT)
4711 .Case("gt", ARMCC::GT)
4712 .Case("le", ARMCC::LE)
4713 .Case("al", ARMCC::AL)
4714 .Default(~0U);
4715 if (CC != ~0U) {
4716 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4717 PredicationCode = CC;
4718 }
Bill Wendling193961b2010-10-29 23:50:21 +00004719 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004720
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004721 // Next, determine if we have a carry setting bit. We explicitly ignore all
4722 // the instructions we know end in 's'.
4723 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004724 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004725 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4726 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4727 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004728 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004729 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004730 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004731 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004732 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004733 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004734 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4735 CarrySetting = true;
4736 }
4737
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004738 // The "cps" instruction can have a interrupt mode operand which is glued into
4739 // the mnemonic. Check if this is the case, split it and parse the imod op
4740 if (Mnemonic.startswith("cps")) {
4741 // Split out any imod code.
4742 unsigned IMod =
4743 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4744 .Case("ie", ARM_PROC::IE)
4745 .Case("id", ARM_PROC::ID)
4746 .Default(~0U);
4747 if (IMod != ~0U) {
4748 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4749 ProcessorIMod = IMod;
4750 }
4751 }
4752
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004753 // The "it" instruction has the condition mask on the end of the mnemonic.
4754 if (Mnemonic.startswith("it")) {
4755 ITMask = Mnemonic.slice(2, Mnemonic.size());
4756 Mnemonic = Mnemonic.slice(0, 2);
4757 }
4758
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004759 return Mnemonic;
4760}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004761
4762/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4763/// inclusion of carry set or predication code operands.
4764//
4765// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004766void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004767getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004768 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004769 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4770 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004771 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004772 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004773 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004774 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004775 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004776 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004777 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004778 Mnemonic == "mla" || Mnemonic == "smlal" ||
4779 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004780 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004781 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004782 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004783
Daniel Dunbar09264122011-01-11 19:06:29 +00004784 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4785 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4786 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4787 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbach803898f2011-09-06 20:27:04 +00004788 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4789 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach25977222011-08-19 23:24:36 +00004790 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach93981412011-10-11 21:55:36 +00004791 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4792 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4793 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbachb9d4e372011-08-26 22:21:51 +00004794 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4795 !isThumb()) ||
Jim Grosbachb908b7a2011-09-10 00:15:36 +00004796 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004797 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004798 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004799 CanAcceptPredicationCode = true;
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004800
Jim Grosbach6c45b752011-09-16 16:39:25 +00004801 if (isThumb()) {
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004802 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbachb98ab912011-06-30 22:10:46 +00004803 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopescf99dc72011-01-20 16:35:57 +00004804 CanAcceptPredicationCode = false;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004805 }
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004806}
4807
Jim Grosbach7283da92011-08-16 21:12:37 +00004808bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4809 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004810 // FIXME: This is all horribly hacky. We really need a better way to deal
4811 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004812
4813 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4814 // another does not. Specifically, the MOVW instruction does not. So we
4815 // special case it here and remove the defaulted (non-setting) cc_out
4816 // operand if that's the instruction we're trying to match.
4817 //
4818 // We do this as post-processing of the explicit operands rather than just
4819 // conditionally adding the cc_out in the first place because we need
4820 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004821 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004822 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4823 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4824 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4825 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004826
4827 // Register-register 'add' for thumb does not have a cc_out operand
4828 // when there are only two register operands.
4829 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4830 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4831 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4832 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4833 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004834 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004835 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4836 // have to check the immediate range here since Thumb2 has a variant
4837 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004838 if (((isThumb() && Mnemonic == "add") ||
4839 (isThumbTwo() && Mnemonic == "sub")) &&
4840 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004841 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4842 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4843 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004844 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004845 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004846 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004847 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004848 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4849 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004850 // selecting via the generic "add" mnemonic, so to know that we
4851 // should remove the cc_out operand, we have to explicitly check that
4852 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004853 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4854 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004855 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4856 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4857 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4858 // Nest conditions rather than one big 'if' statement for readability.
4859 //
4860 // If either register is a high reg, it's either one of the SP
4861 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004862 // check against T3. If the second register is the PC, this is an
4863 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004864 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4865 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach78dcaed2012-01-21 00:07:56 +00004866 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004867 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4868 return false;
4869 // If both registers are low, we're in an IT block, and the immediate is
4870 // in range, we should use encoding T1 instead, which has a cc_out.
4871 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004872 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004873 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4874 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4875 return false;
4876
4877 // Otherwise, we use encoding T4, which does not have a cc_out
4878 // operand.
4879 return true;
4880 }
4881
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004882 // The thumb2 multiply instruction doesn't have a CCOut register, so
4883 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4884 // use the 16-bit encoding or not.
4885 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4886 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4887 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4888 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4889 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4890 // If the registers aren't low regs, the destination reg isn't the
4891 // same as one of the source regs, or the cc_out operand is zero
4892 // outside of an IT block, we have to use the 32-bit encoding, so
4893 // remove the cc_out operand.
4894 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4895 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004896 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004897 !inITBlock() ||
4898 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4899 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4900 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4901 static_cast<ARMOperand*>(Operands[4])->getReg())))
4902 return true;
4903
Jim Grosbachefa7e952011-11-15 19:55:16 +00004904 // Also check the 'mul' syntax variant that doesn't specify an explicit
4905 // destination register.
4906 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4907 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4908 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4909 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4910 // If the registers aren't low regs or the cc_out operand is zero
4911 // outside of an IT block, we have to use the 32-bit encoding, so
4912 // remove the cc_out operand.
4913 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4914 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4915 !inITBlock()))
4916 return true;
4917
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004918
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004919
Jim Grosbach4b701af2011-08-24 21:42:27 +00004920 // Register-register 'add/sub' for thumb does not have a cc_out operand
4921 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4922 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4923 // right, this will result in better diagnostics (which operand is off)
4924 // anyway.
4925 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4926 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004927 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4928 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004929 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4930 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4931 (Operands.size() == 6 &&
4932 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004933 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004934
Jim Grosbach7283da92011-08-16 21:12:37 +00004935 return false;
4936}
4937
Jim Grosbach12952fe2011-11-11 23:08:10 +00004938static bool isDataTypeToken(StringRef Tok) {
4939 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4940 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4941 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4942 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4943 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4944 Tok == ".f" || Tok == ".d";
4945}
4946
4947// FIXME: This bit should probably be handled via an explicit match class
4948// in the .td files that matches the suffix instead of having it be
4949// a literal string token the way it is now.
4950static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4951 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4952}
4953
Jim Grosbach8be2f652011-12-09 23:34:09 +00004954static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004955/// Parse an arm instruction mnemonic followed by its operands.
4956bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4957 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004958 // Apply mnemonic aliases before doing anything else, as the destination
4959 // mnemnonic may include suffices and we want to handle them normally.
4960 // The generic tblgen'erated code does this later, at the start of
4961 // MatchInstructionImpl(), but that's too late for aliases that include
4962 // any sort of suffix.
4963 unsigned AvailableFeatures = getAvailableFeatures();
4964 applyMnemonicAliases(Name, AvailableFeatures);
4965
Jim Grosbachab5830e2011-12-14 02:16:11 +00004966 // First check for the ARM-specific .req directive.
4967 if (Parser.getTok().is(AsmToken::Identifier) &&
4968 Parser.getTok().getIdentifier() == ".req") {
4969 parseDirectiveReq(Name, NameLoc);
4970 // We always return 'error' for this, as we're done with this
4971 // statement and don't need to match the 'instruction."
4972 return true;
4973 }
4974
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004975 // Create the leading tokens for the mnemonic, split by '.' characters.
4976 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004977 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004978
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004979 // Split out the predication code and carry setting flag from the mnemonic.
4980 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004981 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004982 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004983 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004984 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004985 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004986
Jim Grosbach1c171b12011-08-25 17:23:55 +00004987 // In Thumb1, only the branch (B) instruction can be predicated.
4988 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4989 Parser.EatToEndOfStatement();
4990 return Error(NameLoc, "conditional execution not supported in Thumb1");
4991 }
4992
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004993 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4994
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004995 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4996 // is the mask as it will be for the IT encoding if the conditional
4997 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4998 // where the conditional bit0 is zero, the instruction post-processing
4999 // will adjust the mask accordingly.
5000 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005001 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5002 if (ITMask.size() > 3) {
5003 Parser.EatToEndOfStatement();
5004 return Error(Loc, "too many conditions on IT instruction");
5005 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005006 unsigned Mask = 8;
5007 for (unsigned i = ITMask.size(); i != 0; --i) {
5008 char pos = ITMask[i - 1];
5009 if (pos != 't' && pos != 'e') {
5010 Parser.EatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005011 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005012 }
5013 Mask >>= 1;
5014 if (ITMask[i - 1] == 't')
5015 Mask |= 8;
5016 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005017 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005018 }
5019
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005020 // FIXME: This is all a pretty gross hack. We should automatically handle
5021 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005022
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005023 // Next, add the CCOut and ConditionCode operands, if needed.
5024 //
5025 // For mnemonics which can ever incorporate a carry setting bit or predication
5026 // code, our matching model involves us always generating CCOut and
5027 // ConditionCode operands to match the mnemonic "as written" and then we let
5028 // the matcher deal with finding the right instruction or generating an
5029 // appropriate error.
5030 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005031 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005032
Jim Grosbach03a8a162011-07-14 22:04:21 +00005033 // If we had a carry-set on an instruction that can't do that, issue an
5034 // error.
5035 if (!CanAcceptCarrySet && CarrySetting) {
5036 Parser.EatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005037 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005038 "' can not set flags, but 's' suffix specified");
5039 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005040 // If we had a predication code on an instruction that can't do that, issue an
5041 // error.
5042 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5043 Parser.EatToEndOfStatement();
5044 return Error(NameLoc, "instruction '" + Mnemonic +
5045 "' is not predicable, but condition code specified");
5046 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005047
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005048 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005049 if (CanAcceptCarrySet) {
5050 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005051 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005052 Loc));
5053 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005054
5055 // Add the predication code operand, if necessary.
5056 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005057 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5058 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005059 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005060 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005061 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005062
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005063 // Add the processor imod operand, if necessary.
5064 if (ProcessorIMod) {
5065 Operands.push_back(ARMOperand::CreateImm(
5066 MCConstantExpr::Create(ProcessorIMod, getContext()),
5067 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005068 }
5069
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005070 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005071 while (Next != StringRef::npos) {
5072 Start = Next;
5073 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005074 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005075
Jim Grosbach12952fe2011-11-11 23:08:10 +00005076 // Some NEON instructions have an optional datatype suffix that is
5077 // completely ignored. Check for that.
5078 if (isDataTypeToken(ExtraToken) &&
5079 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5080 continue;
5081
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005082 if (ExtraToken != ".n") {
5083 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5084 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5085 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005086 }
5087
5088 // Read the remaining operands.
5089 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005090 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005091 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnera2a9d162010-09-11 16:18:25 +00005092 Parser.EatToEndOfStatement();
5093 return true;
5094 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005095
5096 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005097 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005098
5099 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005100 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnera2a9d162010-09-11 16:18:25 +00005101 Parser.EatToEndOfStatement();
5102 return true;
5103 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005104 }
5105 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005106
Chris Lattnera2a9d162010-09-11 16:18:25 +00005107 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005108 SMLoc Loc = getLexer().getLoc();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005109 Parser.EatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005110 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005111 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005112
Chris Lattner91689c12010-09-08 05:10:46 +00005113 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005114
Jim Grosbach7283da92011-08-16 21:12:37 +00005115 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5116 // do and don't have a cc_out optional-def operand. With some spot-checks
5117 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005118 // parse and adjust accordingly before actually matching. We shouldn't ever
5119 // try to remove a cc_out operand that was explicitly set on the the
5120 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5121 // table driven matcher doesn't fit well with the ARM instruction set.
5122 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005123 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5124 Operands.erase(Operands.begin() + 1);
5125 delete Op;
5126 }
5127
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005128 // ARM mode 'blx' need special handling, as the register operand version
5129 // is predicable, but the label operand version is not. So, we can't rely
5130 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005131 // a k_CondCode operand in the list. If we're trying to match the label
5132 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005133 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5134 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5135 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5136 Operands.erase(Operands.begin() + 1);
5137 delete Op;
5138 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005139
5140 // The vector-compare-to-zero instructions have a literal token "#0" at
5141 // the end that comes to here as an immediate operand. Convert it to a
5142 // token to play nicely with the matcher.
5143 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5144 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5145 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5146 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5147 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5148 if (CE && CE->getValue() == 0) {
5149 Operands.erase(Operands.begin() + 5);
5150 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5151 delete Op;
5152 }
5153 }
Jim Grosbach46b66462011-10-03 22:30:24 +00005154 // VCMP{E} does the same thing, but with a different operand count.
5155 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5156 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5157 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5158 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5159 if (CE && CE->getValue() == 0) {
5160 Operands.erase(Operands.begin() + 4);
5161 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5162 delete Op;
5163 }
5164 }
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005165 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005166 // end. Convert it to a token here. Take care not to convert those
5167 // that should hit the Thumb2 encoding.
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005168 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005169 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5170 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005171 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5172 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5173 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005174 if (CE && CE->getValue() == 0 &&
5175 (isThumbOne() ||
Jim Grosbach5ac89672011-12-13 21:06:41 +00005176 // The cc_out operand matches the IT block.
5177 ((inITBlock() != CarrySetting) &&
5178 // Neither register operand is a high register.
Jim Grosbach1f1a3592011-12-13 20:50:38 +00005179 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach5ac89672011-12-13 21:06:41 +00005180 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbachc3c32d92011-08-22 23:47:13 +00005181 Operands.erase(Operands.begin() + 5);
5182 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5183 delete Op;
5184 }
5185 }
5186
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005187 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005188}
5189
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005190// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005191
5192// return 'true' if register list contains non-low GPR registers,
5193// 'false' otherwise. If Reg is in the register list or is HiReg, set
5194// 'containsReg' to true.
5195static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5196 unsigned HiReg, bool &containsReg) {
5197 containsReg = false;
5198 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5199 unsigned OpReg = Inst.getOperand(i).getReg();
5200 if (OpReg == Reg)
5201 containsReg = true;
5202 // Anything other than a low register isn't legal here.
5203 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5204 return true;
5205 }
5206 return false;
5207}
5208
Jim Grosbacha31f2232011-09-07 18:05:34 +00005209// Check if the specified regisgter is in the register list of the inst,
5210// starting at the indicated operand number.
5211static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5212 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5213 unsigned OpReg = Inst.getOperand(i).getReg();
5214 if (OpReg == Reg)
5215 return true;
5216 }
5217 return false;
5218}
5219
Jim Grosbached16ec42011-08-29 22:24:09 +00005220// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5221// the ARMInsts array) instead. Getting that here requires awkward
5222// API changes, though. Better way?
5223namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005224extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005225}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005226static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005227 return ARMInsts[Opcode];
5228}
5229
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005230// FIXME: We would really like to be able to tablegen'erate this.
5231bool ARMAsmParser::
5232validateInstruction(MCInst &Inst,
5233 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005234 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005235 SMLoc Loc = Operands[0]->getStartLoc();
5236 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005237 // NOTE: BKPT instruction has the interesting property of being
5238 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005239 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005240 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5241 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005242 unsigned bit = 1;
5243 if (ITState.FirstCond)
5244 ITState.FirstCond = false;
5245 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005246 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005247 // The instruction must be predicable.
5248 if (!MCID.isPredicable())
5249 return Error(Loc, "instructions in IT block must be predicable");
5250 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5251 unsigned ITCond = bit ? ITState.Cond :
5252 ARMCC::getOppositeCondition(ITState.Cond);
5253 if (Cond != ITCond) {
5254 // Find the condition code Operand to get its SMLoc information.
5255 SMLoc CondLoc;
5256 for (unsigned i = 1; i < Operands.size(); ++i)
5257 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5258 CondLoc = Operands[i]->getStartLoc();
5259 return Error(CondLoc, "incorrect condition in IT block; got '" +
5260 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5261 "', but expected '" +
5262 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5263 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005264 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005265 } else if (isThumbTwo() && MCID.isPredicable() &&
5266 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005267 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5268 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005269 return Error(Loc, "predicated instructions must be in IT block");
5270
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005271 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005272 case ARM::LDRD:
5273 case ARM::LDRD_PRE:
5274 case ARM::LDRD_POST:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005275 case ARM::LDREXD: {
5276 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005277 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5278 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005279 if (Rt2 != Rt + 1)
5280 return Error(Operands[3]->getStartLoc(),
5281 "destination operands must be sequential");
5282 return false;
5283 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005284 case ARM::STRD: {
5285 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005286 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5287 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005288 if (Rt2 != Rt + 1)
5289 return Error(Operands[3]->getStartLoc(),
5290 "source operands must be sequential");
5291 return false;
5292 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005293 case ARM::STRD_PRE:
5294 case ARM::STRD_POST:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005295 case ARM::STREXD: {
5296 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005297 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5298 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005299 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005300 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005301 "source operands must be sequential");
5302 return false;
5303 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005304 case ARM::SBFX:
5305 case ARM::UBFX: {
5306 // width must be in range [1, 32-lsb]
5307 unsigned lsb = Inst.getOperand(2).getImm();
5308 unsigned widthm1 = Inst.getOperand(3).getImm();
5309 if (widthm1 >= 32 - lsb)
5310 return Error(Operands[5]->getStartLoc(),
5311 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005312 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005313 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005314 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005315 // If we're parsing Thumb2, the .w variant is available and handles
5316 // most cases that are normally illegal for a Thumb1 LDM
5317 // instruction. We'll make the transformation in processInstruction()
5318 // if necessary.
5319 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005320 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005321 // in the register list.
5322 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005323 bool hasWritebackToken =
5324 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5325 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005326 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005327 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005328 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5329 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005330 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005331 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005332 return Error(Operands[2]->getStartLoc(),
5333 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005334 // If we should not have writeback, there must not be a '!'. This is
5335 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005336 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005337 return Error(Operands[3]->getStartLoc(),
5338 "writeback operator '!' not allowed when base register "
5339 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005340
5341 break;
5342 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005343 case ARM::t2LDMIA_UPD: {
5344 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5345 return Error(Operands[4]->getStartLoc(),
5346 "writeback operator '!' not allowed when base register "
5347 "in register list");
5348 break;
5349 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005350 case ARM::tMUL: {
5351 // The second source operand must be the same register as the destination
5352 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005353 //
5354 // In this case, we must directly check the parsed operands because the
5355 // cvtThumbMultiply() function is written in such a way that it guarantees
5356 // this first statement is always true for the new Inst. Essentially, the
5357 // destination is unconditionally copied into the second source operand
5358 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005359 if (Operands.size() == 6 &&
5360 (((ARMOperand*)Operands[3])->getReg() !=
5361 ((ARMOperand*)Operands[5])->getReg()) &&
5362 (((ARMOperand*)Operands[3])->getReg() !=
5363 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005364 return Error(Operands[3]->getStartLoc(),
5365 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005366 }
5367 break;
5368 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005369 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5370 // so only issue a diagnostic for thumb1. The instructions will be
5371 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005372 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005373 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005374 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5375 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005376 return Error(Operands[2]->getStartLoc(),
5377 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005378 break;
5379 }
5380 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005381 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005382 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5383 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005384 return Error(Operands[2]->getStartLoc(),
5385 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005386 break;
5387 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005388 case ARM::tSTMIA_UPD: {
5389 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005390 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005391 return Error(Operands[4]->getStartLoc(),
5392 "registers must be in range r0-r7");
5393 break;
5394 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005395 case ARM::tADDrSP: {
5396 // If the non-SP source operand and the destination operand are not the
5397 // same, we need thumb2 (for the wide encoding), or we have an error.
5398 if (!isThumbTwo() &&
5399 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5400 return Error(Operands[4]->getStartLoc(),
5401 "source register must be the same as destination");
5402 }
5403 break;
5404 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005405 }
5406
5407 return false;
5408}
5409
Jim Grosbach1a747242012-01-23 23:45:44 +00005410static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005411 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005412 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005413 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005414 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5415 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5416 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5417 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5418 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5419 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5420 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5421 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5422 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005423
5424 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005425 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5426 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5427 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5428 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5429 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005430
Jim Grosbach1e946a42012-01-24 00:43:12 +00005431 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5432 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5433 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5434 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5435 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005436
Jim Grosbach1e946a42012-01-24 00:43:12 +00005437 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5438 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5439 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5440 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5441 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005442
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005443 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005444 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5445 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5446 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5447 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5448 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5449 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5450 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5451 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5452 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5453 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5454 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5455 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5456 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5457 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5458 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005459
Jim Grosbach1a747242012-01-23 23:45:44 +00005460 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005461 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5462 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5463 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5464 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5465 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5466 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5467 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5468 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5469 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5470 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5471 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5472 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5473 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5474 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5475 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5476 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5477 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5478 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005479
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005480 // VST4LN
5481 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5482 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5483 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5484 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5485 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5486 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5487 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5488 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5489 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5490 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5491 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5492 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5493 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5494 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5495 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5496
Jim Grosbachda70eac2012-01-24 00:58:13 +00005497 // VST4
5498 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5499 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5500 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5501 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5502 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5503 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5504 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5505 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5506 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5507 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5508 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5509 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5510 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5511 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5512 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5513 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5514 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5515 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005516 }
5517}
5518
Jim Grosbach1a747242012-01-23 23:45:44 +00005519static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005520 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005521 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005522 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005523 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5524 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5525 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5526 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5527 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5528 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5529 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5530 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5531 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005532
5533 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005534 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5535 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5536 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5537 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5538 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5539 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5540 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5541 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5542 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5543 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5544 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5545 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5546 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5547 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5548 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005549
Jim Grosbachb78403c2012-01-24 23:47:04 +00005550 // VLD3DUP
5551 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5552 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5553 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5554 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5555 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5556 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5557 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5558 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5559 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5560 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5561 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5562 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5563 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5564 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5565 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5566 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5567 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5568 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5569
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005570 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005571 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5572 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5573 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5574 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5575 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5576 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5577 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5578 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5579 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5580 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5581 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5582 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5583 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5584 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5585 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005586
5587 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005588 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5589 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5590 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5591 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5592 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5593 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5594 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5595 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5596 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5597 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5598 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5599 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5600 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5601 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5602 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5603 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5604 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5605 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005606
Jim Grosbach14952a02012-01-24 18:37:25 +00005607 // VLD4LN
5608 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5609 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5610 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5611 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5612 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5613 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5614 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5615 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5616 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5617 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5618 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5619 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5620 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5621 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5622 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5623
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005624 // VLD4DUP
5625 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5626 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5627 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5628 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5629 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5630 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5631 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5632 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5633 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5634 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5635 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5636 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5637 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5638 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5639 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5640 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5641 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5642 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5643
Jim Grosbached561fc2012-01-24 00:43:17 +00005644 // VLD4
5645 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5646 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5647 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5648 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5649 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5650 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5651 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5652 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5653 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5654 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5655 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5656 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5657 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5658 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5659 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5660 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5661 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5662 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005663 }
5664}
5665
Jim Grosbachafad0532011-11-10 23:42:14 +00005666bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005667processInstruction(MCInst &Inst,
5668 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5669 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005670 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5671 case ARM::ADDri: {
5672 if (Inst.getOperand(1).getReg() != ARM::PC ||
5673 Inst.getOperand(5).getReg() != 0)
5674 return false;
5675 MCInst TmpInst;
5676 TmpInst.setOpcode(ARM::ADR);
5677 TmpInst.addOperand(Inst.getOperand(0));
5678 TmpInst.addOperand(Inst.getOperand(2));
5679 TmpInst.addOperand(Inst.getOperand(3));
5680 TmpInst.addOperand(Inst.getOperand(4));
5681 Inst = TmpInst;
5682 return true;
5683 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005684 // Aliases for alternate PC+imm syntax of LDR instructions.
5685 case ARM::t2LDRpcrel:
5686 Inst.setOpcode(ARM::t2LDRpci);
5687 return true;
5688 case ARM::t2LDRBpcrel:
5689 Inst.setOpcode(ARM::t2LDRBpci);
5690 return true;
5691 case ARM::t2LDRHpcrel:
5692 Inst.setOpcode(ARM::t2LDRHpci);
5693 return true;
5694 case ARM::t2LDRSBpcrel:
5695 Inst.setOpcode(ARM::t2LDRSBpci);
5696 return true;
5697 case ARM::t2LDRSHpcrel:
5698 Inst.setOpcode(ARM::t2LDRSHpci);
5699 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005700 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005701 case ARM::VST1LNdWB_register_Asm_8:
5702 case ARM::VST1LNdWB_register_Asm_16:
5703 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005704 MCInst TmpInst;
5705 // Shuffle the operands around so the lane index operand is in the
5706 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005707 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005708 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005709 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5710 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5711 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5712 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5713 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5714 TmpInst.addOperand(Inst.getOperand(1)); // lane
5715 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5716 TmpInst.addOperand(Inst.getOperand(6));
5717 Inst = TmpInst;
5718 return true;
5719 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005720
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005721 case ARM::VST2LNdWB_register_Asm_8:
5722 case ARM::VST2LNdWB_register_Asm_16:
5723 case ARM::VST2LNdWB_register_Asm_32:
5724 case ARM::VST2LNqWB_register_Asm_16:
5725 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005726 MCInst TmpInst;
5727 // Shuffle the operands around so the lane index operand is in the
5728 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005729 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005730 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005731 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5732 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5733 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5734 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5735 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005736 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5737 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005738 TmpInst.addOperand(Inst.getOperand(1)); // lane
5739 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5740 TmpInst.addOperand(Inst.getOperand(6));
5741 Inst = TmpInst;
5742 return true;
5743 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005744
5745 case ARM::VST3LNdWB_register_Asm_8:
5746 case ARM::VST3LNdWB_register_Asm_16:
5747 case ARM::VST3LNdWB_register_Asm_32:
5748 case ARM::VST3LNqWB_register_Asm_16:
5749 case ARM::VST3LNqWB_register_Asm_32: {
5750 MCInst TmpInst;
5751 // Shuffle the operands around so the lane index operand is in the
5752 // right place.
5753 unsigned Spacing;
5754 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5755 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5756 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5757 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5758 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5759 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5760 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5761 Spacing));
5762 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5763 Spacing * 2));
5764 TmpInst.addOperand(Inst.getOperand(1)); // lane
5765 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5766 TmpInst.addOperand(Inst.getOperand(6));
5767 Inst = TmpInst;
5768 return true;
5769 }
5770
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005771 case ARM::VST4LNdWB_register_Asm_8:
5772 case ARM::VST4LNdWB_register_Asm_16:
5773 case ARM::VST4LNdWB_register_Asm_32:
5774 case ARM::VST4LNqWB_register_Asm_16:
5775 case ARM::VST4LNqWB_register_Asm_32: {
5776 MCInst TmpInst;
5777 // Shuffle the operands around so the lane index operand is in the
5778 // right place.
5779 unsigned Spacing;
5780 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5781 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5782 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5783 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5784 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5785 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5786 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5787 Spacing));
5788 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5789 Spacing * 2));
5790 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5791 Spacing * 3));
5792 TmpInst.addOperand(Inst.getOperand(1)); // lane
5793 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5794 TmpInst.addOperand(Inst.getOperand(6));
5795 Inst = TmpInst;
5796 return true;
5797 }
5798
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005799 case ARM::VST1LNdWB_fixed_Asm_8:
5800 case ARM::VST1LNdWB_fixed_Asm_16:
5801 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005802 MCInst TmpInst;
5803 // Shuffle the operands around so the lane index operand is in the
5804 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005805 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005806 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005807 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5808 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5809 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5810 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5811 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5812 TmpInst.addOperand(Inst.getOperand(1)); // lane
5813 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5814 TmpInst.addOperand(Inst.getOperand(5));
5815 Inst = TmpInst;
5816 return true;
5817 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005818
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005819 case ARM::VST2LNdWB_fixed_Asm_8:
5820 case ARM::VST2LNdWB_fixed_Asm_16:
5821 case ARM::VST2LNdWB_fixed_Asm_32:
5822 case ARM::VST2LNqWB_fixed_Asm_16:
5823 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005824 MCInst TmpInst;
5825 // Shuffle the operands around so the lane index operand is in the
5826 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005827 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005828 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005829 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5830 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5831 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5832 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5833 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005834 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5835 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005836 TmpInst.addOperand(Inst.getOperand(1)); // lane
5837 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5838 TmpInst.addOperand(Inst.getOperand(5));
5839 Inst = TmpInst;
5840 return true;
5841 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005842
5843 case ARM::VST3LNdWB_fixed_Asm_8:
5844 case ARM::VST3LNdWB_fixed_Asm_16:
5845 case ARM::VST3LNdWB_fixed_Asm_32:
5846 case ARM::VST3LNqWB_fixed_Asm_16:
5847 case ARM::VST3LNqWB_fixed_Asm_32: {
5848 MCInst TmpInst;
5849 // Shuffle the operands around so the lane index operand is in the
5850 // right place.
5851 unsigned Spacing;
5852 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5853 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5854 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5855 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5856 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5857 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5859 Spacing));
5860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5861 Spacing * 2));
5862 TmpInst.addOperand(Inst.getOperand(1)); // lane
5863 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5864 TmpInst.addOperand(Inst.getOperand(5));
5865 Inst = TmpInst;
5866 return true;
5867 }
5868
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005869 case ARM::VST4LNdWB_fixed_Asm_8:
5870 case ARM::VST4LNdWB_fixed_Asm_16:
5871 case ARM::VST4LNdWB_fixed_Asm_32:
5872 case ARM::VST4LNqWB_fixed_Asm_16:
5873 case ARM::VST4LNqWB_fixed_Asm_32: {
5874 MCInst TmpInst;
5875 // Shuffle the operands around so the lane index operand is in the
5876 // right place.
5877 unsigned Spacing;
5878 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5879 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5880 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5881 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5882 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5883 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5885 Spacing));
5886 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5887 Spacing * 2));
5888 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5889 Spacing * 3));
5890 TmpInst.addOperand(Inst.getOperand(1)); // lane
5891 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5892 TmpInst.addOperand(Inst.getOperand(5));
5893 Inst = TmpInst;
5894 return true;
5895 }
5896
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005897 case ARM::VST1LNdAsm_8:
5898 case ARM::VST1LNdAsm_16:
5899 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005900 MCInst TmpInst;
5901 // Shuffle the operands around so the lane index operand is in the
5902 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005903 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005904 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005905 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5906 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5907 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5908 TmpInst.addOperand(Inst.getOperand(1)); // lane
5909 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5910 TmpInst.addOperand(Inst.getOperand(5));
5911 Inst = TmpInst;
5912 return true;
5913 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005914
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005915 case ARM::VST2LNdAsm_8:
5916 case ARM::VST2LNdAsm_16:
5917 case ARM::VST2LNdAsm_32:
5918 case ARM::VST2LNqAsm_16:
5919 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005920 MCInst TmpInst;
5921 // Shuffle the operands around so the lane index operand is in the
5922 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005923 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005924 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005925 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5926 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5927 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005928 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5929 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005930 TmpInst.addOperand(Inst.getOperand(1)); // lane
5931 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5932 TmpInst.addOperand(Inst.getOperand(5));
5933 Inst = TmpInst;
5934 return true;
5935 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005936
5937 case ARM::VST3LNdAsm_8:
5938 case ARM::VST3LNdAsm_16:
5939 case ARM::VST3LNdAsm_32:
5940 case ARM::VST3LNqAsm_16:
5941 case ARM::VST3LNqAsm_32: {
5942 MCInst TmpInst;
5943 // Shuffle the operands around so the lane index operand is in the
5944 // right place.
5945 unsigned Spacing;
5946 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5947 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5948 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5949 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5950 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5951 Spacing));
5952 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5953 Spacing * 2));
5954 TmpInst.addOperand(Inst.getOperand(1)); // lane
5955 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5956 TmpInst.addOperand(Inst.getOperand(5));
5957 Inst = TmpInst;
5958 return true;
5959 }
5960
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005961 case ARM::VST4LNdAsm_8:
5962 case ARM::VST4LNdAsm_16:
5963 case ARM::VST4LNdAsm_32:
5964 case ARM::VST4LNqAsm_16:
5965 case ARM::VST4LNqAsm_32: {
5966 MCInst TmpInst;
5967 // Shuffle the operands around so the lane index operand is in the
5968 // right place.
5969 unsigned Spacing;
5970 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5971 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5972 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5973 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5974 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5975 Spacing));
5976 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5977 Spacing * 2));
5978 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5979 Spacing * 3));
5980 TmpInst.addOperand(Inst.getOperand(1)); // lane
5981 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5982 TmpInst.addOperand(Inst.getOperand(5));
5983 Inst = TmpInst;
5984 return true;
5985 }
5986
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005987 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005988 case ARM::VLD1LNdWB_register_Asm_8:
5989 case ARM::VLD1LNdWB_register_Asm_16:
5990 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00005991 MCInst TmpInst;
5992 // Shuffle the operands around so the lane index operand is in the
5993 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005994 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005995 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00005996 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5997 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5998 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5999 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6000 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6001 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6002 TmpInst.addOperand(Inst.getOperand(1)); // lane
6003 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6004 TmpInst.addOperand(Inst.getOperand(6));
6005 Inst = TmpInst;
6006 return true;
6007 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006008
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006009 case ARM::VLD2LNdWB_register_Asm_8:
6010 case ARM::VLD2LNdWB_register_Asm_16:
6011 case ARM::VLD2LNdWB_register_Asm_32:
6012 case ARM::VLD2LNqWB_register_Asm_16:
6013 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006014 MCInst TmpInst;
6015 // Shuffle the operands around so the lane index operand is in the
6016 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006017 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006018 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006019 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006020 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6021 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006022 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6023 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6024 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6025 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6026 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006027 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6028 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006029 TmpInst.addOperand(Inst.getOperand(1)); // lane
6030 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6031 TmpInst.addOperand(Inst.getOperand(6));
6032 Inst = TmpInst;
6033 return true;
6034 }
6035
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006036 case ARM::VLD3LNdWB_register_Asm_8:
6037 case ARM::VLD3LNdWB_register_Asm_16:
6038 case ARM::VLD3LNdWB_register_Asm_32:
6039 case ARM::VLD3LNqWB_register_Asm_16:
6040 case ARM::VLD3LNqWB_register_Asm_32: {
6041 MCInst TmpInst;
6042 // Shuffle the operands around so the lane index operand is in the
6043 // right place.
6044 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006045 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006046 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6047 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6048 Spacing));
6049 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006050 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006051 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6052 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6053 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6054 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6055 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6056 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6057 Spacing));
6058 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006059 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006060 TmpInst.addOperand(Inst.getOperand(1)); // lane
6061 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6062 TmpInst.addOperand(Inst.getOperand(6));
6063 Inst = TmpInst;
6064 return true;
6065 }
6066
Jim Grosbach14952a02012-01-24 18:37:25 +00006067 case ARM::VLD4LNdWB_register_Asm_8:
6068 case ARM::VLD4LNdWB_register_Asm_16:
6069 case ARM::VLD4LNdWB_register_Asm_32:
6070 case ARM::VLD4LNqWB_register_Asm_16:
6071 case ARM::VLD4LNqWB_register_Asm_32: {
6072 MCInst TmpInst;
6073 // Shuffle the operands around so the lane index operand is in the
6074 // right place.
6075 unsigned Spacing;
6076 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6077 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6078 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6079 Spacing));
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6081 Spacing * 2));
6082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6083 Spacing * 3));
6084 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6085 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6086 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6087 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6088 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6089 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6090 Spacing));
6091 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6092 Spacing * 2));
6093 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6094 Spacing * 3));
6095 TmpInst.addOperand(Inst.getOperand(1)); // lane
6096 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6097 TmpInst.addOperand(Inst.getOperand(6));
6098 Inst = TmpInst;
6099 return true;
6100 }
6101
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006102 case ARM::VLD1LNdWB_fixed_Asm_8:
6103 case ARM::VLD1LNdWB_fixed_Asm_16:
6104 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006105 MCInst TmpInst;
6106 // Shuffle the operands around so the lane index operand is in the
6107 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006108 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006109 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006110 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6111 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6112 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6113 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6114 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6115 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6116 TmpInst.addOperand(Inst.getOperand(1)); // lane
6117 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6118 TmpInst.addOperand(Inst.getOperand(5));
6119 Inst = TmpInst;
6120 return true;
6121 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006122
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006123 case ARM::VLD2LNdWB_fixed_Asm_8:
6124 case ARM::VLD2LNdWB_fixed_Asm_16:
6125 case ARM::VLD2LNdWB_fixed_Asm_32:
6126 case ARM::VLD2LNqWB_fixed_Asm_16:
6127 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006128 MCInst TmpInst;
6129 // Shuffle the operands around so the lane index operand is in the
6130 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006131 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006132 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006133 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006134 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6135 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006136 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6137 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6138 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6139 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6140 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006141 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6142 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006143 TmpInst.addOperand(Inst.getOperand(1)); // lane
6144 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6145 TmpInst.addOperand(Inst.getOperand(5));
6146 Inst = TmpInst;
6147 return true;
6148 }
6149
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006150 case ARM::VLD3LNdWB_fixed_Asm_8:
6151 case ARM::VLD3LNdWB_fixed_Asm_16:
6152 case ARM::VLD3LNdWB_fixed_Asm_32:
6153 case ARM::VLD3LNqWB_fixed_Asm_16:
6154 case ARM::VLD3LNqWB_fixed_Asm_32: {
6155 MCInst TmpInst;
6156 // Shuffle the operands around so the lane index operand is in the
6157 // right place.
6158 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006159 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006160 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6161 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6162 Spacing));
6163 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006164 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006165 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6166 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6167 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6168 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6169 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6171 Spacing));
6172 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006173 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006174 TmpInst.addOperand(Inst.getOperand(1)); // lane
6175 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6176 TmpInst.addOperand(Inst.getOperand(5));
6177 Inst = TmpInst;
6178 return true;
6179 }
6180
Jim Grosbach14952a02012-01-24 18:37:25 +00006181 case ARM::VLD4LNdWB_fixed_Asm_8:
6182 case ARM::VLD4LNdWB_fixed_Asm_16:
6183 case ARM::VLD4LNdWB_fixed_Asm_32:
6184 case ARM::VLD4LNqWB_fixed_Asm_16:
6185 case ARM::VLD4LNqWB_fixed_Asm_32: {
6186 MCInst TmpInst;
6187 // Shuffle the operands around so the lane index operand is in the
6188 // right place.
6189 unsigned Spacing;
6190 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6191 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6192 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6193 Spacing));
6194 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6195 Spacing * 2));
6196 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6197 Spacing * 3));
6198 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6199 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6200 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6201 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6202 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6203 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6204 Spacing));
6205 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6206 Spacing * 2));
6207 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6208 Spacing * 3));
6209 TmpInst.addOperand(Inst.getOperand(1)); // lane
6210 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6211 TmpInst.addOperand(Inst.getOperand(5));
6212 Inst = TmpInst;
6213 return true;
6214 }
6215
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006216 case ARM::VLD1LNdAsm_8:
6217 case ARM::VLD1LNdAsm_16:
6218 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006219 MCInst TmpInst;
6220 // Shuffle the operands around so the lane index operand is in the
6221 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006222 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006223 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006224 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6225 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6226 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6227 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6228 TmpInst.addOperand(Inst.getOperand(1)); // lane
6229 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6230 TmpInst.addOperand(Inst.getOperand(5));
6231 Inst = TmpInst;
6232 return true;
6233 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006234
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006235 case ARM::VLD2LNdAsm_8:
6236 case ARM::VLD2LNdAsm_16:
6237 case ARM::VLD2LNdAsm_32:
6238 case ARM::VLD2LNqAsm_16:
6239 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006240 MCInst TmpInst;
6241 // Shuffle the operands around so the lane index operand is in the
6242 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006243 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006244 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006245 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006246 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6247 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006248 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6249 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6250 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6252 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006253 TmpInst.addOperand(Inst.getOperand(1)); // lane
6254 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6255 TmpInst.addOperand(Inst.getOperand(5));
6256 Inst = TmpInst;
6257 return true;
6258 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006259
6260 case ARM::VLD3LNdAsm_8:
6261 case ARM::VLD3LNdAsm_16:
6262 case ARM::VLD3LNdAsm_32:
6263 case ARM::VLD3LNqAsm_16:
6264 case ARM::VLD3LNqAsm_32: {
6265 MCInst TmpInst;
6266 // Shuffle the operands around so the lane index operand is in the
6267 // right place.
6268 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006269 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006270 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6271 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6272 Spacing));
6273 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006274 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006275 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6276 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6277 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6278 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6279 Spacing));
6280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006281 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006282 TmpInst.addOperand(Inst.getOperand(1)); // lane
6283 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6284 TmpInst.addOperand(Inst.getOperand(5));
6285 Inst = TmpInst;
6286 return true;
6287 }
6288
Jim Grosbach14952a02012-01-24 18:37:25 +00006289 case ARM::VLD4LNdAsm_8:
6290 case ARM::VLD4LNdAsm_16:
6291 case ARM::VLD4LNdAsm_32:
6292 case ARM::VLD4LNqAsm_16:
6293 case ARM::VLD4LNqAsm_32: {
6294 MCInst TmpInst;
6295 // Shuffle the operands around so the lane index operand is in the
6296 // right place.
6297 unsigned Spacing;
6298 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6299 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6301 Spacing));
6302 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6303 Spacing * 2));
6304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6305 Spacing * 3));
6306 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6307 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6308 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6309 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6310 Spacing));
6311 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6312 Spacing * 2));
6313 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6314 Spacing * 3));
6315 TmpInst.addOperand(Inst.getOperand(1)); // lane
6316 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6317 TmpInst.addOperand(Inst.getOperand(5));
6318 Inst = TmpInst;
6319 return true;
6320 }
6321
Jim Grosbachb78403c2012-01-24 23:47:04 +00006322 // VLD3DUP single 3-element structure to all lanes instructions.
6323 case ARM::VLD3DUPdAsm_8:
6324 case ARM::VLD3DUPdAsm_16:
6325 case ARM::VLD3DUPdAsm_32:
6326 case ARM::VLD3DUPqAsm_8:
6327 case ARM::VLD3DUPqAsm_16:
6328 case ARM::VLD3DUPqAsm_32: {
6329 MCInst TmpInst;
6330 unsigned Spacing;
6331 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6332 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6334 Spacing));
6335 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6336 Spacing * 2));
6337 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6338 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6339 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6340 TmpInst.addOperand(Inst.getOperand(4));
6341 Inst = TmpInst;
6342 return true;
6343 }
6344
6345 case ARM::VLD3DUPdWB_fixed_Asm_8:
6346 case ARM::VLD3DUPdWB_fixed_Asm_16:
6347 case ARM::VLD3DUPdWB_fixed_Asm_32:
6348 case ARM::VLD3DUPqWB_fixed_Asm_8:
6349 case ARM::VLD3DUPqWB_fixed_Asm_16:
6350 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6351 MCInst TmpInst;
6352 unsigned Spacing;
6353 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6354 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6355 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6356 Spacing));
6357 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6358 Spacing * 2));
6359 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6360 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6361 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6362 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6363 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6364 TmpInst.addOperand(Inst.getOperand(4));
6365 Inst = TmpInst;
6366 return true;
6367 }
6368
6369 case ARM::VLD3DUPdWB_register_Asm_8:
6370 case ARM::VLD3DUPdWB_register_Asm_16:
6371 case ARM::VLD3DUPdWB_register_Asm_32:
6372 case ARM::VLD3DUPqWB_register_Asm_8:
6373 case ARM::VLD3DUPqWB_register_Asm_16:
6374 case ARM::VLD3DUPqWB_register_Asm_32: {
6375 MCInst TmpInst;
6376 unsigned Spacing;
6377 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6378 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6379 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6380 Spacing));
6381 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6382 Spacing * 2));
6383 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6384 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6385 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6386 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6387 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6388 TmpInst.addOperand(Inst.getOperand(5));
6389 Inst = TmpInst;
6390 return true;
6391 }
6392
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006393 // VLD3 multiple 3-element structure instructions.
6394 case ARM::VLD3dAsm_8:
6395 case ARM::VLD3dAsm_16:
6396 case ARM::VLD3dAsm_32:
6397 case ARM::VLD3qAsm_8:
6398 case ARM::VLD3qAsm_16:
6399 case ARM::VLD3qAsm_32: {
6400 MCInst TmpInst;
6401 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006402 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006403 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6405 Spacing));
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6407 Spacing * 2));
6408 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6409 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6410 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6411 TmpInst.addOperand(Inst.getOperand(4));
6412 Inst = TmpInst;
6413 return true;
6414 }
6415
6416 case ARM::VLD3dWB_fixed_Asm_8:
6417 case ARM::VLD3dWB_fixed_Asm_16:
6418 case ARM::VLD3dWB_fixed_Asm_32:
6419 case ARM::VLD3qWB_fixed_Asm_8:
6420 case ARM::VLD3qWB_fixed_Asm_16:
6421 case ARM::VLD3qWB_fixed_Asm_32: {
6422 MCInst TmpInst;
6423 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006424 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006425 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6426 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6427 Spacing));
6428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6429 Spacing * 2));
6430 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6431 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6432 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6433 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6434 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6435 TmpInst.addOperand(Inst.getOperand(4));
6436 Inst = TmpInst;
6437 return true;
6438 }
6439
6440 case ARM::VLD3dWB_register_Asm_8:
6441 case ARM::VLD3dWB_register_Asm_16:
6442 case ARM::VLD3dWB_register_Asm_32:
6443 case ARM::VLD3qWB_register_Asm_8:
6444 case ARM::VLD3qWB_register_Asm_16:
6445 case ARM::VLD3qWB_register_Asm_32: {
6446 MCInst TmpInst;
6447 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006448 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006449 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6450 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6451 Spacing));
6452 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6453 Spacing * 2));
6454 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6455 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6456 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6457 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6458 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6459 TmpInst.addOperand(Inst.getOperand(5));
6460 Inst = TmpInst;
6461 return true;
6462 }
6463
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006464 // VLD4DUP single 3-element structure to all lanes instructions.
6465 case ARM::VLD4DUPdAsm_8:
6466 case ARM::VLD4DUPdAsm_16:
6467 case ARM::VLD4DUPdAsm_32:
6468 case ARM::VLD4DUPqAsm_8:
6469 case ARM::VLD4DUPqAsm_16:
6470 case ARM::VLD4DUPqAsm_32: {
6471 MCInst TmpInst;
6472 unsigned Spacing;
6473 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6474 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 Spacing));
6477 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6478 Spacing * 2));
6479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6480 Spacing * 3));
6481 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6482 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6483 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6484 TmpInst.addOperand(Inst.getOperand(4));
6485 Inst = TmpInst;
6486 return true;
6487 }
6488
6489 case ARM::VLD4DUPdWB_fixed_Asm_8:
6490 case ARM::VLD4DUPdWB_fixed_Asm_16:
6491 case ARM::VLD4DUPdWB_fixed_Asm_32:
6492 case ARM::VLD4DUPqWB_fixed_Asm_8:
6493 case ARM::VLD4DUPqWB_fixed_Asm_16:
6494 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6495 MCInst TmpInst;
6496 unsigned Spacing;
6497 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6498 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6500 Spacing));
6501 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6502 Spacing * 2));
6503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6504 Spacing * 3));
6505 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6506 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6507 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6508 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6509 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6510 TmpInst.addOperand(Inst.getOperand(4));
6511 Inst = TmpInst;
6512 return true;
6513 }
6514
6515 case ARM::VLD4DUPdWB_register_Asm_8:
6516 case ARM::VLD4DUPdWB_register_Asm_16:
6517 case ARM::VLD4DUPdWB_register_Asm_32:
6518 case ARM::VLD4DUPqWB_register_Asm_8:
6519 case ARM::VLD4DUPqWB_register_Asm_16:
6520 case ARM::VLD4DUPqWB_register_Asm_32: {
6521 MCInst TmpInst;
6522 unsigned Spacing;
6523 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6524 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6525 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6526 Spacing));
6527 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6528 Spacing * 2));
6529 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6530 Spacing * 3));
6531 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6532 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6533 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6534 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6535 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6536 TmpInst.addOperand(Inst.getOperand(5));
6537 Inst = TmpInst;
6538 return true;
6539 }
6540
6541 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006542 case ARM::VLD4dAsm_8:
6543 case ARM::VLD4dAsm_16:
6544 case ARM::VLD4dAsm_32:
6545 case ARM::VLD4qAsm_8:
6546 case ARM::VLD4qAsm_16:
6547 case ARM::VLD4qAsm_32: {
6548 MCInst TmpInst;
6549 unsigned Spacing;
6550 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6551 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6552 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6553 Spacing));
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6555 Spacing * 2));
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6557 Spacing * 3));
6558 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6559 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6560 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6561 TmpInst.addOperand(Inst.getOperand(4));
6562 Inst = TmpInst;
6563 return true;
6564 }
6565
6566 case ARM::VLD4dWB_fixed_Asm_8:
6567 case ARM::VLD4dWB_fixed_Asm_16:
6568 case ARM::VLD4dWB_fixed_Asm_32:
6569 case ARM::VLD4qWB_fixed_Asm_8:
6570 case ARM::VLD4qWB_fixed_Asm_16:
6571 case ARM::VLD4qWB_fixed_Asm_32: {
6572 MCInst TmpInst;
6573 unsigned Spacing;
6574 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6575 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 Spacing));
6578 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6579 Spacing * 2));
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6581 Spacing * 3));
6582 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6583 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6584 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6585 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6586 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6587 TmpInst.addOperand(Inst.getOperand(4));
6588 Inst = TmpInst;
6589 return true;
6590 }
6591
6592 case ARM::VLD4dWB_register_Asm_8:
6593 case ARM::VLD4dWB_register_Asm_16:
6594 case ARM::VLD4dWB_register_Asm_32:
6595 case ARM::VLD4qWB_register_Asm_8:
6596 case ARM::VLD4qWB_register_Asm_16:
6597 case ARM::VLD4qWB_register_Asm_32: {
6598 MCInst TmpInst;
6599 unsigned Spacing;
6600 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6601 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6602 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6603 Spacing));
6604 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6605 Spacing * 2));
6606 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6607 Spacing * 3));
6608 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6609 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6610 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6611 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6612 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6613 TmpInst.addOperand(Inst.getOperand(5));
6614 Inst = TmpInst;
6615 return true;
6616 }
6617
Jim Grosbach1a747242012-01-23 23:45:44 +00006618 // VST3 multiple 3-element structure instructions.
6619 case ARM::VST3dAsm_8:
6620 case ARM::VST3dAsm_16:
6621 case ARM::VST3dAsm_32:
6622 case ARM::VST3qAsm_8:
6623 case ARM::VST3qAsm_16:
6624 case ARM::VST3qAsm_32: {
6625 MCInst TmpInst;
6626 unsigned Spacing;
6627 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6628 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6629 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6630 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6631 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6632 Spacing));
6633 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6634 Spacing * 2));
6635 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6636 TmpInst.addOperand(Inst.getOperand(4));
6637 Inst = TmpInst;
6638 return true;
6639 }
6640
6641 case ARM::VST3dWB_fixed_Asm_8:
6642 case ARM::VST3dWB_fixed_Asm_16:
6643 case ARM::VST3dWB_fixed_Asm_32:
6644 case ARM::VST3qWB_fixed_Asm_8:
6645 case ARM::VST3qWB_fixed_Asm_16:
6646 case ARM::VST3qWB_fixed_Asm_32: {
6647 MCInst TmpInst;
6648 unsigned Spacing;
6649 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6650 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6651 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6652 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6653 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6654 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6656 Spacing));
6657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6658 Spacing * 2));
6659 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6660 TmpInst.addOperand(Inst.getOperand(4));
6661 Inst = TmpInst;
6662 return true;
6663 }
6664
6665 case ARM::VST3dWB_register_Asm_8:
6666 case ARM::VST3dWB_register_Asm_16:
6667 case ARM::VST3dWB_register_Asm_32:
6668 case ARM::VST3qWB_register_Asm_8:
6669 case ARM::VST3qWB_register_Asm_16:
6670 case ARM::VST3qWB_register_Asm_32: {
6671 MCInst TmpInst;
6672 unsigned Spacing;
6673 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6674 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6675 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6676 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6677 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6678 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6679 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6680 Spacing));
6681 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6682 Spacing * 2));
6683 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6684 TmpInst.addOperand(Inst.getOperand(5));
6685 Inst = TmpInst;
6686 return true;
6687 }
6688
Jim Grosbachda70eac2012-01-24 00:58:13 +00006689 // VST4 multiple 3-element structure instructions.
6690 case ARM::VST4dAsm_8:
6691 case ARM::VST4dAsm_16:
6692 case ARM::VST4dAsm_32:
6693 case ARM::VST4qAsm_8:
6694 case ARM::VST4qAsm_16:
6695 case ARM::VST4qAsm_32: {
6696 MCInst TmpInst;
6697 unsigned Spacing;
6698 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6699 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6700 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6701 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6703 Spacing));
6704 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6705 Spacing * 2));
6706 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6707 Spacing * 3));
6708 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6709 TmpInst.addOperand(Inst.getOperand(4));
6710 Inst = TmpInst;
6711 return true;
6712 }
6713
6714 case ARM::VST4dWB_fixed_Asm_8:
6715 case ARM::VST4dWB_fixed_Asm_16:
6716 case ARM::VST4dWB_fixed_Asm_32:
6717 case ARM::VST4qWB_fixed_Asm_8:
6718 case ARM::VST4qWB_fixed_Asm_16:
6719 case ARM::VST4qWB_fixed_Asm_32: {
6720 MCInst TmpInst;
6721 unsigned Spacing;
6722 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6723 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6724 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6725 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6726 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6727 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6728 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6729 Spacing));
6730 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6731 Spacing * 2));
6732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6733 Spacing * 3));
6734 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6735 TmpInst.addOperand(Inst.getOperand(4));
6736 Inst = TmpInst;
6737 return true;
6738 }
6739
6740 case ARM::VST4dWB_register_Asm_8:
6741 case ARM::VST4dWB_register_Asm_16:
6742 case ARM::VST4dWB_register_Asm_32:
6743 case ARM::VST4qWB_register_Asm_8:
6744 case ARM::VST4qWB_register_Asm_16:
6745 case ARM::VST4qWB_register_Asm_32: {
6746 MCInst TmpInst;
6747 unsigned Spacing;
6748 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6749 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6750 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6751 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6752 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6753 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6754 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6755 Spacing));
6756 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6757 Spacing * 2));
6758 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6759 Spacing * 3));
6760 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6761 TmpInst.addOperand(Inst.getOperand(5));
6762 Inst = TmpInst;
6763 return true;
6764 }
6765
Jim Grosbachad66de12012-04-11 00:15:16 +00006766 // Handle encoding choice for the shift-immediate instructions.
6767 case ARM::t2LSLri:
6768 case ARM::t2LSRri:
6769 case ARM::t2ASRri: {
6770 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6771 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6772 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6773 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6774 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6775 unsigned NewOpc;
6776 switch (Inst.getOpcode()) {
6777 default: llvm_unreachable("unexpected opcode");
6778 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6779 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6780 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6781 }
6782 // The Thumb1 operands aren't in the same order. Awesome, eh?
6783 MCInst TmpInst;
6784 TmpInst.setOpcode(NewOpc);
6785 TmpInst.addOperand(Inst.getOperand(0));
6786 TmpInst.addOperand(Inst.getOperand(5));
6787 TmpInst.addOperand(Inst.getOperand(1));
6788 TmpInst.addOperand(Inst.getOperand(2));
6789 TmpInst.addOperand(Inst.getOperand(3));
6790 TmpInst.addOperand(Inst.getOperand(4));
6791 Inst = TmpInst;
6792 return true;
6793 }
6794 return false;
6795 }
6796
Jim Grosbach485e5622011-12-13 22:45:11 +00006797 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006798 case ARM::t2MOVsr:
6799 case ARM::t2MOVSsr: {
6800 // Which instruction to expand to depends on the CCOut operand and
6801 // whether we're in an IT block if the register operands are low
6802 // registers.
6803 bool isNarrow = false;
6804 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6805 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6806 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6807 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6808 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6809 isNarrow = true;
6810 MCInst TmpInst;
6811 unsigned newOpc;
6812 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6813 default: llvm_unreachable("unexpected opcode!");
6814 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6815 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6816 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6817 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6818 }
6819 TmpInst.setOpcode(newOpc);
6820 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6821 if (isNarrow)
6822 TmpInst.addOperand(MCOperand::CreateReg(
6823 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6824 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6825 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6826 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6827 TmpInst.addOperand(Inst.getOperand(5));
6828 if (!isNarrow)
6829 TmpInst.addOperand(MCOperand::CreateReg(
6830 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6831 Inst = TmpInst;
6832 return true;
6833 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006834 case ARM::t2MOVsi:
6835 case ARM::t2MOVSsi: {
6836 // Which instruction to expand to depends on the CCOut operand and
6837 // whether we're in an IT block if the register operands are low
6838 // registers.
6839 bool isNarrow = false;
6840 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6841 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6842 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6843 isNarrow = true;
6844 MCInst TmpInst;
6845 unsigned newOpc;
6846 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6847 default: llvm_unreachable("unexpected opcode!");
6848 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6849 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6850 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6851 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006852 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006853 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006854 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6855 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006856 TmpInst.setOpcode(newOpc);
6857 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6858 if (isNarrow)
6859 TmpInst.addOperand(MCOperand::CreateReg(
6860 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6861 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006862 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006863 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006864 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6865 TmpInst.addOperand(Inst.getOperand(4));
6866 if (!isNarrow)
6867 TmpInst.addOperand(MCOperand::CreateReg(
6868 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6869 Inst = TmpInst;
6870 return true;
6871 }
6872 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006873 case ARM::ASRr:
6874 case ARM::LSRr:
6875 case ARM::LSLr:
6876 case ARM::RORr: {
6877 ARM_AM::ShiftOpc ShiftTy;
6878 switch(Inst.getOpcode()) {
6879 default: llvm_unreachable("unexpected opcode!");
6880 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6881 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6882 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6883 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6884 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006885 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6886 MCInst TmpInst;
6887 TmpInst.setOpcode(ARM::MOVsr);
6888 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6889 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6890 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6891 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6892 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6893 TmpInst.addOperand(Inst.getOperand(4));
6894 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6895 Inst = TmpInst;
6896 return true;
6897 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006898 case ARM::ASRi:
6899 case ARM::LSRi:
6900 case ARM::LSLi:
6901 case ARM::RORi: {
6902 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006903 switch(Inst.getOpcode()) {
6904 default: llvm_unreachable("unexpected opcode!");
6905 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6906 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6907 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6908 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6909 }
6910 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006911 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00006912 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00006913 // A shift by 32 should be encoded as 0 when permitted
6914 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6915 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006916 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006917 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006918 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006919 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6920 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00006921 if (Opc == ARM::MOVsi)
6922 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00006923 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6924 TmpInst.addOperand(Inst.getOperand(4));
6925 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6926 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006927 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00006928 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006929 case ARM::RRXi: {
6930 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6931 MCInst TmpInst;
6932 TmpInst.setOpcode(ARM::MOVsi);
6933 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6934 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6935 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6936 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6937 TmpInst.addOperand(Inst.getOperand(3));
6938 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6939 Inst = TmpInst;
6940 return true;
6941 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00006942 case ARM::t2LDMIA_UPD: {
6943 // If this is a load of a single register, then we should use
6944 // a post-indexed LDR instruction instead, per the ARM ARM.
6945 if (Inst.getNumOperands() != 5)
6946 return false;
6947 MCInst TmpInst;
6948 TmpInst.setOpcode(ARM::t2LDR_POST);
6949 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6950 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6951 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6952 TmpInst.addOperand(MCOperand::CreateImm(4));
6953 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6954 TmpInst.addOperand(Inst.getOperand(3));
6955 Inst = TmpInst;
6956 return true;
6957 }
6958 case ARM::t2STMDB_UPD: {
6959 // If this is a store of a single register, then we should use
6960 // a pre-indexed STR instruction instead, per the ARM ARM.
6961 if (Inst.getNumOperands() != 5)
6962 return false;
6963 MCInst TmpInst;
6964 TmpInst.setOpcode(ARM::t2STR_PRE);
6965 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6966 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6967 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6968 TmpInst.addOperand(MCOperand::CreateImm(-4));
6969 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6970 TmpInst.addOperand(Inst.getOperand(3));
6971 Inst = TmpInst;
6972 return true;
6973 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006974 case ARM::LDMIA_UPD:
6975 // If this is a load of a single register via a 'pop', then we should use
6976 // a post-indexed LDR instruction instead, per the ARM ARM.
6977 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6978 Inst.getNumOperands() == 5) {
6979 MCInst TmpInst;
6980 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6981 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6982 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6983 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6984 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6985 TmpInst.addOperand(MCOperand::CreateImm(4));
6986 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6987 TmpInst.addOperand(Inst.getOperand(3));
6988 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006989 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006990 }
6991 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00006992 case ARM::STMDB_UPD:
6993 // If this is a store of a single register via a 'push', then we should use
6994 // a pre-indexed STR instruction instead, per the ARM ARM.
6995 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6996 Inst.getNumOperands() == 5) {
6997 MCInst TmpInst;
6998 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6999 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7000 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7001 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7002 TmpInst.addOperand(MCOperand::CreateImm(-4));
7003 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7004 TmpInst.addOperand(Inst.getOperand(3));
7005 Inst = TmpInst;
7006 }
7007 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007008 case ARM::t2ADDri12:
7009 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7010 // mnemonic was used (not "addw"), encoding T3 is preferred.
7011 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7012 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7013 break;
7014 Inst.setOpcode(ARM::t2ADDri);
7015 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7016 break;
7017 case ARM::t2SUBri12:
7018 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7019 // mnemonic was used (not "subw"), encoding T3 is preferred.
7020 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7021 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7022 break;
7023 Inst.setOpcode(ARM::t2SUBri);
7024 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7025 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007026 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007027 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007028 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7029 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7030 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007031 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007032 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007033 return true;
7034 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007035 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007036 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007037 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007038 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7039 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7040 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007041 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007042 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007043 return true;
7044 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007045 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007046 case ARM::t2ADDri:
7047 case ARM::t2SUBri: {
7048 // If the destination and first source operand are the same, and
7049 // the flags are compatible with the current IT status, use encoding T2
7050 // instead of T3. For compatibility with the system 'as'. Make sure the
7051 // wide encoding wasn't explicit.
7052 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007053 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007054 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7055 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7056 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7057 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7058 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7059 break;
7060 MCInst TmpInst;
7061 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7062 ARM::tADDi8 : ARM::tSUBi8);
7063 TmpInst.addOperand(Inst.getOperand(0));
7064 TmpInst.addOperand(Inst.getOperand(5));
7065 TmpInst.addOperand(Inst.getOperand(0));
7066 TmpInst.addOperand(Inst.getOperand(2));
7067 TmpInst.addOperand(Inst.getOperand(3));
7068 TmpInst.addOperand(Inst.getOperand(4));
7069 Inst = TmpInst;
7070 return true;
7071 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007072 case ARM::t2ADDrr: {
7073 // If the destination and first source operand are the same, and
7074 // there's no setting of the flags, use encoding T2 instead of T3.
7075 // Note that this is only for ADD, not SUB. This mirrors the system
7076 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7077 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7078 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007079 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7080 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007081 break;
7082 MCInst TmpInst;
7083 TmpInst.setOpcode(ARM::tADDhirr);
7084 TmpInst.addOperand(Inst.getOperand(0));
7085 TmpInst.addOperand(Inst.getOperand(0));
7086 TmpInst.addOperand(Inst.getOperand(2));
7087 TmpInst.addOperand(Inst.getOperand(3));
7088 TmpInst.addOperand(Inst.getOperand(4));
7089 Inst = TmpInst;
7090 return true;
7091 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007092 case ARM::tADDrSP: {
7093 // If the non-SP source operand and the destination operand are not the
7094 // same, we need to use the 32-bit encoding if it's available.
7095 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7096 Inst.setOpcode(ARM::t2ADDrr);
7097 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7098 return true;
7099 }
7100 break;
7101 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007102 case ARM::tB:
7103 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007104 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007105 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007106 return true;
7107 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007108 break;
7109 case ARM::t2B:
7110 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007111 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007112 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007113 return true;
7114 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007115 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007116 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007117 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007118 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007119 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007120 return true;
7121 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007122 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007123 case ARM::tBcc:
7124 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007125 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007126 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007127 return true;
7128 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007129 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007130 case ARM::tLDMIA: {
7131 // If the register list contains any high registers, or if the writeback
7132 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7133 // instead if we're in Thumb2. Otherwise, this should have generated
7134 // an error in validateInstruction().
7135 unsigned Rn = Inst.getOperand(0).getReg();
7136 bool hasWritebackToken =
7137 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7138 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7139 bool listContainsBase;
7140 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7141 (!listContainsBase && !hasWritebackToken) ||
7142 (listContainsBase && hasWritebackToken)) {
7143 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7144 assert (isThumbTwo());
7145 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7146 // If we're switching to the updating version, we need to insert
7147 // the writeback tied operand.
7148 if (hasWritebackToken)
7149 Inst.insert(Inst.begin(),
7150 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007151 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007152 }
7153 break;
7154 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007155 case ARM::tSTMIA_UPD: {
7156 // If the register list contains any high registers, we need to use
7157 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7158 // should have generated an error in validateInstruction().
7159 unsigned Rn = Inst.getOperand(0).getReg();
7160 bool listContainsBase;
7161 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7162 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7163 assert (isThumbTwo());
7164 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007165 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007166 }
7167 break;
7168 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007169 case ARM::tPOP: {
7170 bool listContainsBase;
7171 // If the register list contains any high registers, we need to use
7172 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7173 // should have generated an error in validateInstruction().
7174 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007175 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007176 assert (isThumbTwo());
7177 Inst.setOpcode(ARM::t2LDMIA_UPD);
7178 // Add the base register and writeback operands.
7179 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7180 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007181 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007182 }
7183 case ARM::tPUSH: {
7184 bool listContainsBase;
7185 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007186 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007187 assert (isThumbTwo());
7188 Inst.setOpcode(ARM::t2STMDB_UPD);
7189 // Add the base register and writeback operands.
7190 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7191 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007192 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007193 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007194 case ARM::t2MOVi: {
7195 // If we can use the 16-bit encoding and the user didn't explicitly
7196 // request the 32-bit variant, transform it here.
7197 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007198 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007199 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7200 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7201 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007202 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7203 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7204 // The operands aren't in the same order for tMOVi8...
7205 MCInst TmpInst;
7206 TmpInst.setOpcode(ARM::tMOVi8);
7207 TmpInst.addOperand(Inst.getOperand(0));
7208 TmpInst.addOperand(Inst.getOperand(4));
7209 TmpInst.addOperand(Inst.getOperand(1));
7210 TmpInst.addOperand(Inst.getOperand(2));
7211 TmpInst.addOperand(Inst.getOperand(3));
7212 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007213 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007214 }
7215 break;
7216 }
7217 case ARM::t2MOVr: {
7218 // If we can use the 16-bit encoding and the user didn't explicitly
7219 // request the 32-bit variant, transform it here.
7220 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7221 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7222 Inst.getOperand(2).getImm() == ARMCC::AL &&
7223 Inst.getOperand(4).getReg() == ARM::CPSR &&
7224 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7225 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7226 // The operands aren't the same for tMOV[S]r... (no cc_out)
7227 MCInst TmpInst;
7228 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7229 TmpInst.addOperand(Inst.getOperand(0));
7230 TmpInst.addOperand(Inst.getOperand(1));
7231 TmpInst.addOperand(Inst.getOperand(2));
7232 TmpInst.addOperand(Inst.getOperand(3));
7233 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007234 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007235 }
7236 break;
7237 }
Jim Grosbach82213192011-09-19 20:29:33 +00007238 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007239 case ARM::t2SXTB:
7240 case ARM::t2UXTH:
7241 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007242 // If we can use the 16-bit encoding and the user didn't explicitly
7243 // request the 32-bit variant, transform it here.
7244 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7245 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7246 Inst.getOperand(2).getImm() == 0 &&
7247 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7248 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007249 unsigned NewOpc;
7250 switch (Inst.getOpcode()) {
7251 default: llvm_unreachable("Illegal opcode!");
7252 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7253 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7254 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7255 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7256 }
Jim Grosbach82213192011-09-19 20:29:33 +00007257 // The operands aren't the same for thumb1 (no rotate operand).
7258 MCInst TmpInst;
7259 TmpInst.setOpcode(NewOpc);
7260 TmpInst.addOperand(Inst.getOperand(0));
7261 TmpInst.addOperand(Inst.getOperand(1));
7262 TmpInst.addOperand(Inst.getOperand(3));
7263 TmpInst.addOperand(Inst.getOperand(4));
7264 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007265 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007266 }
7267 break;
7268 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007269 case ARM::MOVsi: {
7270 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007271 // rrx shifts and asr/lsr of #32 is encoded as 0
7272 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7273 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007274 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7275 // Shifting by zero is accepted as a vanilla 'MOVr'
7276 MCInst TmpInst;
7277 TmpInst.setOpcode(ARM::MOVr);
7278 TmpInst.addOperand(Inst.getOperand(0));
7279 TmpInst.addOperand(Inst.getOperand(1));
7280 TmpInst.addOperand(Inst.getOperand(3));
7281 TmpInst.addOperand(Inst.getOperand(4));
7282 TmpInst.addOperand(Inst.getOperand(5));
7283 Inst = TmpInst;
7284 return true;
7285 }
7286 return false;
7287 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007288 case ARM::ANDrsi:
7289 case ARM::ORRrsi:
7290 case ARM::EORrsi:
7291 case ARM::BICrsi:
7292 case ARM::SUBrsi:
7293 case ARM::ADDrsi: {
7294 unsigned newOpc;
7295 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7296 if (SOpc == ARM_AM::rrx) return false;
7297 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007298 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007299 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7300 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7301 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7302 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7303 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7304 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7305 }
7306 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007307 // The exception is for right shifts, where 0 == 32
7308 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7309 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007310 MCInst TmpInst;
7311 TmpInst.setOpcode(newOpc);
7312 TmpInst.addOperand(Inst.getOperand(0));
7313 TmpInst.addOperand(Inst.getOperand(1));
7314 TmpInst.addOperand(Inst.getOperand(2));
7315 TmpInst.addOperand(Inst.getOperand(4));
7316 TmpInst.addOperand(Inst.getOperand(5));
7317 TmpInst.addOperand(Inst.getOperand(6));
7318 Inst = TmpInst;
7319 return true;
7320 }
7321 return false;
7322 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007323 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007324 case ARM::t2IT: {
7325 // The mask bits for all but the first condition are represented as
7326 // the low bit of the condition code value implies 't'. We currently
7327 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007328 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007329 MCOperand &MO = Inst.getOperand(1);
7330 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007331 unsigned OrigMask = Mask;
7332 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007333 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007334 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7335 for (unsigned i = 3; i != TZ; --i)
7336 Mask ^= 1 << i;
Richard Bartonf435b092012-04-27 08:42:59 +00007337 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007338 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007339
7340 // Set up the IT block state according to the IT instruction we just
7341 // matched.
7342 assert(!inITBlock() && "nested IT blocks?!");
7343 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7344 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7345 ITState.CurPosition = 0;
7346 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007347 break;
7348 }
Richard Bartona39625e2012-07-09 16:12:24 +00007349 case ARM::t2LSLrr:
7350 case ARM::t2LSRrr:
7351 case ARM::t2ASRrr:
7352 case ARM::t2SBCrr:
7353 case ARM::t2RORrr:
7354 case ARM::t2BICrr:
7355 {
Richard Bartond5660372012-07-09 16:14:28 +00007356 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007357 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7358 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7359 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007360 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7361 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007362 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7363 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7364 unsigned NewOpc;
7365 switch (Inst.getOpcode()) {
7366 default: llvm_unreachable("unexpected opcode");
7367 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7368 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7369 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7370 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7371 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7372 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7373 }
7374 MCInst TmpInst;
7375 TmpInst.setOpcode(NewOpc);
7376 TmpInst.addOperand(Inst.getOperand(0));
7377 TmpInst.addOperand(Inst.getOperand(5));
7378 TmpInst.addOperand(Inst.getOperand(1));
7379 TmpInst.addOperand(Inst.getOperand(2));
7380 TmpInst.addOperand(Inst.getOperand(3));
7381 TmpInst.addOperand(Inst.getOperand(4));
7382 Inst = TmpInst;
7383 return true;
7384 }
7385 return false;
7386 }
7387 case ARM::t2ANDrr:
7388 case ARM::t2EORrr:
7389 case ARM::t2ADCrr:
7390 case ARM::t2ORRrr:
7391 {
Richard Bartond5660372012-07-09 16:14:28 +00007392 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007393 // These instructions are special in that they are commutable, so shorter encodings
7394 // are available more often.
7395 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7396 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7397 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7398 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007399 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7400 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007401 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7402 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7403 unsigned NewOpc;
7404 switch (Inst.getOpcode()) {
7405 default: llvm_unreachable("unexpected opcode");
7406 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7407 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7408 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7409 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7410 }
7411 MCInst TmpInst;
7412 TmpInst.setOpcode(NewOpc);
7413 TmpInst.addOperand(Inst.getOperand(0));
7414 TmpInst.addOperand(Inst.getOperand(5));
7415 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7416 TmpInst.addOperand(Inst.getOperand(1));
7417 TmpInst.addOperand(Inst.getOperand(2));
7418 } else {
7419 TmpInst.addOperand(Inst.getOperand(2));
7420 TmpInst.addOperand(Inst.getOperand(1));
7421 }
7422 TmpInst.addOperand(Inst.getOperand(3));
7423 TmpInst.addOperand(Inst.getOperand(4));
7424 Inst = TmpInst;
7425 return true;
7426 }
7427 return false;
7428 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007429 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007430 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007431}
7432
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007433unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7434 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7435 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007436 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007437 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007438 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7439 assert(MCID.hasOptionalDef() &&
7440 "optionally flag setting instruction missing optional def operand");
7441 assert(MCID.NumOperands == Inst.getNumOperands() &&
7442 "operand count mismatch!");
7443 // Find the optional-def operand (cc_out).
7444 unsigned OpNo;
7445 for (OpNo = 0;
7446 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7447 ++OpNo)
7448 ;
7449 // If we're parsing Thumb1, reject it completely.
7450 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7451 return Match_MnemonicFail;
7452 // If we're parsing Thumb2, which form is legal depends on whether we're
7453 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007454 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7455 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007456 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007457 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7458 inITBlock())
7459 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007460 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007461 // Some high-register supporting Thumb1 encodings only allow both registers
7462 // to be from r0-r7 when in Thumb2.
7463 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7464 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7465 isARMLowRegister(Inst.getOperand(2).getReg()))
7466 return Match_RequiresThumb2;
7467 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007468 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007469 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7470 isARMLowRegister(Inst.getOperand(1).getReg()))
7471 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007472 return Match_Success;
7473}
7474
Jim Grosbach5117ef72012-04-24 22:40:08 +00007475static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007476bool ARMAsmParser::
7477MatchAndEmitInstruction(SMLoc IDLoc,
7478 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7479 MCStreamer &Out) {
7480 MCInst Inst;
Chad Rosiere38bb6a2012-09-03 02:06:46 +00007481 unsigned Kind;
Chris Lattner9487de62010-10-28 21:28:01 +00007482 unsigned ErrorInfo;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007483 unsigned MatchResult;
Chad Rosier8f06e7d2012-10-05 18:41:14 +00007484 MatchInstMapAndConstraints MapAndConstraints;
Chad Rosierf4e35dc2012-10-01 23:45:51 +00007485 MatchResult = MatchInstructionImpl(Operands, Kind, Inst,
7486 MapAndConstraints, ErrorInfo,
7487 /*matchingInlineAsm*/ false);
Kevin Enderby3164a342010-12-09 19:19:43 +00007488 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007489 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007490 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007491 // Context sensitive operand constraints aren't handled by the matcher,
7492 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007493 if (validateInstruction(Inst, Operands)) {
7494 // Still progress the IT block, otherwise one wrong condition causes
7495 // nasty cascading errors.
7496 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007497 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007498 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007499
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007500 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007501 // encoding is selected. Loop on it while changes happen so the
7502 // individual transformations can chain off each other. E.g.,
7503 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7504 while (processInstruction(Inst, Operands))
7505 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007506
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007507 // Only move forward at the very end so that everything in validate
7508 // and process gets a consistent answer about whether we're in an IT
7509 // block.
7510 forwardITPosition();
7511
Jim Grosbach82f76d12012-01-25 19:52:01 +00007512 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7513 // doesn't actually encode.
7514 if (Inst.getOpcode() == ARM::ITasm)
7515 return false;
7516
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007517 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007518 Out.EmitInstruction(Inst);
7519 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007520 case Match_MissingFeature: {
7521 assert(ErrorInfo && "Unknown missing feature!");
7522 // Special case the error message for the very common case where only
7523 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7524 std::string Msg = "instruction requires:";
7525 unsigned Mask = 1;
7526 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7527 if (ErrorInfo & Mask) {
7528 Msg += " ";
7529 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7530 }
7531 Mask <<= 1;
7532 }
7533 return Error(IDLoc, Msg);
7534 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007535 case Match_InvalidOperand: {
7536 SMLoc ErrorLoc = IDLoc;
7537 if (ErrorInfo != ~0U) {
7538 if (ErrorInfo >= Operands.size())
7539 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007540
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007541 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7542 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7543 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007544
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007545 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007546 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007547 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007548 return Error(IDLoc, "invalid instruction",
7549 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007550 case Match_RequiresNotITBlock:
7551 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007552 case Match_RequiresITBlock:
7553 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007554 case Match_RequiresV6:
7555 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7556 case Match_RequiresThumb2:
7557 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007558 case Match_ImmRange0_15: {
7559 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7560 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7561 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7562 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007563 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007564
Eric Christopher91d7b902010-10-29 09:26:59 +00007565 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007566}
7567
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007568/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007569bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7570 StringRef IDVal = DirectiveID.getIdentifier();
7571 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007572 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007573 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007574 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007575 else if (IDVal == ".arm")
7576 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007577 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007578 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007579 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007580 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007581 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007582 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007583 else if (IDVal == ".unreq")
7584 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007585 else if (IDVal == ".arch")
7586 return parseDirectiveArch(DirectiveID.getLoc());
7587 else if (IDVal == ".eabi_attribute")
7588 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyccab3172009-09-15 00:27:25 +00007589 return true;
7590}
7591
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007592/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007593/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007594bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007595 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7596 for (;;) {
7597 const MCExpr *Value;
7598 if (getParser().ParseExpression(Value))
7599 return true;
7600
Chris Lattnerc35681b2010-01-19 19:46:13 +00007601 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007602
7603 if (getLexer().is(AsmToken::EndOfStatement))
7604 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007605
Kevin Enderbyccab3172009-09-15 00:27:25 +00007606 // FIXME: Improve diagnostic.
7607 if (getLexer().isNot(AsmToken::Comma))
7608 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007609 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007610 }
7611 }
7612
Sean Callanana83fd7d2010-01-19 20:27:46 +00007613 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007614 return false;
7615}
7616
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007617/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007618/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007619bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007620 if (getLexer().isNot(AsmToken::EndOfStatement))
7621 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007622 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007623
Jim Grosbach7f882392011-12-07 18:04:19 +00007624 if (!isThumb())
7625 SwitchMode();
7626 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7627 return false;
7628}
7629
7630/// parseDirectiveARM
7631/// ::= .arm
7632bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7633 if (getLexer().isNot(AsmToken::EndOfStatement))
7634 return Error(L, "unexpected token in directive");
7635 Parser.Lex();
7636
7637 if (isThumb())
7638 SwitchMode();
7639 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007640 return false;
7641}
7642
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007643/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007644/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007645bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007646 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7647 bool isMachO = MAI.hasSubsectionsViaSymbols();
7648 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007649 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007650
Jim Grosbach1152cc02011-12-21 22:30:16 +00007651 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007652 // ELF doesn't
7653 if (isMachO) {
7654 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007655 if (Tok.isNot(AsmToken::EndOfStatement)) {
7656 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7657 return Error(L, "unexpected token in .thumb_func directive");
7658 Name = Tok.getIdentifier();
7659 Parser.Lex(); // Consume the identifier token.
7660 needFuncName = false;
7661 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007662 }
7663
Jim Grosbach1152cc02011-12-21 22:30:16 +00007664 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007665 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007666
7667 // Eat the end of statement and any blank lines that follow.
7668 while (getLexer().is(AsmToken::EndOfStatement))
7669 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007670
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007671 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007672 // We really should be checking the next symbol definition even if there's
7673 // stuff in between.
7674 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007675 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007676 }
7677
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007678 // Mark symbol as a thumb symbol.
7679 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7680 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007681 return false;
7682}
7683
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007684/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007685/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007686bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007687 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007688 if (Tok.isNot(AsmToken::Identifier))
7689 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007690 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007691 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007692 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007693 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007694 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007695 else
7696 return Error(L, "unrecognized syntax mode in .syntax directive");
7697
7698 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007699 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007700 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007701
7702 // TODO tell the MC streamer the mode
7703 // getParser().getStreamer().Emit???();
7704 return false;
7705}
7706
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007707/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007708/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007709bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007710 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007711 if (Tok.isNot(AsmToken::Integer))
7712 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007713 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007714 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007715 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007716 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007717 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007718 else
7719 return Error(L, "invalid operand to .code directive");
7720
7721 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007722 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007723 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007724
Evan Cheng284b4672011-07-08 22:36:29 +00007725 if (Val == 16) {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007726 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007727 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007728 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007729 } else {
Jim Grosbachf471ac32011-09-06 18:46:23 +00007730 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007731 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007732 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007733 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007734
Kevin Enderby146dcf22009-10-15 20:48:48 +00007735 return false;
7736}
7737
Jim Grosbachab5830e2011-12-14 02:16:11 +00007738/// parseDirectiveReq
7739/// ::= name .req registername
7740bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7741 Parser.Lex(); // Eat the '.req' token.
7742 unsigned Reg;
7743 SMLoc SRegLoc, ERegLoc;
7744 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7745 Parser.EatToEndOfStatement();
7746 return Error(SRegLoc, "register name expected");
7747 }
7748
7749 // Shouldn't be anything else.
7750 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7751 Parser.EatToEndOfStatement();
7752 return Error(Parser.getTok().getLoc(),
7753 "unexpected input in .req directive.");
7754 }
7755
7756 Parser.Lex(); // Consume the EndOfStatement
7757
7758 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7759 return Error(SRegLoc, "redefinition of '" + Name +
7760 "' does not match original.");
7761
7762 return false;
7763}
7764
7765/// parseDirectiveUneq
7766/// ::= .unreq registername
7767bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7768 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7769 Parser.EatToEndOfStatement();
7770 return Error(L, "unexpected input in .unreq directive.");
7771 }
7772 RegisterReqs.erase(Parser.getTok().getIdentifier());
7773 Parser.Lex(); // Eat the identifier.
7774 return false;
7775}
7776
Jason W Kim135d2442011-12-20 17:38:12 +00007777/// parseDirectiveArch
7778/// ::= .arch token
7779bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7780 return true;
7781}
7782
7783/// parseDirectiveEabiAttr
7784/// ::= .eabi_attribute int, int
7785bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7786 return true;
7787}
7788
Sean Callanan643a5572010-04-07 20:29:34 +00007789extern "C" void LLVMInitializeARMAsmLexer();
7790
Kevin Enderby8be42bd2009-10-30 22:55:57 +00007791/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00007792extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00007793 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7794 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan643a5572010-04-07 20:29:34 +00007795 LLVMInitializeARMAsmLexer();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007796}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007797
Chris Lattner3e4582a2010-09-06 19:11:01 +00007798#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00007799#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00007800#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00007801#include "ARMGenAsmMatcher.inc"