blob: 00e7f6e8fb990fb509b17cffd21eda8a33ba1201 [file] [log] [blame]
Kevin Enderbyca9c42c2009-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 Cheng94b95502011-07-26 00:24:13 +000010#include "MCTargetDesc/ARMBaseInfo.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMMCExpr.h"
Chris Lattnerc6ef2772010-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 Espindola64695402011-05-16 16:17:21 +000016#include "llvm/MC/MCAsmInfo.h"
Jim Grosbach642fc9c2010-11-05 22:33:53 +000017#include "llvm/MC/MCContext.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000018#include "llvm/MC/MCStreamer.h"
19#include "llvm/MC/MCExpr.h"
20#include "llvm/MC/MCInst.h"
Evan Cheng78011362011-08-23 20:15:21 +000021#include "llvm/MC/MCInstrDesc.h"
Evan Cheng94b95502011-07-26 00:24:13 +000022#include "llvm/MC/MCRegisterInfo.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000023#include "llvm/MC/MCSubtargetInfo.h"
Evan Cheng94b95502011-07-26 00:24:13 +000024#include "llvm/MC/MCTargetAsmParser.h"
Jim Grosbach89df9962011-08-26 21:43:41 +000025#include "llvm/Support/MathExtras.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000026#include "llvm/Support/SourceMgr.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000027#include "llvm/Support/TargetRegistry.h"
Daniel Dunbarfa315de2010-08-11 06:37:12 +000028#include "llvm/Support/raw_ostream.h"
Jim Grosbach11e03e72011-08-22 18:50:36 +000029#include "llvm/ADT/BitVector.h"
Benjamin Kramer75ca4b92011-07-08 21:06:23 +000030#include "llvm/ADT/OwningPtr.h"
Evan Cheng94b95502011-07-26 00:24:13 +000031#include "llvm/ADT/STLExtras.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000032#include "llvm/ADT/SmallVector.h"
Daniel Dunbar345a9a62010-08-11 06:37:20 +000033#include "llvm/ADT/StringSwitch.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000034#include "llvm/ADT/Twine.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000035
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000036using namespace llvm;
37
Chris Lattner3a697562010-10-28 17:20:03 +000038namespace {
Bill Wendling146018f2010-11-06 21:42:12 +000039
40class ARMOperand;
Jim Grosbach16c74252010-10-29 14:46:02 +000041
Jim Grosbach7636bf62011-12-02 00:35:16 +000042enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbach98b05a52011-11-30 01:09:44 +000043
Evan Cheng94b95502011-07-26 00:24:13 +000044class ARMAsmParser : public MCTargetAsmParser {
Evan Chengffc0e732011-07-09 05:47:46 +000045 MCSubtargetInfo &STI;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000046 MCAsmParser &Parser;
Jim Grosbach28f08c92012-03-05 19:33:30 +000047 const MCRegisterInfo *MRI;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000048
Jim Grosbacha39cda72011-12-14 02:16:11 +000049 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
51
Jim Grosbachf8e1e3e2011-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 Grosbacha1109882011-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 Grosbachf8e1e3e2011-08-29 22:24:09 +000080
81
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000082 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000083 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
84
Benjamin Kramer362a05a2012-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 Enderbyca9c42c2009-09-15 00:27:25 +000093
Jim Grosbach1355cf12011-07-26 17:10:22 +000094 int tryParseRegister();
95 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d87ec22011-07-26 20:41:24 +000096 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +000097 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7ce05792011-08-03 23:50:40 +000098 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +000099 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
100 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000101 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
102 unsigned &ShiftAmount);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000103 bool parseDirectiveWord(unsigned Size, SMLoc L);
104 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach9a70df92011-12-07 18:04:19 +0000105 bool parseDirectiveARM(SMLoc L);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000106 bool parseDirectiveThumbFunc(SMLoc L);
107 bool parseDirectiveCode(SMLoc L);
108 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbacha39cda72011-12-14 02:16:11 +0000109 bool parseDirectiveReq(StringRef Name, SMLoc L);
110 bool parseDirectiveUnreq(SMLoc L);
Jason W Kimd7c9e082011-12-20 17:38:12 +0000111 bool parseDirectiveArch(SMLoc L);
112 bool parseDirectiveEabiAttr(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +0000113
Jim Grosbach1355cf12011-07-26 17:10:22 +0000114 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach89df9962011-08-26 21:43:41 +0000115 bool &CarrySetting, unsigned &ProcessorIMod,
116 StringRef &ITMask);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000117 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +0000118 bool &CanAcceptPredicationCode);
Jim Grosbach16c74252010-10-29 14:46:02 +0000119
Evan Chengebdeeab2011-07-08 01:53:10 +0000120 bool isThumb() const {
121 // FIXME: Can tablegen auto-generate this?
Evan Chengffc0e732011-07-09 05:47:46 +0000122 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Chengebdeeab2011-07-08 01:53:10 +0000123 }
Evan Chengebdeeab2011-07-08 01:53:10 +0000124 bool isThumbOne() const {
Evan Chengffc0e732011-07-09 05:47:46 +0000125 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Chengebdeeab2011-07-08 01:53:10 +0000126 }
Jim Grosbach47a0d522011-08-16 20:45:50 +0000127 bool isThumbTwo() const {
128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
129 }
Jim Grosbach194bd892011-08-16 22:20:01 +0000130 bool hasV6Ops() const {
131 return STI.getFeatureBits() & ARM::HasV6Ops;
132 }
James Molloyacad68d2011-09-28 14:21:38 +0000133 bool hasV7Ops() const {
134 return STI.getFeatureBits() & ARM::HasV7Ops;
135 }
Evan Cheng32869202011-07-08 22:36:29 +0000136 void SwitchMode() {
Evan Chengffc0e732011-07-09 05:47:46 +0000137 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
138 setAvailableFeatures(FB);
Evan Cheng32869202011-07-08 22:36:29 +0000139 }
James Molloyacad68d2011-09-28 14:21:38 +0000140 bool isMClass() const {
141 return STI.getFeatureBits() & ARM::FeatureMClass;
142 }
Evan Chengebdeeab2011-07-08 01:53:10 +0000143
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000144 /// @name Auto-generated Match Functions
145 /// {
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000146
Chris Lattner0692ee62010-09-06 19:11:01 +0000147#define GET_ASSEMBLER_HEADER
148#include "ARMGenAsmMatcher.inc"
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000149
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000150 /// }
151
Jim Grosbach89df9962011-08-26 21:43:41 +0000152 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000153 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbachf922c472011-02-12 01:34:40 +0000154 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000155 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbachf922c472011-02-12 01:34:40 +0000156 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000157 OperandMatchResultTy parseCoprocOptionOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000159 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000160 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000161 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000162 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000163 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000164 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachf6c05252011-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 Grosbachc27d4f92011-07-22 17:44:50 +0000173 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach580f4a92011-07-25 22:20:28 +0000174 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000175 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000176 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000177 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach251bf252011-08-10 21:56:18 +0000178 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach9d390362011-10-03 23:38:36 +0000179 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach862019c2011-10-18 23:02:30 +0000180 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7636bf62011-12-02 00:35:16 +0000181 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000182
183 // Asm Match Converter Methods
Jim Grosbacha77295d2011-09-08 22:07:06 +0000184 bool cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
185 const SmallVectorImpl<MCParsedAsmOperand*> &);
186 bool cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
187 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheeec0252011-09-08 00:39:19 +0000188 bool cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
189 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachee2c2a42011-09-16 21:55:56 +0000190 bool cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
191 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000192 bool cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000193 const SmallVectorImpl<MCParsedAsmOperand*> &);
Owen Anderson9ab0f252011-08-26 20:43:14 +0000194 bool cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
195 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach548340c2011-08-11 19:22:40 +0000196 bool cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
197 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000198 bool cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000199 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7b8f46c2011-08-11 21:17:22 +0000200 bool cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
201 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000202 bool cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
203 const SmallVectorImpl<MCParsedAsmOperand*> &);
204 bool cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
205 const SmallVectorImpl<MCParsedAsmOperand*> &);
206 bool cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
207 const SmallVectorImpl<MCParsedAsmOperand*> &);
208 bool cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
209 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000210 bool cvtLdrdPre(MCInst &Inst, unsigned Opcode,
211 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach14605d12011-08-11 20:28:23 +0000212 bool cvtStrdPre(MCInst &Inst, unsigned Opcode,
213 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach623a4542011-08-10 22:42:16 +0000214 bool cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
215 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach88ae2bc2011-08-19 22:07:46 +0000216 bool cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
217 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach12431322011-10-24 22:16:58 +0000218 bool cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
219 const SmallVectorImpl<MCParsedAsmOperand*> &);
220 bool cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
221 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach4334e032011-10-31 21:50:31 +0000222 bool cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
223 const SmallVectorImpl<MCParsedAsmOperand*> &);
224 bool cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
225 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach189610f2011-07-26 18:25:39 +0000226
227 bool validateInstruction(MCInst &Inst,
228 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach83ec8772011-11-10 23:42:14 +0000229 bool processInstruction(MCInst &Inst,
Jim Grosbachf8fce712011-08-11 17:35:48 +0000230 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachd54b4e62011-08-16 21:12:37 +0000231 bool shouldOmitCCOutOperand(StringRef Mnemonic,
232 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach189610f2011-07-26 18:25:39 +0000233
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000234public:
Jim Grosbach47a0d522011-08-16 20:45:50 +0000235 enum ARMMatchResultTy {
Jim Grosbach194bd892011-08-16 22:20:01 +0000236 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000237 Match_RequiresNotITBlock,
Jim Grosbach194bd892011-08-16 22:20:01 +0000238 Match_RequiresV6,
239 Match_RequiresThumb2
Jim Grosbach47a0d522011-08-16 20:45:50 +0000240 };
241
Evan Chengffc0e732011-07-09 05:47:46 +0000242 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Evan Cheng94b95502011-07-26 00:24:13 +0000243 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
Evan Chengebdeeab2011-07-08 01:53:10 +0000244 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng32869202011-07-08 22:36:29 +0000245
Jim Grosbach28f08c92012-03-05 19:33:30 +0000246 // Cache the MCRegisterInfo.
247 MRI = &getContext().getRegisterInfo();
248
Evan Chengebdeeab2011-07-08 01:53:10 +0000249 // Initialize the set of available features.
Evan Chengffc0e732011-07-09 05:47:46 +0000250 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000251
252 // Not in an ITBlock to start with.
253 ITState.CurPosition = ~0U;
Evan Chengebdeeab2011-07-08 01:53:10 +0000254 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000255
Jim Grosbach1355cf12011-07-26 17:10:22 +0000256 // Implementation of the MCTargetAsmParser interface:
257 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
258 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Jim Grosbach189610f2011-07-26 18:25:39 +0000259 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000260 bool ParseDirective(AsmToken DirectiveID);
261
Jim Grosbach47a0d522011-08-16 20:45:50 +0000262 unsigned checkTargetMatchPredicate(MCInst &Inst);
263
Jim Grosbach1355cf12011-07-26 17:10:22 +0000264 bool MatchAndEmitInstruction(SMLoc IDLoc,
265 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
266 MCStreamer &Out);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000267};
Jim Grosbach16c74252010-10-29 14:46:02 +0000268} // end anonymous namespace
269
Chris Lattner3a697562010-10-28 17:20:03 +0000270namespace {
271
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000272/// ARMOperand - Instances of this class represent a parsed ARM machine
273/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000274class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000275 enum KindTy {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000276 k_CondCode,
277 k_CCOut,
278 k_ITCondMask,
279 k_CoprocNum,
280 k_CoprocReg,
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000281 k_CoprocOption,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000282 k_Immediate,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000283 k_MemBarrierOpt,
284 k_Memory,
285 k_PostIndexRegister,
286 k_MSRMask,
287 k_ProcIFlags,
Jim Grosbach460a9052011-10-07 23:56:00 +0000288 k_VectorIndex,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000289 k_Register,
290 k_RegisterList,
291 k_DPRRegisterList,
292 k_SPRRegisterList,
Jim Grosbach862019c2011-10-18 23:02:30 +0000293 k_VectorList,
Jim Grosbach98b05a52011-11-30 01:09:44 +0000294 k_VectorListAllLanes,
Jim Grosbach7636bf62011-12-02 00:35:16 +0000295 k_VectorListIndexed,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000296 k_ShiftedRegister,
297 k_ShiftedImmediate,
298 k_ShifterImmediate,
299 k_RotateImmediate,
300 k_BitfieldDescriptor,
301 k_Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000302 } Kind;
303
Sean Callanan76264762010-04-02 22:27:05 +0000304 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000305 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000306
307 union {
308 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000309 ARMCC::CondCodes Val;
310 } CC;
311
312 struct {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000313 unsigned Val;
314 } Cop;
315
316 struct {
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000317 unsigned Val;
318 } CoprocOption;
319
320 struct {
Jim Grosbach89df9962011-08-26 21:43:41 +0000321 unsigned Mask:4;
322 } ITMask;
323
324 struct {
325 ARM_MB::MemBOpt Val;
326 } MBOpt;
327
328 struct {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000329 ARM_PROC::IFlags Val;
330 } IFlags;
331
332 struct {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000333 unsigned Val;
334 } MMask;
335
336 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000337 const char *Data;
338 unsigned Length;
339 } Tok;
340
341 struct {
342 unsigned RegNum;
343 } Reg;
344
Jim Grosbach862019c2011-10-18 23:02:30 +0000345 // A vector register list is a sequential list of 1 to 4 registers.
346 struct {
347 unsigned RegNum;
348 unsigned Count;
Jim Grosbach7636bf62011-12-02 00:35:16 +0000349 unsigned LaneIndex;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +0000350 bool isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +0000351 } VectorList;
352
Bill Wendling8155e5b2010-11-06 22:19:43 +0000353 struct {
Jim Grosbach460a9052011-10-07 23:56:00 +0000354 unsigned Val;
355 } VectorIndex;
356
357 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000358 const MCExpr *Val;
359 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000360
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000361 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000362 struct {
363 unsigned BaseRegNum;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000364 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
365 // was specified.
366 const MCConstantExpr *OffsetImm; // Offset immediate value
367 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
368 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbach57dcb852011-10-11 17:29:55 +0000369 unsigned ShiftImm; // shift for OffsetReg.
370 unsigned Alignment; // 0 = no alignment specified
Jim Grosbacheeaf1c12011-12-19 18:31:43 +0000371 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbach7ce05792011-08-03 23:50:40 +0000372 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbache53c87b2011-10-11 15:59:20 +0000373 } Memory;
Owen Anderson00828302011-03-18 22:50:18 +0000374
375 struct {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000376 unsigned RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000377 bool isAdd;
378 ARM_AM::ShiftOpc ShiftTy;
379 unsigned ShiftImm;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000380 } PostIdxReg;
381
382 struct {
Jim Grosbach580f4a92011-07-25 22:20:28 +0000383 bool isASR;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000384 unsigned Imm;
Jim Grosbach580f4a92011-07-25 22:20:28 +0000385 } ShifterImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000386 struct {
387 ARM_AM::ShiftOpc ShiftTy;
388 unsigned SrcReg;
389 unsigned ShiftReg;
390 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000391 } RegShiftedReg;
Owen Anderson92a20222011-07-21 18:54:16 +0000392 struct {
393 ARM_AM::ShiftOpc ShiftTy;
394 unsigned SrcReg;
395 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000396 } RegShiftedImm;
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000397 struct {
398 unsigned Imm;
399 } RotImm;
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000400 struct {
401 unsigned LSB;
402 unsigned Width;
403 } Bitfield;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000404 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000405
Bill Wendling146018f2010-11-06 21:42:12 +0000406 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
407public:
Sean Callanan76264762010-04-02 22:27:05 +0000408 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
409 Kind = o.Kind;
410 StartLoc = o.StartLoc;
411 EndLoc = o.EndLoc;
412 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000413 case k_CondCode:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000414 CC = o.CC;
415 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000416 case k_ITCondMask:
Jim Grosbach89df9962011-08-26 21:43:41 +0000417 ITMask = o.ITMask;
418 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000419 case k_Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000420 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000421 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000422 case k_CCOut:
423 case k_Register:
Sean Callanan76264762010-04-02 22:27:05 +0000424 Reg = o.Reg;
425 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000426 case k_RegisterList:
427 case k_DPRRegisterList:
428 case k_SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000429 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000430 break;
Jim Grosbach862019c2011-10-18 23:02:30 +0000431 case k_VectorList:
Jim Grosbach98b05a52011-11-30 01:09:44 +0000432 case k_VectorListAllLanes:
Jim Grosbach7636bf62011-12-02 00:35:16 +0000433 case k_VectorListIndexed:
Jim Grosbach862019c2011-10-18 23:02:30 +0000434 VectorList = o.VectorList;
435 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000436 case k_CoprocNum:
437 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000438 Cop = o.Cop;
439 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000440 case k_CoprocOption:
441 CoprocOption = o.CoprocOption;
442 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000443 case k_Immediate:
Sean Callanan76264762010-04-02 22:27:05 +0000444 Imm = o.Imm;
445 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000446 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000447 MBOpt = o.MBOpt;
448 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000449 case k_Memory:
Jim Grosbache53c87b2011-10-11 15:59:20 +0000450 Memory = o.Memory;
Sean Callanan76264762010-04-02 22:27:05 +0000451 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000452 case k_PostIndexRegister:
Jim Grosbach7ce05792011-08-03 23:50:40 +0000453 PostIdxReg = o.PostIdxReg;
454 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000455 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000456 MMask = o.MMask;
457 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000458 case k_ProcIFlags:
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000459 IFlags = o.IFlags;
Owen Anderson00828302011-03-18 22:50:18 +0000460 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000461 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +0000462 ShifterImm = o.ShifterImm;
Owen Anderson00828302011-03-18 22:50:18 +0000463 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000464 case k_ShiftedRegister:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000465 RegShiftedReg = o.RegShiftedReg;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000466 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000467 case k_ShiftedImmediate:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000468 RegShiftedImm = o.RegShiftedImm;
Owen Anderson92a20222011-07-21 18:54:16 +0000469 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000470 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000471 RotImm = o.RotImm;
472 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000473 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000474 Bitfield = o.Bitfield;
475 break;
Jim Grosbach460a9052011-10-07 23:56:00 +0000476 case k_VectorIndex:
477 VectorIndex = o.VectorIndex;
478 break;
Sean Callanan76264762010-04-02 22:27:05 +0000479 }
480 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000481
Sean Callanan76264762010-04-02 22:27:05 +0000482 /// getStartLoc - Get the location of the first token of this operand.
483 SMLoc getStartLoc() const { return StartLoc; }
484 /// getEndLoc - Get the location of the last token of this operand.
485 SMLoc getEndLoc() const { return EndLoc; }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000486
Benjamin Kramer362a05a2012-04-15 17:04:27 +0000487 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
488
Daniel Dunbar8462b302010-08-11 06:36:53 +0000489 ARMCC::CondCodes getCondCode() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000490 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000491 return CC.Val;
492 }
493
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000494 unsigned getCoproc() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000495 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000496 return Cop.Val;
497 }
498
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000499 StringRef getToken() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000500 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000501 return StringRef(Tok.Data, Tok.Length);
502 }
503
504 unsigned getReg() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000505 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000506 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000507 }
508
Bill Wendling5fa22a12010-11-09 23:28:44 +0000509 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000510 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
511 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000512 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000513 }
514
Kevin Enderbycfe07242009-10-13 22:19:02 +0000515 const MCExpr *getImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000516 assert(isImm() && "Invalid access!");
Kevin Enderbycfe07242009-10-13 22:19:02 +0000517 return Imm.Val;
518 }
519
Jim Grosbach460a9052011-10-07 23:56:00 +0000520 unsigned getVectorIndex() const {
521 assert(Kind == k_VectorIndex && "Invalid access!");
522 return VectorIndex.Val;
523 }
524
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000525 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000526 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000527 return MBOpt.Val;
528 }
529
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000530 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000531 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000532 return IFlags.Val;
533 }
534
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000535 unsigned getMSRMask() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000536 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000537 return MMask.Val;
538 }
539
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000540 bool isCoprocNum() const { return Kind == k_CoprocNum; }
541 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000542 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000543 bool isCondCode() const { return Kind == k_CondCode; }
544 bool isCCOut() const { return Kind == k_CCOut; }
545 bool isITMask() const { return Kind == k_ITCondMask; }
546 bool isITCondCode() const { return Kind == k_CondCode; }
547 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbach51222d12012-01-20 18:09:51 +0000548 bool isFPImm() const {
549 if (!isImm()) return false;
550 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
551 if (!CE) return false;
552 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
553 return Val != -1;
554 }
Jim Grosbach4050bc42011-12-22 22:19:05 +0000555 bool isFBits16() const {
556 if (!isImm()) return false;
557 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
558 if (!CE) return false;
559 int64_t Value = CE->getValue();
560 return Value >= 0 && Value <= 16;
561 }
562 bool isFBits32() const {
563 if (!isImm()) return false;
564 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
565 if (!CE) return false;
566 int64_t Value = CE->getValue();
567 return Value >= 1 && Value <= 32;
568 }
Jim Grosbacha77295d2011-09-08 22:07:06 +0000569 bool isImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000570 if (!isImm()) return false;
Jim Grosbacha77295d2011-09-08 22:07:06 +0000571 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
572 if (!CE) return false;
573 int64_t Value = CE->getValue();
574 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
575 }
Jim Grosbach72f39f82011-08-24 21:22:15 +0000576 bool isImm0_1020s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000577 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000578 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
579 if (!CE) return false;
580 int64_t Value = CE->getValue();
581 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
582 }
583 bool isImm0_508s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000584 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000585 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
586 if (!CE) return false;
587 int64_t Value = CE->getValue();
588 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
589 }
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000590 bool isImm0_508s4Neg() const {
591 if (!isImm()) return false;
592 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
593 if (!CE) return false;
594 int64_t Value = -CE->getValue();
595 // explicitly exclude zero. we want that to use the normal 0_508 version.
596 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
597 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000598 bool isImm0_255() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000599 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000600 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
601 if (!CE) return false;
602 int64_t Value = CE->getValue();
603 return Value >= 0 && Value < 256;
604 }
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000605 bool isImm0_4095() const {
606 if (!isImm()) return false;
607 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
608 if (!CE) return false;
609 int64_t Value = CE->getValue();
610 return Value >= 0 && Value < 4096;
611 }
612 bool isImm0_4095Neg() const {
613 if (!isImm()) return false;
614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
615 if (!CE) return false;
616 int64_t Value = -CE->getValue();
617 return Value > 0 && Value < 4096;
618 }
Jim Grosbach587f5062011-12-02 23:34:39 +0000619 bool isImm0_1() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000620 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
622 if (!CE) return false;
623 int64_t Value = CE->getValue();
624 return Value >= 0 && Value < 2;
625 }
626 bool isImm0_3() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000627 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000628 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
629 if (!CE) return false;
630 int64_t Value = CE->getValue();
631 return Value >= 0 && Value < 4;
632 }
Jim Grosbach83ab0702011-07-13 22:01:08 +0000633 bool isImm0_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000634 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
636 if (!CE) return false;
637 int64_t Value = CE->getValue();
638 return Value >= 0 && Value < 8;
639 }
640 bool isImm0_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000641 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
643 if (!CE) return false;
644 int64_t Value = CE->getValue();
645 return Value >= 0 && Value < 16;
646 }
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000647 bool isImm0_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000648 if (!isImm()) return false;
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
650 if (!CE) return false;
651 int64_t Value = CE->getValue();
652 return Value >= 0 && Value < 32;
653 }
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000654 bool isImm0_63() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000655 if (!isImm()) return false;
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
657 if (!CE) return false;
658 int64_t Value = CE->getValue();
659 return Value >= 0 && Value < 64;
660 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000661 bool isImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000662 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
664 if (!CE) return false;
665 int64_t Value = CE->getValue();
666 return Value == 8;
667 }
668 bool isImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000669 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
671 if (!CE) return false;
672 int64_t Value = CE->getValue();
673 return Value == 16;
674 }
675 bool isImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000676 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000677 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
678 if (!CE) return false;
679 int64_t Value = CE->getValue();
680 return Value == 32;
681 }
Jim Grosbach6b044c22011-12-08 22:06:06 +0000682 bool isShrImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000683 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
685 if (!CE) return false;
686 int64_t Value = CE->getValue();
687 return Value > 0 && Value <= 8;
688 }
689 bool isShrImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000690 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
692 if (!CE) return false;
693 int64_t Value = CE->getValue();
694 return Value > 0 && Value <= 16;
695 }
696 bool isShrImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000697 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
699 if (!CE) return false;
700 int64_t Value = CE->getValue();
701 return Value > 0 && Value <= 32;
702 }
703 bool isShrImm64() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000704 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
706 if (!CE) return false;
707 int64_t Value = CE->getValue();
708 return Value > 0 && Value <= 64;
709 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000710 bool isImm1_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000711 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
713 if (!CE) return false;
714 int64_t Value = CE->getValue();
715 return Value > 0 && Value < 8;
716 }
717 bool isImm1_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000718 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
720 if (!CE) return false;
721 int64_t Value = CE->getValue();
722 return Value > 0 && Value < 16;
723 }
724 bool isImm1_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000725 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
727 if (!CE) return false;
728 int64_t Value = CE->getValue();
729 return Value > 0 && Value < 32;
730 }
Jim Grosbachf4943352011-07-25 23:09:14 +0000731 bool isImm1_16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000732 if (!isImm()) return false;
Jim Grosbachf4943352011-07-25 23:09:14 +0000733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
734 if (!CE) return false;
735 int64_t Value = CE->getValue();
736 return Value > 0 && Value < 17;
737 }
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000738 bool isImm1_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000739 if (!isImm()) return false;
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
741 if (!CE) return false;
742 int64_t Value = CE->getValue();
743 return Value > 0 && Value < 33;
744 }
Jim Grosbachee10ff82011-11-10 19:18:01 +0000745 bool isImm0_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000746 if (!isImm()) return false;
Jim Grosbachee10ff82011-11-10 19:18:01 +0000747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
748 if (!CE) return false;
749 int64_t Value = CE->getValue();
750 return Value >= 0 && Value < 33;
751 }
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000752 bool isImm0_65535() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000753 if (!isImm()) return false;
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
755 if (!CE) return false;
756 int64_t Value = CE->getValue();
757 return Value >= 0 && Value < 65536;
758 }
Jim Grosbachffa32252011-07-19 19:13:28 +0000759 bool isImm0_65535Expr() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000760 if (!isImm()) return false;
Jim Grosbachffa32252011-07-19 19:13:28 +0000761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
762 // If it's not a constant expression, it'll generate a fixup and be
763 // handled later.
764 if (!CE) return true;
765 int64_t Value = CE->getValue();
766 return Value >= 0 && Value < 65536;
767 }
Jim Grosbached838482011-07-26 16:24:27 +0000768 bool isImm24bit() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000769 if (!isImm()) return false;
Jim Grosbached838482011-07-26 16:24:27 +0000770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
771 if (!CE) return false;
772 int64_t Value = CE->getValue();
773 return Value >= 0 && Value <= 0xffffff;
774 }
Jim Grosbach70939ee2011-08-17 21:51:27 +0000775 bool isImmThumbSR() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000776 if (!isImm()) return false;
Jim Grosbach70939ee2011-08-17 21:51:27 +0000777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
778 if (!CE) return false;
779 int64_t Value = CE->getValue();
780 return Value > 0 && Value < 33;
781 }
Jim Grosbachf6c05252011-07-21 17:23:04 +0000782 bool isPKHLSLImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000783 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
785 if (!CE) return false;
786 int64_t Value = CE->getValue();
787 return Value >= 0 && Value < 32;
788 }
789 bool isPKHASRImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000790 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
792 if (!CE) return false;
793 int64_t Value = CE->getValue();
794 return Value > 0 && Value <= 32;
795 }
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000796 bool isARMSOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000797 if (!isImm()) return false;
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000798 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
799 if (!CE) return false;
800 int64_t Value = CE->getValue();
801 return ARM_AM::getSOImmVal(Value) != -1;
802 }
Jim Grosbache70ec842011-10-28 22:50:54 +0000803 bool isARMSOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000804 if (!isImm()) return false;
Jim Grosbache70ec842011-10-28 22:50:54 +0000805 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
806 if (!CE) return false;
807 int64_t Value = CE->getValue();
808 return ARM_AM::getSOImmVal(~Value) != -1;
809 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000810 bool isARMSOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000811 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
813 if (!CE) return false;
814 int64_t Value = CE->getValue();
Jim Grosbachad353c62012-03-30 19:59:02 +0000815 // Only use this when not representable as a plain so_imm.
816 return ARM_AM::getSOImmVal(Value) == -1 &&
817 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000818 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000819 bool isT2SOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000820 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
822 if (!CE) return false;
823 int64_t Value = CE->getValue();
824 return ARM_AM::getT2SOImmVal(Value) != -1;
825 }
Jim Grosbach89a63372011-10-28 22:36:30 +0000826 bool isT2SOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000827 if (!isImm()) return false;
Jim Grosbach89a63372011-10-28 22:36:30 +0000828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
829 if (!CE) return false;
830 int64_t Value = CE->getValue();
831 return ARM_AM::getT2SOImmVal(~Value) != -1;
832 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000833 bool isT2SOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000834 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
836 if (!CE) return false;
837 int64_t Value = CE->getValue();
Jim Grosbachad353c62012-03-30 19:59:02 +0000838 // Only use this when not representable as a plain so_imm.
839 return ARM_AM::getT2SOImmVal(Value) == -1 &&
840 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000841 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000842 bool isSetEndImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000843 if (!isImm()) return false;
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
847 return Value == 1 || Value == 0;
848 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000849 bool isReg() const { return Kind == k_Register; }
850 bool isRegList() const { return Kind == k_RegisterList; }
851 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
852 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
853 bool isToken() const { return Kind == k_Token; }
854 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
855 bool isMemory() const { return Kind == k_Memory; }
856 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
857 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
858 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
859 bool isRotImm() const { return Kind == k_RotateImmediate; }
860 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
861 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000862 bool isPostIdxReg() const {
Jim Grosbach430052b2011-11-14 17:52:47 +0000863 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000864 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000865 bool isMemNoOffset(bool alignOK = false) const {
Jim Grosbachf6c35c52011-10-10 23:06:42 +0000866 if (!isMemory())
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000867 return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000868 // No offset of any kind.
Jim Grosbach57dcb852011-10-11 17:29:55 +0000869 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
870 (alignOK || Memory.Alignment == 0);
871 }
Jim Grosbach0b4c6732012-01-18 22:46:46 +0000872 bool isMemPCRelImm12() const {
873 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
874 return false;
875 // Base register must be PC.
876 if (Memory.BaseRegNum != ARM::PC)
877 return false;
878 // Immediate offset in range [-4095, 4095].
879 if (!Memory.OffsetImm) return true;
880 int64_t Val = Memory.OffsetImm->getValue();
881 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
882 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000883 bool isAlignedMemory() const {
884 return isMemNoOffset(true);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000885 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000886 bool isAddrMode2() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000887 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000888 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000889 if (Memory.OffsetRegNum) return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000890 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000891 if (!Memory.OffsetImm) return true;
892 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach7ce05792011-08-03 23:50:40 +0000893 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000894 }
Jim Grosbach039c2e12011-08-04 23:01:30 +0000895 bool isAM2OffsetImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000896 if (!isImm()) return false;
Jim Grosbach039c2e12011-08-04 23:01:30 +0000897 // Immediate offset in range [-4095, 4095].
898 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
899 if (!CE) return false;
900 int64_t Val = CE->getValue();
901 return Val > -4096 && Val < 4096;
902 }
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000903 bool isAddrMode3() const {
Jim Grosbach2f196742011-12-19 23:06:24 +0000904 // If we have an immediate that's not a constant, treat it as a label
905 // reference needing a fixup. If it is a constant, it's something else
906 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000907 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +0000908 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000909 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000910 // No shifts are legal for AM3.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000911 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000912 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000913 if (Memory.OffsetRegNum) return true;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000914 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000915 if (!Memory.OffsetImm) return true;
916 int64_t Val = Memory.OffsetImm->getValue();
Silviu Barangaca3cd412012-05-11 09:10:54 +0000917 // The #-0 offset is encoded as INT32_MIN, and we have to check
918 // for this too.
919 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000920 }
921 bool isAM3Offset() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000922 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000923 return false;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000924 if (Kind == k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000925 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
926 // Immediate offset in range [-255, 255].
927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
928 if (!CE) return false;
929 int64_t Val = CE->getValue();
Jim Grosbach251bf252011-08-10 21:56:18 +0000930 // Special case, #-0 is INT32_MIN.
931 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000932 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000933 bool isAddrMode5() const {
Jim Grosbach681460f2011-11-01 01:24:45 +0000934 // If we have an immediate that's not a constant, treat it as a label
935 // reference needing a fixup. If it is a constant, it's something else
936 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000937 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach681460f2011-11-01 01:24:45 +0000938 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000939 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000940 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000941 if (Memory.OffsetRegNum) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000942 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000943 if (!Memory.OffsetImm) return true;
944 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +0000945 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbach681460f2011-11-01 01:24:45 +0000946 Val == INT32_MIN;
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000947 }
Jim Grosbach7f739be2011-09-19 22:21:13 +0000948 bool isMemTBB() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000949 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000950 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach7f739be2011-09-19 22:21:13 +0000951 return false;
952 return true;
953 }
954 bool isMemTBH() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000955 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000956 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
957 Memory.Alignment != 0 )
Jim Grosbach7f739be2011-09-19 22:21:13 +0000958 return false;
959 return true;
960 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000961 bool isMemRegOffset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000962 if (!isMemory() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendlingf4caf692010-12-14 03:36:38 +0000963 return false;
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000964 return true;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000965 }
Jim Grosbachab899c12011-09-07 23:10:15 +0000966 bool isT2MemRegOffset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000967 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
968 Memory.Alignment != 0)
Jim Grosbachab899c12011-09-07 23:10:15 +0000969 return false;
970 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000971 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbachab899c12011-09-07 23:10:15 +0000972 return true;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000973 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbachab899c12011-09-07 23:10:15 +0000974 return false;
975 return true;
976 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000977 bool isMemThumbRR() const {
978 // Thumb reg+reg addressing is simple. Just two registers, a base and
979 // an offset. No shifts, negations or any other complicating factors.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000980 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000981 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000982 return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000983 return isARMLowRegister(Memory.BaseRegNum) &&
984 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +0000985 }
986 bool isMemThumbRIs4() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000987 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000988 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach60f91a32011-08-19 17:55:24 +0000989 return false;
990 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000991 if (!Memory.OffsetImm) return true;
992 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +0000993 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
994 }
Jim Grosbach38466302011-08-19 18:55:51 +0000995 bool isMemThumbRIs2() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000996 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000997 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach38466302011-08-19 18:55:51 +0000998 return false;
999 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001000 if (!Memory.OffsetImm) return true;
1001 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach38466302011-08-19 18:55:51 +00001002 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1003 }
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001004 bool isMemThumbRIs1() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +00001005 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001006 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001007 return false;
1008 // Immediate offset in range [0, 31].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001009 if (!Memory.OffsetImm) return true;
1010 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001011 return Val >= 0 && Val <= 31;
1012 }
Jim Grosbachecd85892011-08-19 18:13:48 +00001013 bool isMemThumbSPI() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001014 if (!isMemory() || Memory.OffsetRegNum != 0 ||
1015 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbachecd85892011-08-19 18:13:48 +00001016 return false;
1017 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001018 if (!Memory.OffsetImm) return true;
1019 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +00001020 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001021 }
Jim Grosbacha77295d2011-09-08 22:07:06 +00001022 bool isMemImm8s4Offset() const {
Jim Grosbach2f196742011-12-19 23:06:24 +00001023 // If we have an immediate that's not a constant, treat it as a label
1024 // reference needing a fixup. If it is a constant, it's something else
1025 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001026 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +00001027 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +00001028 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha77295d2011-09-08 22:07:06 +00001029 return false;
1030 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001031 if (!Memory.OffsetImm) return true;
1032 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha77295d2011-09-08 22:07:06 +00001033 return Val >= -1020 && Val <= 1020 && (Val & 3) == 0;
1034 }
Jim Grosbachb6aed502011-09-09 18:37:27 +00001035 bool isMemImm0_1020s4Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001036 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachb6aed502011-09-09 18:37:27 +00001037 return false;
1038 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001039 if (!Memory.OffsetImm) return true;
1040 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachb6aed502011-09-09 18:37:27 +00001041 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1042 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001043 bool isMemImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001044 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001045 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001046 // Base reg of PC isn't allowed for these encodings.
1047 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001048 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001049 if (!Memory.OffsetImm) return true;
1050 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson4d2a0012011-09-23 22:25:02 +00001051 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001052 }
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001053 bool isMemPosImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001054 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001055 return false;
1056 // Immediate offset in range [0, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001057 if (!Memory.OffsetImm) return true;
1058 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001059 return Val >= 0 && Val < 256;
1060 }
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001061 bool isMemNegImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001062 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001063 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001064 // Base reg of PC isn't allowed for these encodings.
1065 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001066 // Immediate offset in range [-255, -1].
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001067 if (!Memory.OffsetImm) return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +00001068 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001069 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001070 }
1071 bool isMemUImm12Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001072 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001073 return false;
1074 // Immediate offset in range [0, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001075 if (!Memory.OffsetImm) return true;
1076 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001077 return (Val >= 0 && Val < 4096);
1078 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001079 bool isMemImm12Offset() const {
Jim Grosbach09176e12011-08-08 20:59:31 +00001080 // If we have an immediate that's not a constant, treat it as a label
1081 // reference needing a fixup. If it is a constant, it's something else
1082 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001083 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach09176e12011-08-08 20:59:31 +00001084 return true;
1085
Jim Grosbach57dcb852011-10-11 17:29:55 +00001086 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001087 return false;
1088 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001089 if (!Memory.OffsetImm) return true;
1090 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +00001091 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001092 }
1093 bool isPostIdxImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001094 if (!isImm()) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001095 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1096 if (!CE) return false;
1097 int64_t Val = CE->getValue();
Owen Anderson63553c72011-08-29 17:17:09 +00001098 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001099 }
Jim Grosbach2bd01182011-10-11 21:55:36 +00001100 bool isPostIdxImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001101 if (!isImm()) return false;
Jim Grosbach2bd01182011-10-11 21:55:36 +00001102 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1103 if (!CE) return false;
1104 int64_t Val = CE->getValue();
1105 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1106 (Val == INT32_MIN);
1107 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001108
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001109 bool isMSRMask() const { return Kind == k_MSRMask; }
1110 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001111
Jim Grosbach0e387b22011-10-17 22:26:03 +00001112 // NEON operands.
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001113 bool isSingleSpacedVectorList() const {
1114 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1115 }
1116 bool isDoubleSpacedVectorList() const {
1117 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1118 }
Jim Grosbach862019c2011-10-18 23:02:30 +00001119 bool isVecListOneD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001120 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach862019c2011-10-18 23:02:30 +00001121 return VectorList.Count == 1;
1122 }
1123
Jim Grosbach28f08c92012-03-05 19:33:30 +00001124 bool isVecListDPair() const {
1125 if (!isSingleSpacedVectorList()) return false;
1126 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1127 .contains(VectorList.RegNum));
1128 }
1129
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001130 bool isVecListThreeD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001131 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001132 return VectorList.Count == 3;
1133 }
1134
Jim Grosbachb6310312011-10-21 20:35:01 +00001135 bool isVecListFourD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001136 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachb6310312011-10-21 20:35:01 +00001137 return VectorList.Count == 4;
1138 }
1139
Jim Grosbachc3384c92012-03-05 21:43:40 +00001140 bool isVecListDPairSpaced() const {
Kevin Enderby9f2e1602012-03-20 17:41:51 +00001141 if (isSingleSpacedVectorList()) return false;
Jim Grosbachc3384c92012-03-05 21:43:40 +00001142 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1143 .contains(VectorList.RegNum));
1144 }
1145
Jim Grosbachc387fc62012-01-23 23:20:46 +00001146 bool isVecListThreeQ() const {
1147 if (!isDoubleSpacedVectorList()) return false;
1148 return VectorList.Count == 3;
1149 }
1150
Jim Grosbach7945ead2012-01-24 00:43:12 +00001151 bool isVecListFourQ() const {
1152 if (!isDoubleSpacedVectorList()) return false;
1153 return VectorList.Count == 4;
1154 }
1155
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001156 bool isSingleSpacedVectorAllLanes() const {
1157 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1158 }
1159 bool isDoubleSpacedVectorAllLanes() const {
1160 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1161 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00001162 bool isVecListOneDAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001163 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach98b05a52011-11-30 01:09:44 +00001164 return VectorList.Count == 1;
1165 }
1166
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001167 bool isVecListDPairAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001168 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001169 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1170 .contains(VectorList.RegNum));
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001171 }
1172
Jim Grosbach4d0983a2012-03-06 23:10:38 +00001173 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001174 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach13af2222011-11-30 18:21:25 +00001175 return VectorList.Count == 2;
1176 }
1177
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001178 bool isVecListThreeDAllLanes() const {
1179 if (!isSingleSpacedVectorAllLanes()) return false;
1180 return VectorList.Count == 3;
1181 }
1182
1183 bool isVecListThreeQAllLanes() const {
1184 if (!isDoubleSpacedVectorAllLanes()) return false;
1185 return VectorList.Count == 3;
1186 }
1187
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001188 bool isVecListFourDAllLanes() const {
1189 if (!isSingleSpacedVectorAllLanes()) return false;
1190 return VectorList.Count == 4;
1191 }
1192
1193 bool isVecListFourQAllLanes() const {
1194 if (!isDoubleSpacedVectorAllLanes()) return false;
1195 return VectorList.Count == 4;
1196 }
1197
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001198 bool isSingleSpacedVectorIndexed() const {
1199 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1200 }
1201 bool isDoubleSpacedVectorIndexed() const {
1202 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1203 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00001204 bool isVecListOneDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001205 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach7636bf62011-12-02 00:35:16 +00001206 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1207 }
1208
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001209 bool isVecListOneDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001210 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001211 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1212 }
1213
1214 bool isVecListOneDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001215 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001216 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1217 }
1218
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001219 bool isVecListTwoDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001220 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001221 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1222 }
1223
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001224 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001225 if (!isSingleSpacedVectorIndexed()) return false;
1226 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1227 }
1228
1229 bool isVecListTwoQWordIndexed() const {
1230 if (!isDoubleSpacedVectorIndexed()) return false;
1231 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1232 }
1233
1234 bool isVecListTwoQHWordIndexed() const {
1235 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001236 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1237 }
1238
1239 bool isVecListTwoDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001240 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001241 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1242 }
1243
Jim Grosbach3a678af2012-01-23 21:53:26 +00001244 bool isVecListThreeDByteIndexed() const {
1245 if (!isSingleSpacedVectorIndexed()) return false;
1246 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1247 }
1248
1249 bool isVecListThreeDHWordIndexed() const {
1250 if (!isSingleSpacedVectorIndexed()) return false;
1251 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1252 }
1253
1254 bool isVecListThreeQWordIndexed() const {
1255 if (!isDoubleSpacedVectorIndexed()) return false;
1256 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1257 }
1258
1259 bool isVecListThreeQHWordIndexed() const {
1260 if (!isDoubleSpacedVectorIndexed()) return false;
1261 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1262 }
1263
1264 bool isVecListThreeDWordIndexed() const {
1265 if (!isSingleSpacedVectorIndexed()) return false;
1266 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1267 }
1268
Jim Grosbache983a132012-01-24 18:37:25 +00001269 bool isVecListFourDByteIndexed() const {
1270 if (!isSingleSpacedVectorIndexed()) return false;
1271 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1272 }
1273
1274 bool isVecListFourDHWordIndexed() const {
1275 if (!isSingleSpacedVectorIndexed()) return false;
1276 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1277 }
1278
1279 bool isVecListFourQWordIndexed() const {
1280 if (!isDoubleSpacedVectorIndexed()) return false;
1281 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1282 }
1283
1284 bool isVecListFourQHWordIndexed() const {
1285 if (!isDoubleSpacedVectorIndexed()) return false;
1286 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1287 }
1288
1289 bool isVecListFourDWordIndexed() const {
1290 if (!isSingleSpacedVectorIndexed()) return false;
1291 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1292 }
1293
Jim Grosbach460a9052011-10-07 23:56:00 +00001294 bool isVectorIndex8() const {
1295 if (Kind != k_VectorIndex) return false;
1296 return VectorIndex.Val < 8;
1297 }
1298 bool isVectorIndex16() const {
1299 if (Kind != k_VectorIndex) return false;
1300 return VectorIndex.Val < 4;
1301 }
1302 bool isVectorIndex32() const {
1303 if (Kind != k_VectorIndex) return false;
1304 return VectorIndex.Val < 2;
1305 }
1306
Jim Grosbach0e387b22011-10-17 22:26:03 +00001307 bool isNEONi8splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001308 if (!isImm()) return false;
Jim Grosbach0e387b22011-10-17 22:26:03 +00001309 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1310 // Must be a constant.
1311 if (!CE) return false;
1312 int64_t Value = CE->getValue();
1313 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1314 // value.
Jim Grosbach0e387b22011-10-17 22:26:03 +00001315 return Value >= 0 && Value < 256;
1316 }
Jim Grosbach460a9052011-10-07 23:56:00 +00001317
Jim Grosbachea461102011-10-17 23:09:09 +00001318 bool isNEONi16splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001319 if (!isImm()) return false;
Jim Grosbachea461102011-10-17 23:09:09 +00001320 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1321 // Must be a constant.
1322 if (!CE) return false;
1323 int64_t Value = CE->getValue();
1324 // i16 value in the range [0,255] or [0x0100, 0xff00]
1325 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1326 }
1327
Jim Grosbach6248a542011-10-18 00:22:00 +00001328 bool isNEONi32splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001329 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001330 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1331 // Must be a constant.
1332 if (!CE) return false;
1333 int64_t Value = CE->getValue();
1334 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1335 return (Value >= 0 && Value < 256) ||
1336 (Value >= 0x0100 && Value <= 0xff00) ||
1337 (Value >= 0x010000 && Value <= 0xff0000) ||
1338 (Value >= 0x01000000 && Value <= 0xff000000);
1339 }
1340
1341 bool isNEONi32vmov() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001342 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001343 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1344 // Must be a constant.
1345 if (!CE) return false;
1346 int64_t Value = CE->getValue();
1347 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1348 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1349 return (Value >= 0 && Value < 256) ||
1350 (Value >= 0x0100 && Value <= 0xff00) ||
1351 (Value >= 0x010000 && Value <= 0xff0000) ||
1352 (Value >= 0x01000000 && Value <= 0xff000000) ||
1353 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1354 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1355 }
Jim Grosbach9b087852011-12-19 23:51:07 +00001356 bool isNEONi32vmovNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001357 if (!isImm()) return false;
Jim Grosbach9b087852011-12-19 23:51:07 +00001358 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1359 // Must be a constant.
1360 if (!CE) return false;
1361 int64_t Value = ~CE->getValue();
1362 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1363 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1364 return (Value >= 0 && Value < 256) ||
1365 (Value >= 0x0100 && Value <= 0xff00) ||
1366 (Value >= 0x010000 && Value <= 0xff0000) ||
1367 (Value >= 0x01000000 && Value <= 0xff000000) ||
1368 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1369 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1370 }
Jim Grosbach6248a542011-10-18 00:22:00 +00001371
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001372 bool isNEONi64splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001373 if (!isImm()) return false;
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001374 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1375 // Must be a constant.
1376 if (!CE) return false;
1377 uint64_t Value = CE->getValue();
1378 // i64 value with each byte being either 0 or 0xff.
1379 for (unsigned i = 0; i < 8; ++i)
1380 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1381 return true;
1382 }
1383
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001384 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +00001385 // Add as immediates when possible. Null MCExpr = 0.
1386 if (Expr == 0)
1387 Inst.addOperand(MCOperand::CreateImm(0));
1388 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001389 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1390 else
1391 Inst.addOperand(MCOperand::CreateExpr(Expr));
1392 }
1393
Daniel Dunbar8462b302010-08-11 06:36:53 +00001394 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001395 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +00001396 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +00001397 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1398 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +00001399 }
1400
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001401 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1402 assert(N == 1 && "Invalid number of operands!");
1403 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1404 }
1405
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00001406 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1407 assert(N == 1 && "Invalid number of operands!");
1408 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1409 }
1410
1411 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1412 assert(N == 1 && "Invalid number of operands!");
1413 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1414 }
1415
Jim Grosbach89df9962011-08-26 21:43:41 +00001416 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1417 assert(N == 1 && "Invalid number of operands!");
1418 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1419 }
1420
1421 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1422 assert(N == 1 && "Invalid number of operands!");
1423 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1424 }
1425
Jim Grosbachd67641b2010-12-06 18:21:12 +00001426 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1427 assert(N == 1 && "Invalid number of operands!");
1428 Inst.addOperand(MCOperand::CreateReg(getReg()));
1429 }
1430
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001431 void addRegOperands(MCInst &Inst, unsigned N) const {
1432 assert(N == 1 && "Invalid number of operands!");
1433 Inst.addOperand(MCOperand::CreateReg(getReg()));
1434 }
1435
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001436 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbache8606dc2011-07-13 17:50:29 +00001437 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001438 assert(isRegShiftedReg() &&
1439 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001440 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1441 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001442 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001443 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001444 }
1445
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001446 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson152d4a42011-07-21 23:38:37 +00001447 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001448 assert(isRegShiftedImm() &&
1449 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001450 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonb56e4112012-04-25 18:00:18 +00001451 // Shift of #32 is encoded as 0 where permitted
1452 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Anderson92a20222011-07-21 18:54:16 +00001453 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonb56e4112012-04-25 18:00:18 +00001454 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Anderson92a20222011-07-21 18:54:16 +00001455 }
1456
Jim Grosbach580f4a92011-07-25 22:20:28 +00001457 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson00828302011-03-18 22:50:18 +00001458 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach580f4a92011-07-25 22:20:28 +00001459 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1460 ShifterImm.Imm));
Owen Anderson00828302011-03-18 22:50:18 +00001461 }
1462
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001463 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +00001464 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +00001465 const SmallVectorImpl<unsigned> &RegList = getRegList();
1466 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00001467 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1468 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001469 }
1470
Bill Wendling0f630752010-11-17 04:32:08 +00001471 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1472 addRegListOperands(Inst, N);
1473 }
1474
1475 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1476 addRegListOperands(Inst, N);
1477 }
1478
Jim Grosbach7e1547e2011-07-27 20:15:40 +00001479 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1480 assert(N == 1 && "Invalid number of operands!");
1481 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1482 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1483 }
1484
Jim Grosbach293a2ee2011-07-28 21:34:26 +00001485 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1486 assert(N == 1 && "Invalid number of operands!");
1487 // Munge the lsb/width into a bitfield mask.
1488 unsigned lsb = Bitfield.LSB;
1489 unsigned width = Bitfield.Width;
1490 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1491 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1492 (32 - (lsb + width)));
1493 Inst.addOperand(MCOperand::CreateImm(Mask));
1494 }
1495
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001496 void addImmOperands(MCInst &Inst, unsigned N) const {
1497 assert(N == 1 && "Invalid number of operands!");
1498 addExpr(Inst, getImm());
1499 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001500
Jim Grosbach4050bc42011-12-22 22:19:05 +00001501 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1502 assert(N == 1 && "Invalid number of operands!");
1503 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1504 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1505 }
1506
1507 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1508 assert(N == 1 && "Invalid number of operands!");
1509 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1510 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1511 }
1512
Jim Grosbach9d390362011-10-03 23:38:36 +00001513 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1514 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach51222d12012-01-20 18:09:51 +00001515 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1516 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1517 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach9d390362011-10-03 23:38:36 +00001518 }
1519
Jim Grosbacha77295d2011-09-08 22:07:06 +00001520 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1521 assert(N == 1 && "Invalid number of operands!");
1522 // FIXME: We really want to scale the value here, but the LDRD/STRD
1523 // instruction don't encode operands that way yet.
1524 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1525 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1526 }
1527
Jim Grosbach72f39f82011-08-24 21:22:15 +00001528 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1529 assert(N == 1 && "Invalid number of operands!");
1530 // The immediate is scaled by four in the encoding and is stored
1531 // in the MCInst as such. Lop off the low two bits here.
1532 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1533 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1534 }
1535
Jim Grosbach4e53fe82012-04-05 20:57:13 +00001536 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1537 assert(N == 1 && "Invalid number of operands!");
1538 // The immediate is scaled by four in the encoding and is stored
1539 // in the MCInst as such. Lop off the low two bits here.
1540 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1541 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1542 }
1543
Jim Grosbach72f39f82011-08-24 21:22:15 +00001544 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1545 assert(N == 1 && "Invalid number of operands!");
1546 // The immediate is scaled by four in the encoding and is stored
1547 // in the MCInst as such. Lop off the low two bits here.
1548 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1549 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1550 }
1551
Jim Grosbachf4943352011-07-25 23:09:14 +00001552 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1553 assert(N == 1 && "Invalid number of operands!");
1554 // The constant encodes as the immediate-1, and we store in the instruction
1555 // the bits as encoded, so subtract off one here.
1556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1557 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1558 }
1559
Jim Grosbach4a5ffb32011-07-22 23:16:18 +00001560 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1561 assert(N == 1 && "Invalid number of operands!");
1562 // The constant encodes as the immediate-1, and we store in the instruction
1563 // the bits as encoded, so subtract off one here.
1564 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1565 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1566 }
1567
Jim Grosbach70939ee2011-08-17 21:51:27 +00001568 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1569 assert(N == 1 && "Invalid number of operands!");
1570 // The constant encodes as the immediate, except for 32, which encodes as
1571 // zero.
1572 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1573 unsigned Imm = CE->getValue();
1574 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1575 }
1576
Jim Grosbachf6c05252011-07-21 17:23:04 +00001577 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1578 assert(N == 1 && "Invalid number of operands!");
1579 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1580 // the instruction as well.
1581 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1582 int Val = CE->getValue();
1583 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1584 }
1585
Jim Grosbach89a63372011-10-28 22:36:30 +00001586 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1587 assert(N == 1 && "Invalid number of operands!");
1588 // The operand is actually a t2_so_imm, but we have its bitwise
1589 // negation in the assembly source, so twiddle it here.
1590 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1591 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1592 }
1593
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001594 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1595 assert(N == 1 && "Invalid number of operands!");
1596 // The operand is actually a t2_so_imm, but we have its
1597 // negation in the assembly source, so twiddle it here.
1598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1599 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1600 }
1601
Jim Grosbach4e53fe82012-04-05 20:57:13 +00001602 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1603 assert(N == 1 && "Invalid number of operands!");
1604 // The operand is actually an imm0_4095, but we have its
1605 // negation in the assembly source, so twiddle it here.
1606 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1607 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1608 }
1609
Jim Grosbache70ec842011-10-28 22:50:54 +00001610 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1611 assert(N == 1 && "Invalid number of operands!");
1612 // The operand is actually a so_imm, but we have its bitwise
1613 // negation in the assembly source, so twiddle it here.
1614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1615 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1616 }
1617
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001618 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1619 assert(N == 1 && "Invalid number of operands!");
1620 // The operand is actually a so_imm, but we have its
1621 // negation in the assembly source, so twiddle it here.
1622 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1623 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1624 }
1625
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001626 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1627 assert(N == 1 && "Invalid number of operands!");
1628 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1629 }
1630
Jim Grosbach7ce05792011-08-03 23:50:40 +00001631 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1632 assert(N == 1 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001633 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00001634 }
1635
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001636 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1637 assert(N == 1 && "Invalid number of operands!");
1638 int32_t Imm = Memory.OffsetImm->getValue();
1639 // FIXME: Handle #-0
1640 if (Imm == INT32_MIN) Imm = 0;
1641 Inst.addOperand(MCOperand::CreateImm(Imm));
1642 }
1643
Jim Grosbach57dcb852011-10-11 17:29:55 +00001644 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1645 assert(N == 2 && "Invalid number of operands!");
1646 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1647 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1648 }
1649
Jim Grosbach7ce05792011-08-03 23:50:40 +00001650 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1651 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001652 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1653 if (!Memory.OffsetRegNum) {
Jim Grosbach7ce05792011-08-03 23:50:40 +00001654 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1655 // Special case for #-0
1656 if (Val == INT32_MIN) Val = 0;
1657 if (Val < 0) Val = -Val;
1658 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1659 } else {
1660 // For register offset, we encode the shift type and negation flag
1661 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001662 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1663 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001664 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001665 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1666 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001667 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001668 }
1669
Jim Grosbach039c2e12011-08-04 23:01:30 +00001670 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1671 assert(N == 2 && "Invalid number of operands!");
1672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1673 assert(CE && "non-constant AM2OffsetImm operand!");
1674 int32_t Val = CE->getValue();
1675 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1676 // Special case for #-0
1677 if (Val == INT32_MIN) Val = 0;
1678 if (Val < 0) Val = -Val;
1679 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1680 Inst.addOperand(MCOperand::CreateReg(0));
1681 Inst.addOperand(MCOperand::CreateImm(Val));
1682 }
1683
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001684 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1685 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001686 // If we have an immediate that's not a constant, treat it as a label
1687 // reference needing a fixup. If it is a constant, it's something else
1688 // and we reject it.
1689 if (isImm()) {
1690 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1691 Inst.addOperand(MCOperand::CreateReg(0));
1692 Inst.addOperand(MCOperand::CreateImm(0));
1693 return;
1694 }
1695
Jim Grosbache53c87b2011-10-11 15:59:20 +00001696 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1697 if (!Memory.OffsetRegNum) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001698 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::getAM3Opc(AddSub, Val);
1703 } else {
1704 // For register offset, we encode the shift type and negation flag
1705 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001706 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001707 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001708 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1709 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001710 Inst.addOperand(MCOperand::CreateImm(Val));
1711 }
1712
1713 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1714 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001715 if (Kind == k_PostIndexRegister) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001716 int32_t Val =
1717 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1718 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1719 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach251bf252011-08-10 21:56:18 +00001720 return;
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001721 }
1722
1723 // Constant offset.
1724 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1725 int32_t Val = CE->getValue();
1726 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1727 // Special case for #-0
1728 if (Val == INT32_MIN) Val = 0;
1729 if (Val < 0) Val = -Val;
Jim Grosbach251bf252011-08-10 21:56:18 +00001730 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001731 Inst.addOperand(MCOperand::CreateReg(0));
1732 Inst.addOperand(MCOperand::CreateImm(Val));
1733 }
1734
Jim Grosbach7ce05792011-08-03 23:50:40 +00001735 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1736 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach681460f2011-11-01 01:24:45 +00001737 // If we have an immediate that's not a constant, treat it as a label
1738 // reference needing a fixup. If it is a constant, it's something else
1739 // and we reject it.
1740 if (isImm()) {
1741 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1742 Inst.addOperand(MCOperand::CreateImm(0));
1743 return;
1744 }
1745
Jim Grosbach7ce05792011-08-03 23:50:40 +00001746 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001747 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001748 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1749 // Special case for #-0
1750 if (Val == INT32_MIN) Val = 0;
1751 if (Val < 0) Val = -Val;
1752 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001753 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001754 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001755 }
1756
Jim Grosbacha77295d2011-09-08 22:07:06 +00001757 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1758 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001759 // If we have an immediate that's not a constant, treat it as a label
1760 // reference needing a fixup. If it is a constant, it's something else
1761 // and we reject it.
1762 if (isImm()) {
1763 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1764 Inst.addOperand(MCOperand::CreateImm(0));
1765 return;
1766 }
1767
Jim Grosbache53c87b2011-10-11 15:59:20 +00001768 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1769 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha77295d2011-09-08 22:07:06 +00001770 Inst.addOperand(MCOperand::CreateImm(Val));
1771 }
1772
Jim Grosbachb6aed502011-09-09 18:37:27 +00001773 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1774 assert(N == 2 && "Invalid number of operands!");
1775 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001776 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1777 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachb6aed502011-09-09 18:37:27 +00001778 Inst.addOperand(MCOperand::CreateImm(Val));
1779 }
1780
Jim Grosbach7ce05792011-08-03 23:50:40 +00001781 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1782 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001783 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1784 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001785 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner14b93852010-10-29 00:27:31 +00001786 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001787
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001788 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1789 addMemImm8OffsetOperands(Inst, N);
1790 }
1791
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001792 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001793 addMemImm8OffsetOperands(Inst, N);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001794 }
1795
1796 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1797 assert(N == 2 && "Invalid number of operands!");
1798 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001799 if (isImm()) {
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001800 addExpr(Inst, getImm());
1801 Inst.addOperand(MCOperand::CreateImm(0));
1802 return;
1803 }
1804
1805 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001806 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1807 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001808 Inst.addOperand(MCOperand::CreateImm(Val));
1809 }
1810
Jim Grosbach7ce05792011-08-03 23:50:40 +00001811 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1812 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach09176e12011-08-08 20:59:31 +00001813 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001814 if (isImm()) {
Jim Grosbach09176e12011-08-08 20:59:31 +00001815 addExpr(Inst, getImm());
1816 Inst.addOperand(MCOperand::CreateImm(0));
1817 return;
1818 }
1819
1820 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001821 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1822 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001823 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendlingf4caf692010-12-14 03:36:38 +00001824 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001825
Jim Grosbach7f739be2011-09-19 22:21:13 +00001826 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1827 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001828 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1829 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001830 }
1831
1832 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1833 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001834 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1835 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001836 }
1837
Jim Grosbach7ce05792011-08-03 23:50:40 +00001838 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1839 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001840 unsigned Val =
1841 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1842 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001843 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1844 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001845 Inst.addOperand(MCOperand::CreateImm(Val));
1846 }
1847
Jim Grosbachab899c12011-09-07 23:10:15 +00001848 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1849 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001850 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1851 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1852 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbachab899c12011-09-07 23:10:15 +00001853 }
1854
Jim Grosbach7ce05792011-08-03 23:50:40 +00001855 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1856 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001857 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1858 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001859 }
1860
Jim Grosbach60f91a32011-08-19 17:55:24 +00001861 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1862 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001863 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1864 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +00001865 Inst.addOperand(MCOperand::CreateImm(Val));
1866 }
1867
Jim Grosbach38466302011-08-19 18:55:51 +00001868 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1869 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001870 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1871 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach38466302011-08-19 18:55:51 +00001872 Inst.addOperand(MCOperand::CreateImm(Val));
1873 }
1874
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001875 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1876 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001877 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1878 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001879 Inst.addOperand(MCOperand::CreateImm(Val));
1880 }
1881
Jim Grosbachecd85892011-08-19 18:13:48 +00001882 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1883 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001884 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1885 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachecd85892011-08-19 18:13:48 +00001886 Inst.addOperand(MCOperand::CreateImm(Val));
1887 }
1888
Jim Grosbach7ce05792011-08-03 23:50:40 +00001889 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1890 assert(N == 1 && "Invalid number of operands!");
1891 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1892 assert(CE && "non-constant post-idx-imm8 operand!");
1893 int Imm = CE->getValue();
1894 bool isAdd = Imm >= 0;
Owen Anderson63553c72011-08-29 17:17:09 +00001895 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001896 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1897 Inst.addOperand(MCOperand::CreateImm(Imm));
1898 }
1899
Jim Grosbach2bd01182011-10-11 21:55:36 +00001900 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1901 assert(N == 1 && "Invalid number of operands!");
1902 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1903 assert(CE && "non-constant post-idx-imm8s4 operand!");
1904 int Imm = CE->getValue();
1905 bool isAdd = Imm >= 0;
1906 if (Imm == INT32_MIN) Imm = 0;
1907 // Immediate is scaled by 4.
1908 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1909 Inst.addOperand(MCOperand::CreateImm(Imm));
1910 }
1911
Jim Grosbach7ce05792011-08-03 23:50:40 +00001912 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1913 assert(N == 2 && "Invalid number of operands!");
1914 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00001915 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1916 }
1917
1918 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1919 assert(N == 2 && "Invalid number of operands!");
1920 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1921 // The sign, shift type, and shift amount are encoded in a single operand
1922 // using the AM2 encoding helpers.
1923 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1924 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1925 PostIdxReg.ShiftTy);
1926 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001927 }
1928
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001929 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1930 assert(N == 1 && "Invalid number of operands!");
1931 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1932 }
1933
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001934 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1935 assert(N == 1 && "Invalid number of operands!");
1936 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1937 }
1938
Jim Grosbach6029b6d2011-11-29 23:51:09 +00001939 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach862019c2011-10-18 23:02:30 +00001940 assert(N == 1 && "Invalid number of operands!");
1941 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1942 }
1943
Jim Grosbach7636bf62011-12-02 00:35:16 +00001944 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1945 assert(N == 2 && "Invalid number of operands!");
1946 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1947 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1948 }
1949
Jim Grosbach460a9052011-10-07 23:56:00 +00001950 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1951 assert(N == 1 && "Invalid number of operands!");
1952 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1953 }
1954
1955 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1956 assert(N == 1 && "Invalid number of operands!");
1957 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1958 }
1959
1960 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1961 assert(N == 1 && "Invalid number of operands!");
1962 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1963 }
1964
Jim Grosbach0e387b22011-10-17 22:26:03 +00001965 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1966 assert(N == 1 && "Invalid number of operands!");
1967 // The immediate encodes the type of constant as well as the value.
1968 // Mask in that this is an i8 splat.
1969 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1970 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1971 }
1972
Jim Grosbachea461102011-10-17 23:09:09 +00001973 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1974 assert(N == 1 && "Invalid number of operands!");
1975 // The immediate encodes the type of constant as well as the value.
1976 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1977 unsigned Value = CE->getValue();
1978 if (Value >= 256)
1979 Value = (Value >> 8) | 0xa00;
1980 else
1981 Value |= 0x800;
1982 Inst.addOperand(MCOperand::CreateImm(Value));
1983 }
1984
Jim Grosbach6248a542011-10-18 00:22:00 +00001985 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
1986 assert(N == 1 && "Invalid number of operands!");
1987 // The immediate encodes the type of constant as well as the value.
1988 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1989 unsigned Value = CE->getValue();
1990 if (Value >= 256 && Value <= 0xff00)
1991 Value = (Value >> 8) | 0x200;
1992 else if (Value > 0xffff && Value <= 0xff0000)
1993 Value = (Value >> 16) | 0x400;
1994 else if (Value > 0xffffff)
1995 Value = (Value >> 24) | 0x600;
1996 Inst.addOperand(MCOperand::CreateImm(Value));
1997 }
1998
1999 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2000 assert(N == 1 && "Invalid number of operands!");
2001 // The immediate encodes the type of constant as well as the value.
2002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2003 unsigned Value = CE->getValue();
2004 if (Value >= 256 && Value <= 0xffff)
2005 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2006 else if (Value > 0xffff && Value <= 0xffffff)
2007 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2008 else if (Value > 0xffffff)
2009 Value = (Value >> 24) | 0x600;
2010 Inst.addOperand(MCOperand::CreateImm(Value));
2011 }
2012
Jim Grosbach9b087852011-12-19 23:51:07 +00002013 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2014 assert(N == 1 && "Invalid number of operands!");
2015 // The immediate encodes the type of constant as well as the value.
2016 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2017 unsigned Value = ~CE->getValue();
2018 if (Value >= 256 && Value <= 0xffff)
2019 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2020 else if (Value > 0xffff && Value <= 0xffffff)
2021 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2022 else if (Value > 0xffffff)
2023 Value = (Value >> 24) | 0x600;
2024 Inst.addOperand(MCOperand::CreateImm(Value));
2025 }
2026
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00002027 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2028 assert(N == 1 && "Invalid number of operands!");
2029 // The immediate encodes the type of constant as well as the value.
2030 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2031 uint64_t Value = CE->getValue();
2032 unsigned Imm = 0;
2033 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2034 Imm |= (Value & 1) << i;
2035 }
2036 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2037 }
2038
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002039 virtual void print(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +00002040
Jim Grosbach89df9962011-08-26 21:43:41 +00002041 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002042 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach89df9962011-08-26 21:43:41 +00002043 Op->ITMask.Mask = Mask;
2044 Op->StartLoc = S;
2045 Op->EndLoc = S;
2046 return Op;
2047 }
2048
Chris Lattner3a697562010-10-28 17:20:03 +00002049 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002050 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002051 Op->CC.Val = CC;
2052 Op->StartLoc = S;
2053 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002054 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002055 }
2056
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002057 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002058 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002059 Op->Cop.Val = CopVal;
2060 Op->StartLoc = S;
2061 Op->EndLoc = S;
2062 return Op;
2063 }
2064
2065 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002066 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002067 Op->Cop.Val = CopVal;
2068 Op->StartLoc = S;
2069 Op->EndLoc = S;
2070 return Op;
2071 }
2072
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002073 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2074 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2075 Op->Cop.Val = Val;
2076 Op->StartLoc = S;
2077 Op->EndLoc = E;
2078 return Op;
2079 }
2080
Jim Grosbachd67641b2010-12-06 18:21:12 +00002081 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002082 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbachd67641b2010-12-06 18:21:12 +00002083 Op->Reg.RegNum = RegNum;
2084 Op->StartLoc = S;
2085 Op->EndLoc = S;
2086 return Op;
2087 }
2088
Chris Lattner3a697562010-10-28 17:20:03 +00002089 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002090 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan76264762010-04-02 22:27:05 +00002091 Op->Tok.Data = Str.data();
2092 Op->Tok.Length = Str.size();
2093 Op->StartLoc = S;
2094 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002095 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002096 }
2097
Bill Wendling50d0f582010-11-18 23:43:05 +00002098 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002099 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan76264762010-04-02 22:27:05 +00002100 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +00002101 Op->StartLoc = S;
2102 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002103 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002104 }
2105
Jim Grosbache8606dc2011-07-13 17:50:29 +00002106 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2107 unsigned SrcReg,
2108 unsigned ShiftReg,
2109 unsigned ShiftImm,
2110 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002111 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002112 Op->RegShiftedReg.ShiftTy = ShTy;
2113 Op->RegShiftedReg.SrcReg = SrcReg;
2114 Op->RegShiftedReg.ShiftReg = ShiftReg;
2115 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002116 Op->StartLoc = S;
2117 Op->EndLoc = E;
2118 return Op;
2119 }
2120
Owen Anderson92a20222011-07-21 18:54:16 +00002121 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2122 unsigned SrcReg,
2123 unsigned ShiftImm,
2124 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002125 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002126 Op->RegShiftedImm.ShiftTy = ShTy;
2127 Op->RegShiftedImm.SrcReg = SrcReg;
2128 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Anderson92a20222011-07-21 18:54:16 +00002129 Op->StartLoc = S;
2130 Op->EndLoc = E;
2131 return Op;
2132 }
2133
Jim Grosbach580f4a92011-07-25 22:20:28 +00002134 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002135 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002136 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach580f4a92011-07-25 22:20:28 +00002137 Op->ShifterImm.isASR = isASR;
2138 Op->ShifterImm.Imm = Imm;
Owen Anderson00828302011-03-18 22:50:18 +00002139 Op->StartLoc = S;
2140 Op->EndLoc = E;
2141 return Op;
2142 }
2143
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002144 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002145 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002146 Op->RotImm.Imm = Imm;
2147 Op->StartLoc = S;
2148 Op->EndLoc = E;
2149 return Op;
2150 }
2151
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002152 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2153 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002154 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002155 Op->Bitfield.LSB = LSB;
2156 Op->Bitfield.Width = Width;
2157 Op->StartLoc = S;
2158 Op->EndLoc = E;
2159 return Op;
2160 }
2161
Bill Wendling7729e062010-11-09 22:44:22 +00002162 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +00002163 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002164 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002165 KindTy Kind = k_RegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002166
Jim Grosbachd300b942011-09-13 22:56:44 +00002167 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002168 Kind = k_DPRRegisterList;
Jim Grosbachd300b942011-09-13 22:56:44 +00002169 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng275944a2011-07-25 21:32:49 +00002170 contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002171 Kind = k_SPRRegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002172
2173 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +00002174 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002175 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +00002176 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +00002177 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002178 Op->StartLoc = StartLoc;
2179 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +00002180 return Op;
2181 }
2182
Jim Grosbach862019c2011-10-18 23:02:30 +00002183 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002184 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbach862019c2011-10-18 23:02:30 +00002185 ARMOperand *Op = new ARMOperand(k_VectorList);
2186 Op->VectorList.RegNum = RegNum;
2187 Op->VectorList.Count = Count;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002188 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +00002189 Op->StartLoc = S;
2190 Op->EndLoc = E;
2191 return Op;
2192 }
2193
Jim Grosbach98b05a52011-11-30 01:09:44 +00002194 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002195 bool isDoubleSpaced,
Jim Grosbach98b05a52011-11-30 01:09:44 +00002196 SMLoc S, SMLoc E) {
2197 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2198 Op->VectorList.RegNum = RegNum;
2199 Op->VectorList.Count = Count;
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002200 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002201 Op->StartLoc = S;
2202 Op->EndLoc = E;
2203 return Op;
2204 }
2205
Jim Grosbach7636bf62011-12-02 00:35:16 +00002206 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002207 unsigned Index,
2208 bool isDoubleSpaced,
2209 SMLoc S, SMLoc E) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00002210 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2211 Op->VectorList.RegNum = RegNum;
2212 Op->VectorList.Count = Count;
2213 Op->VectorList.LaneIndex = Index;
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002214 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002215 Op->StartLoc = S;
2216 Op->EndLoc = E;
2217 return Op;
2218 }
2219
Jim Grosbach460a9052011-10-07 23:56:00 +00002220 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2221 MCContext &Ctx) {
2222 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2223 Op->VectorIndex.Val = Idx;
2224 Op->StartLoc = S;
2225 Op->EndLoc = E;
2226 return Op;
2227 }
2228
Chris Lattner3a697562010-10-28 17:20:03 +00002229 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002230 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan76264762010-04-02 22:27:05 +00002231 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +00002232 Op->StartLoc = S;
2233 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002234 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +00002235 }
2236
Jim Grosbach7ce05792011-08-03 23:50:40 +00002237 static ARMOperand *CreateMem(unsigned BaseRegNum,
2238 const MCConstantExpr *OffsetImm,
2239 unsigned OffsetRegNum,
2240 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach0d6fac32011-08-05 22:03:36 +00002241 unsigned ShiftImm,
Jim Grosbach57dcb852011-10-11 17:29:55 +00002242 unsigned Alignment,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002243 bool isNegative,
Chris Lattner3a697562010-10-28 17:20:03 +00002244 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002245 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbache53c87b2011-10-11 15:59:20 +00002246 Op->Memory.BaseRegNum = BaseRegNum;
2247 Op->Memory.OffsetImm = OffsetImm;
2248 Op->Memory.OffsetRegNum = OffsetRegNum;
2249 Op->Memory.ShiftType = ShiftType;
2250 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbach57dcb852011-10-11 17:29:55 +00002251 Op->Memory.Alignment = Alignment;
Jim Grosbache53c87b2011-10-11 15:59:20 +00002252 Op->Memory.isNegative = isNegative;
Jim Grosbach7ce05792011-08-03 23:50:40 +00002253 Op->StartLoc = S;
2254 Op->EndLoc = E;
2255 return Op;
2256 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002257
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002258 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2259 ARM_AM::ShiftOpc ShiftTy,
2260 unsigned ShiftImm,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002261 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002262 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbach7ce05792011-08-03 23:50:40 +00002263 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002264 Op->PostIdxReg.isAdd = isAdd;
2265 Op->PostIdxReg.ShiftTy = ShiftTy;
2266 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan76264762010-04-02 22:27:05 +00002267 Op->StartLoc = S;
2268 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002269 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002270 }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002271
2272 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002273 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002274 Op->MBOpt.Val = Opt;
2275 Op->StartLoc = S;
2276 Op->EndLoc = S;
2277 return Op;
2278 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002279
2280 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002281 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002282 Op->IFlags.Val = IFlags;
2283 Op->StartLoc = S;
2284 Op->EndLoc = S;
2285 return Op;
2286 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002287
2288 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002289 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002290 Op->MMask.Val = MMask;
2291 Op->StartLoc = S;
2292 Op->EndLoc = S;
2293 return Op;
2294 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002295};
2296
2297} // end anonymous namespace.
2298
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002299void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002300 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002301 case k_CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +00002302 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002303 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002304 case k_CCOut:
Jim Grosbachd67641b2010-12-06 18:21:12 +00002305 OS << "<ccout " << getReg() << ">";
2306 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002307 case k_ITCondMask: {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002308 static const char *MaskStr[] = {
2309 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2310 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2311 };
Jim Grosbach89df9962011-08-26 21:43:41 +00002312 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2313 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2314 break;
2315 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002316 case k_CoprocNum:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002317 OS << "<coprocessor number: " << getCoproc() << ">";
2318 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002319 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002320 OS << "<coprocessor register: " << getCoproc() << ">";
2321 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002322 case k_CoprocOption:
2323 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2324 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002325 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002326 OS << "<mask: " << getMSRMask() << ">";
2327 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002328 case k_Immediate:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002329 getImm()->print(OS);
2330 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002331 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002332 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2333 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002334 case k_Memory:
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002335 OS << "<memory "
Jim Grosbache53c87b2011-10-11 15:59:20 +00002336 << " base:" << Memory.BaseRegNum;
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002337 OS << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002338 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002339 case k_PostIndexRegister:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002340 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2341 << PostIdxReg.RegNum;
2342 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2343 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2344 << PostIdxReg.ShiftImm;
2345 OS << ">";
Jim Grosbach7ce05792011-08-03 23:50:40 +00002346 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002347 case k_ProcIFlags: {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002348 OS << "<ARM_PROC::";
2349 unsigned IFlags = getProcIFlags();
2350 for (int i=2; i >= 0; --i)
2351 if (IFlags & (1 << i))
2352 OS << ARM_PROC::IFlagsToString(1 << i);
2353 OS << ">";
2354 break;
2355 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002356 case k_Register:
Bill Wendling50d0f582010-11-18 23:43:05 +00002357 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002358 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002359 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +00002360 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2361 << " #" << ShifterImm.Imm << ">";
Jim Grosbache8606dc2011-07-13 17:50:29 +00002362 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002363 case k_ShiftedRegister:
Owen Anderson92a20222011-07-21 18:54:16 +00002364 OS << "<so_reg_reg "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002365 << RegShiftedReg.SrcReg << " "
2366 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2367 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson00828302011-03-18 22:50:18 +00002368 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002369 case k_ShiftedImmediate:
Owen Anderson92a20222011-07-21 18:54:16 +00002370 OS << "<so_reg_imm "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002371 << RegShiftedImm.SrcReg << " "
2372 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2373 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Anderson92a20222011-07-21 18:54:16 +00002374 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002375 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002376 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2377 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002378 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002379 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2380 << ", width: " << Bitfield.Width << ">";
2381 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002382 case k_RegisterList:
2383 case k_DPRRegisterList:
2384 case k_SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +00002385 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002386
Bill Wendling5fa22a12010-11-09 23:28:44 +00002387 const SmallVectorImpl<unsigned> &RegList = getRegList();
2388 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002389 I = RegList.begin(), E = RegList.end(); I != E; ) {
2390 OS << *I;
2391 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002392 }
2393
2394 OS << ">";
2395 break;
2396 }
Jim Grosbach862019c2011-10-18 23:02:30 +00002397 case k_VectorList:
2398 OS << "<vector_list " << VectorList.Count << " * "
2399 << VectorList.RegNum << ">";
2400 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002401 case k_VectorListAllLanes:
2402 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2403 << VectorList.RegNum << ">";
2404 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002405 case k_VectorListIndexed:
2406 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2407 << VectorList.Count << " * " << VectorList.RegNum << ">";
2408 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002409 case k_Token:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002410 OS << "'" << getToken() << "'";
2411 break;
Jim Grosbach460a9052011-10-07 23:56:00 +00002412 case k_VectorIndex:
2413 OS << "<vectorindex " << getVectorIndex() << ">";
2414 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002415 }
2416}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002417
2418/// @name Auto-generated Match Functions
2419/// {
2420
2421static unsigned MatchRegisterName(StringRef Name);
2422
2423/// }
2424
Bob Wilson69df7232011-02-03 21:46:10 +00002425bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2426 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbacha39cda72011-12-14 02:16:11 +00002427 StartLoc = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002428 RegNo = tryParseRegister();
Jim Grosbacha39cda72011-12-14 02:16:11 +00002429 EndLoc = Parser.getTok().getLoc();
Roman Divackybf755322011-01-27 17:14:22 +00002430
2431 return (RegNo == (unsigned)-1);
2432}
2433
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002434/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +00002435/// and if it is a register name the token is eaten and the register number is
2436/// returned. Otherwise return -1.
2437///
Jim Grosbach1355cf12011-07-26 17:10:22 +00002438int ARMAsmParser::tryParseRegister() {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002439 const AsmToken &Tok = Parser.getTok();
Jim Grosbach7ce05792011-08-03 23:50:40 +00002440 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002441
Benjamin Kramer59085362011-11-06 20:37:06 +00002442 std::string lowerCase = Tok.getString().lower();
Owen Anderson0c9f2502011-01-13 22:50:36 +00002443 unsigned RegNum = MatchRegisterName(lowerCase);
2444 if (!RegNum) {
2445 RegNum = StringSwitch<unsigned>(lowerCase)
2446 .Case("r13", ARM::SP)
2447 .Case("r14", ARM::LR)
2448 .Case("r15", ARM::PC)
2449 .Case("ip", ARM::R12)
Jim Grosbach40e28552011-12-08 19:27:38 +00002450 // Additional register name aliases for 'gas' compatibility.
2451 .Case("a1", ARM::R0)
2452 .Case("a2", ARM::R1)
2453 .Case("a3", ARM::R2)
2454 .Case("a4", ARM::R3)
2455 .Case("v1", ARM::R4)
2456 .Case("v2", ARM::R5)
2457 .Case("v3", ARM::R6)
2458 .Case("v4", ARM::R7)
2459 .Case("v5", ARM::R8)
2460 .Case("v6", ARM::R9)
2461 .Case("v7", ARM::R10)
2462 .Case("v8", ARM::R11)
2463 .Case("sb", ARM::R9)
2464 .Case("sl", ARM::R10)
2465 .Case("fp", ARM::R11)
Owen Anderson0c9f2502011-01-13 22:50:36 +00002466 .Default(0);
2467 }
Jim Grosbacha39cda72011-12-14 02:16:11 +00002468 if (!RegNum) {
Jim Grosbachaee718b2011-12-20 23:11:00 +00002469 // Check for aliases registered via .req. Canonicalize to lower case.
2470 // That's more consistent since register names are case insensitive, and
2471 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2472 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbacha39cda72011-12-14 02:16:11 +00002473 // If no match, return failure.
2474 if (Entry == RegisterReqs.end())
2475 return -1;
2476 Parser.Lex(); // Eat identifier token.
2477 return Entry->getValue();
2478 }
Bob Wilson69df7232011-02-03 21:46:10 +00002479
Chris Lattnere5658fa2010-10-30 04:09:10 +00002480 Parser.Lex(); // Eat identifier token.
Jim Grosbach460a9052011-10-07 23:56:00 +00002481
Chris Lattnere5658fa2010-10-30 04:09:10 +00002482 return RegNum;
2483}
Jim Grosbachd4462a52010-11-01 16:44:21 +00002484
Jim Grosbach19906722011-07-13 18:49:30 +00002485// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2486// If a recoverable error occurs, return 1. If an irrecoverable error
2487// occurs, return -1. An irrecoverable error is one where tokens have been
2488// consumed in the process of trying to parse the shifter (i.e., when it is
2489// indeed a shifter operand, but malformed).
Jim Grosbach0d87ec22011-07-26 20:41:24 +00002490int ARMAsmParser::tryParseShiftRegister(
Owen Anderson00828302011-03-18 22:50:18 +00002491 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2492 SMLoc S = Parser.getTok().getLoc();
2493 const AsmToken &Tok = Parser.getTok();
2494 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2495
Benjamin Kramer59085362011-11-06 20:37:06 +00002496 std::string lowerCase = Tok.getString().lower();
Owen Anderson00828302011-03-18 22:50:18 +00002497 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbachaf4edea2011-12-07 23:40:58 +00002498 .Case("asl", ARM_AM::lsl)
Owen Anderson00828302011-03-18 22:50:18 +00002499 .Case("lsl", ARM_AM::lsl)
2500 .Case("lsr", ARM_AM::lsr)
2501 .Case("asr", ARM_AM::asr)
2502 .Case("ror", ARM_AM::ror)
2503 .Case("rrx", ARM_AM::rrx)
2504 .Default(ARM_AM::no_shift);
2505
2506 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbach19906722011-07-13 18:49:30 +00002507 return 1;
Owen Anderson00828302011-03-18 22:50:18 +00002508
Jim Grosbache8606dc2011-07-13 17:50:29 +00002509 Parser.Lex(); // Eat the operator.
Owen Anderson00828302011-03-18 22:50:18 +00002510
Jim Grosbache8606dc2011-07-13 17:50:29 +00002511 // The source register for the shift has already been added to the
2512 // operand list, so we need to pop it off and combine it into the shifted
2513 // register operand instead.
Benjamin Kramereac07962011-07-14 18:41:22 +00002514 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbache8606dc2011-07-13 17:50:29 +00002515 if (!PrevOp->isReg())
2516 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2517 int SrcReg = PrevOp->getReg();
2518 int64_t Imm = 0;
2519 int ShiftReg = 0;
2520 if (ShiftTy == ARM_AM::rrx) {
2521 // RRX Doesn't have an explicit shift amount. The encoder expects
2522 // the shift register to be the same as the source register. Seems odd,
2523 // but OK.
2524 ShiftReg = SrcReg;
2525 } else {
2526 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00002527 if (Parser.getTok().is(AsmToken::Hash) ||
2528 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbache8606dc2011-07-13 17:50:29 +00002529 Parser.Lex(); // Eat hash.
2530 SMLoc ImmLoc = Parser.getTok().getLoc();
2531 const MCExpr *ShiftExpr = 0;
Jim Grosbach19906722011-07-13 18:49:30 +00002532 if (getParser().ParseExpression(ShiftExpr)) {
2533 Error(ImmLoc, "invalid immediate shift value");
2534 return -1;
2535 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002536 // The expression must be evaluatable as an immediate.
2537 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbach19906722011-07-13 18:49:30 +00002538 if (!CE) {
2539 Error(ImmLoc, "invalid immediate shift value");
2540 return -1;
2541 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002542 // Range check the immediate.
2543 // lsl, ror: 0 <= imm <= 31
2544 // lsr, asr: 0 <= imm <= 32
2545 Imm = CE->getValue();
2546 if (Imm < 0 ||
2547 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2548 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbach19906722011-07-13 18:49:30 +00002549 Error(ImmLoc, "immediate shift value out of range");
2550 return -1;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002551 }
Jim Grosbachde626ad2011-12-22 17:37:00 +00002552 // shift by zero is a nop. Always send it through as lsl.
2553 // ('as' compatibility)
2554 if (Imm == 0)
2555 ShiftTy = ARM_AM::lsl;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002556 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach1355cf12011-07-26 17:10:22 +00002557 ShiftReg = tryParseRegister();
Jim Grosbache8606dc2011-07-13 17:50:29 +00002558 SMLoc L = Parser.getTok().getLoc();
Jim Grosbach19906722011-07-13 18:49:30 +00002559 if (ShiftReg == -1) {
2560 Error (L, "expected immediate or register in shift operand");
2561 return -1;
2562 }
2563 } else {
2564 Error (Parser.getTok().getLoc(),
Jim Grosbache8606dc2011-07-13 17:50:29 +00002565 "expected immediate or register in shift operand");
Jim Grosbach19906722011-07-13 18:49:30 +00002566 return -1;
2567 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002568 }
2569
Owen Anderson92a20222011-07-21 18:54:16 +00002570 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2571 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002572 ShiftReg, Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002573 S, Parser.getTok().getLoc()));
Owen Anderson92a20222011-07-21 18:54:16 +00002574 else
2575 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2576 S, Parser.getTok().getLoc()));
Owen Anderson00828302011-03-18 22:50:18 +00002577
Jim Grosbach19906722011-07-13 18:49:30 +00002578 return 0;
Owen Anderson00828302011-03-18 22:50:18 +00002579}
2580
2581
Bill Wendling50d0f582010-11-18 23:43:05 +00002582/// Try to parse a register name. The token must be an Identifier when called.
2583/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2584/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +00002585///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002586/// TODO this is likely to change to allow different register types and or to
2587/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +00002588bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002589tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002590 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002591 int RegNo = tryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +00002592 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +00002593 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002594
Bill Wendling50d0f582010-11-18 23:43:05 +00002595 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002596
Chris Lattnere5658fa2010-10-30 04:09:10 +00002597 const AsmToken &ExclaimTok = Parser.getTok();
2598 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +00002599 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2600 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +00002601 Parser.Lex(); // Eat exclaim token
Jim Grosbach460a9052011-10-07 23:56:00 +00002602 return false;
2603 }
2604
2605 // Also check for an index operand. This is only legal for vector registers,
2606 // but that'll get caught OK in operand matching, so we don't need to
2607 // explicitly filter everything else out here.
2608 if (Parser.getTok().is(AsmToken::LBrac)) {
2609 SMLoc SIdx = Parser.getTok().getLoc();
2610 Parser.Lex(); // Eat left bracket token.
2611
2612 const MCExpr *ImmVal;
Jim Grosbach460a9052011-10-07 23:56:00 +00002613 if (getParser().ParseExpression(ImmVal))
Jim Grosbach24dda212012-01-31 23:51:09 +00002614 return true;
Jim Grosbach460a9052011-10-07 23:56:00 +00002615 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002616 if (!MCE)
2617 return TokError("immediate value expected for vector index");
Jim Grosbach460a9052011-10-07 23:56:00 +00002618
2619 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002620 if (Parser.getTok().isNot(AsmToken::RBrac))
2621 return Error(E, "']' expected");
Jim Grosbach460a9052011-10-07 23:56:00 +00002622
2623 Parser.Lex(); // Eat right bracket token.
2624
2625 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2626 SIdx, E,
2627 getContext()));
Kevin Enderby99e6d4e2009-10-07 18:01:35 +00002628 }
2629
Bill Wendling50d0f582010-11-18 23:43:05 +00002630 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002631}
2632
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002633/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2634/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2635/// "c5", ...
2636static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002637 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2638 // but efficient.
2639 switch (Name.size()) {
David Blaikie4d6ccb52012-01-20 21:51:11 +00002640 default: return -1;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002641 case 2:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002642 if (Name[0] != CoprocOp)
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002643 return -1;
2644 switch (Name[1]) {
2645 default: return -1;
2646 case '0': return 0;
2647 case '1': return 1;
2648 case '2': return 2;
2649 case '3': return 3;
2650 case '4': return 4;
2651 case '5': return 5;
2652 case '6': return 6;
2653 case '7': return 7;
2654 case '8': return 8;
2655 case '9': return 9;
2656 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002657 case 3:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002658 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002659 return -1;
2660 switch (Name[2]) {
2661 default: return -1;
2662 case '0': return 10;
2663 case '1': return 11;
2664 case '2': return 12;
2665 case '3': return 13;
2666 case '4': return 14;
2667 case '5': return 15;
2668 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002669 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002670}
2671
Jim Grosbach89df9962011-08-26 21:43:41 +00002672/// parseITCondCode - Try to parse a condition code for an IT instruction.
2673ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2674parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2675 SMLoc S = Parser.getTok().getLoc();
2676 const AsmToken &Tok = Parser.getTok();
2677 if (!Tok.is(AsmToken::Identifier))
2678 return MatchOperand_NoMatch;
Richard Barton04a09a42012-04-27 17:34:01 +00002679 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach89df9962011-08-26 21:43:41 +00002680 .Case("eq", ARMCC::EQ)
2681 .Case("ne", ARMCC::NE)
2682 .Case("hs", ARMCC::HS)
2683 .Case("cs", ARMCC::HS)
2684 .Case("lo", ARMCC::LO)
2685 .Case("cc", ARMCC::LO)
2686 .Case("mi", ARMCC::MI)
2687 .Case("pl", ARMCC::PL)
2688 .Case("vs", ARMCC::VS)
2689 .Case("vc", ARMCC::VC)
2690 .Case("hi", ARMCC::HI)
2691 .Case("ls", ARMCC::LS)
2692 .Case("ge", ARMCC::GE)
2693 .Case("lt", ARMCC::LT)
2694 .Case("gt", ARMCC::GT)
2695 .Case("le", ARMCC::LE)
2696 .Case("al", ARMCC::AL)
2697 .Default(~0U);
2698 if (CC == ~0U)
2699 return MatchOperand_NoMatch;
2700 Parser.Lex(); // Eat the token.
2701
2702 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2703
2704 return MatchOperand_Success;
2705}
2706
Jim Grosbach43904292011-07-25 20:14:50 +00002707/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002708/// token must be an Identifier when called, and if it is a coprocessor
2709/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002710ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002711parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002712 SMLoc S = Parser.getTok().getLoc();
2713 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002714 if (Tok.isNot(AsmToken::Identifier))
2715 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002716
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002717 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002718 if (Num == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002719 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002720
2721 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002722 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002723 return MatchOperand_Success;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002724}
2725
Jim Grosbach43904292011-07-25 20:14:50 +00002726/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002727/// token must be an Identifier when called, and if it is a coprocessor
2728/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002729ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002730parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002731 SMLoc S = Parser.getTok().getLoc();
2732 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002733 if (Tok.isNot(AsmToken::Identifier))
2734 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002735
2736 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2737 if (Reg == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002738 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002739
2740 Parser.Lex(); // Eat identifier token.
2741 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002742 return MatchOperand_Success;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002743}
2744
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002745/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2746/// coproc_option : '{' imm0_255 '}'
2747ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2748parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2749 SMLoc S = Parser.getTok().getLoc();
2750
2751 // If this isn't a '{', this isn't a coprocessor immediate operand.
2752 if (Parser.getTok().isNot(AsmToken::LCurly))
2753 return MatchOperand_NoMatch;
2754 Parser.Lex(); // Eat the '{'
2755
2756 const MCExpr *Expr;
2757 SMLoc Loc = Parser.getTok().getLoc();
2758 if (getParser().ParseExpression(Expr)) {
2759 Error(Loc, "illegal expression");
2760 return MatchOperand_ParseFail;
2761 }
2762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2763 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2764 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2765 return MatchOperand_ParseFail;
2766 }
2767 int Val = CE->getValue();
2768
2769 // Check for and consume the closing '}'
2770 if (Parser.getTok().isNot(AsmToken::RCurly))
2771 return MatchOperand_ParseFail;
2772 SMLoc E = Parser.getTok().getLoc();
2773 Parser.Lex(); // Eat the '}'
2774
2775 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2776 return MatchOperand_Success;
2777}
2778
Jim Grosbachd0588e22011-09-14 18:08:35 +00002779// For register list parsing, we need to map from raw GPR register numbering
2780// to the enumeration values. The enumeration values aren't sorted by
2781// register number due to our using "sp", "lr" and "pc" as canonical names.
2782static unsigned getNextRegister(unsigned Reg) {
2783 // If this is a GPR, we need to do it manually, otherwise we can rely
2784 // on the sort ordering of the enumeration since the other reg-classes
2785 // are sane.
2786 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2787 return Reg + 1;
2788 switch(Reg) {
Craig Topperbc219812012-02-07 02:50:20 +00002789 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbachd0588e22011-09-14 18:08:35 +00002790 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2791 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2792 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2793 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2794 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2795 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2796 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2797 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2798 }
2799}
2800
Jim Grosbachce485e72011-11-11 21:27:40 +00002801// Return the low-subreg of a given Q register.
2802static unsigned getDRegFromQReg(unsigned QReg) {
2803 switch (QReg) {
2804 default: llvm_unreachable("expected a Q register!");
2805 case ARM::Q0: return ARM::D0;
2806 case ARM::Q1: return ARM::D2;
2807 case ARM::Q2: return ARM::D4;
2808 case ARM::Q3: return ARM::D6;
2809 case ARM::Q4: return ARM::D8;
2810 case ARM::Q5: return ARM::D10;
2811 case ARM::Q6: return ARM::D12;
2812 case ARM::Q7: return ARM::D14;
2813 case ARM::Q8: return ARM::D16;
Jim Grosbach25e0a872011-11-15 21:01:30 +00002814 case ARM::Q9: return ARM::D18;
Jim Grosbachce485e72011-11-11 21:27:40 +00002815 case ARM::Q10: return ARM::D20;
2816 case ARM::Q11: return ARM::D22;
2817 case ARM::Q12: return ARM::D24;
2818 case ARM::Q13: return ARM::D26;
2819 case ARM::Q14: return ARM::D28;
2820 case ARM::Q15: return ARM::D30;
2821 }
2822}
2823
Jim Grosbachd0588e22011-09-14 18:08:35 +00002824/// Parse a register list.
Bill Wendling50d0f582010-11-18 23:43:05 +00002825bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002826parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +00002827 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00002828 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +00002829 SMLoc S = Parser.getTok().getLoc();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002830 Parser.Lex(); // Eat '{' token.
2831 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002832
Jim Grosbachd0588e22011-09-14 18:08:35 +00002833 // Check the first register in the list to see what register class
2834 // this is a list of.
2835 int Reg = tryParseRegister();
2836 if (Reg == -1)
2837 return Error(RegLoc, "register expected");
2838
Jim Grosbachce485e72011-11-11 21:27:40 +00002839 // The reglist instructions have at most 16 registers, so reserve
2840 // space for that many.
2841 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2842
2843 // Allow Q regs and just interpret them as the two D sub-registers.
2844 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2845 Reg = getDRegFromQReg(Reg);
2846 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2847 ++Reg;
2848 }
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002849 const MCRegisterClass *RC;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002850 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2851 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2852 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2853 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2854 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2855 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2856 else
2857 return Error(RegLoc, "invalid register in register list");
2858
Jim Grosbachce485e72011-11-11 21:27:40 +00002859 // Store the register.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002860 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002861
Jim Grosbachd0588e22011-09-14 18:08:35 +00002862 // This starts immediately after the first register token in the list,
2863 // so we can see either a comma or a minus (range separator) as a legal
2864 // next token.
2865 while (Parser.getTok().is(AsmToken::Comma) ||
2866 Parser.getTok().is(AsmToken::Minus)) {
2867 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache43862b2011-11-15 23:19:15 +00002868 Parser.Lex(); // Eat the minus.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002869 SMLoc EndLoc = Parser.getTok().getLoc();
2870 int EndReg = tryParseRegister();
2871 if (EndReg == -1)
2872 return Error(EndLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002873 // Allow Q regs and just interpret them as the two D sub-registers.
2874 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2875 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002876 // If the register is the same as the start reg, there's nothing
2877 // more to do.
2878 if (Reg == EndReg)
2879 continue;
2880 // The register must be in the same register class as the first.
2881 if (!RC->contains(EndReg))
2882 return Error(EndLoc, "invalid register in register list");
2883 // Ranges must go from low to high.
2884 if (getARMRegisterNumbering(Reg) > getARMRegisterNumbering(EndReg))
2885 return Error(EndLoc, "bad range in register list");
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002886
Jim Grosbachd0588e22011-09-14 18:08:35 +00002887 // Add all the registers in the range to the register list.
2888 while (Reg != EndReg) {
2889 Reg = getNextRegister(Reg);
2890 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2891 }
2892 continue;
2893 }
2894 Parser.Lex(); // Eat the comma.
2895 RegLoc = Parser.getTok().getLoc();
2896 int OldReg = Reg;
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002897 const AsmToken RegTok = Parser.getTok();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002898 Reg = tryParseRegister();
2899 if (Reg == -1)
Jim Grosbach2d539692011-09-12 23:36:42 +00002900 return Error(RegLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002901 // Allow Q regs and just interpret them as the two D sub-registers.
2902 bool isQReg = false;
2903 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2904 Reg = getDRegFromQReg(Reg);
2905 isQReg = true;
2906 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002907 // The register must be in the same register class as the first.
2908 if (!RC->contains(Reg))
2909 return Error(RegLoc, "invalid register in register list");
2910 // List must be monotonically increasing.
Jim Grosbachbe7cf2b2012-03-16 20:48:38 +00002911 if (getARMRegisterNumbering(Reg) < getARMRegisterNumbering(OldReg)) {
2912 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2913 Warning(RegLoc, "register list not in ascending order");
2914 else
2915 return Error(RegLoc, "register list not in ascending order");
2916 }
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002917 if (getARMRegisterNumbering(Reg) == getARMRegisterNumbering(OldReg)) {
2918 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2919 ") in register list");
2920 continue;
2921 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002922 // VFP register lists must also be contiguous.
2923 // It's OK to use the enumeration values directly here rather, as the
2924 // VFP register classes have the enum sorted properly.
2925 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2926 Reg != OldReg + 1)
2927 return Error(RegLoc, "non-contiguous register range");
2928 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbachce485e72011-11-11 21:27:40 +00002929 if (isQReg)
2930 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge7176102010-11-06 22:36:58 +00002931 }
2932
Jim Grosbachd0588e22011-09-14 18:08:35 +00002933 SMLoc E = Parser.getTok().getLoc();
2934 if (Parser.getTok().isNot(AsmToken::RCurly))
2935 return Error(E, "'}' expected");
2936 Parser.Lex(); // Eat '}' token.
2937
Jim Grosbach27debd62011-12-13 21:48:29 +00002938 // Push the register list operand.
Bill Wendling50d0f582010-11-18 23:43:05 +00002939 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach27debd62011-12-13 21:48:29 +00002940
2941 // The ARM system instruction variants for LDM/STM have a '^' token here.
2942 if (Parser.getTok().is(AsmToken::Caret)) {
2943 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2944 Parser.Lex(); // Eat '^' token.
2945 }
2946
Bill Wendling50d0f582010-11-18 23:43:05 +00002947 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002948}
2949
Jim Grosbach98b05a52011-11-30 01:09:44 +00002950// Helper function to parse the lane index for vector lists.
2951ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach7636bf62011-12-02 00:35:16 +00002952parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2953 Index = 0; // Always return a defined index value.
Jim Grosbach98b05a52011-11-30 01:09:44 +00002954 if (Parser.getTok().is(AsmToken::LBrac)) {
2955 Parser.Lex(); // Eat the '['.
2956 if (Parser.getTok().is(AsmToken::RBrac)) {
2957 // "Dn[]" is the 'all lanes' syntax.
2958 LaneKind = AllLanes;
2959 Parser.Lex(); // Eat the ']'.
2960 return MatchOperand_Success;
2961 }
Jim Grosbachceee9842012-03-19 20:39:53 +00002962
2963 // There's an optional '#' token here. Normally there wouldn't be, but
2964 // inline assemble puts one in, and it's friendly to accept that.
2965 if (Parser.getTok().is(AsmToken::Hash))
2966 Parser.Lex(); // Eat the '#'
2967
Jim Grosbachc9313252011-12-21 01:19:23 +00002968 const MCExpr *LaneIndex;
2969 SMLoc Loc = Parser.getTok().getLoc();
2970 if (getParser().ParseExpression(LaneIndex)) {
2971 Error(Loc, "illegal expression");
2972 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002973 }
Jim Grosbachc9313252011-12-21 01:19:23 +00002974 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2975 if (!CE) {
2976 Error(Loc, "lane index must be empty or an integer");
2977 return MatchOperand_ParseFail;
2978 }
2979 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2980 Error(Parser.getTok().getLoc(), "']' expected");
2981 return MatchOperand_ParseFail;
2982 }
2983 Parser.Lex(); // Eat the ']'.
2984 int64_t Val = CE->getValue();
2985
2986 // FIXME: Make this range check context sensitive for .8, .16, .32.
2987 if (Val < 0 || Val > 7) {
2988 Error(Parser.getTok().getLoc(), "lane index out of range");
2989 return MatchOperand_ParseFail;
2990 }
2991 Index = Val;
2992 LaneKind = IndexedLane;
2993 return MatchOperand_Success;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002994 }
2995 LaneKind = NoLanes;
2996 return MatchOperand_Success;
2997}
2998
Jim Grosbach862019c2011-10-18 23:02:30 +00002999// parse a vector register list
3000ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3001parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003002 VectorLaneTy LaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003003 unsigned LaneIndex;
Jim Grosbach5c984e42011-11-15 21:45:55 +00003004 SMLoc S = Parser.getTok().getLoc();
3005 // As an extension (to match gas), support a plain D register or Q register
3006 // (without encosing curly braces) as a single or double entry list,
3007 // respectively.
3008 if (Parser.getTok().is(AsmToken::Identifier)) {
3009 int Reg = tryParseRegister();
3010 if (Reg == -1)
3011 return MatchOperand_NoMatch;
3012 SMLoc E = Parser.getTok().getLoc();
3013 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00003014 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00003015 if (Res != MatchOperand_Success)
3016 return Res;
3017 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003018 case NoLanes:
3019 E = Parser.getTok().getLoc();
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003020 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003021 break;
3022 case AllLanes:
3023 E = Parser.getTok().getLoc();
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003024 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3025 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003026 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003027 case IndexedLane:
3028 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003029 LaneIndex,
3030 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003031 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003032 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003033 return MatchOperand_Success;
3034 }
3035 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3036 Reg = getDRegFromQReg(Reg);
Jim Grosbach7636bf62011-12-02 00:35:16 +00003037 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00003038 if (Res != MatchOperand_Success)
3039 return Res;
3040 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003041 case NoLanes:
3042 E = Parser.getTok().getLoc();
Jim Grosbach28f08c92012-03-05 19:33:30 +00003043 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003044 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003045 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003046 break;
3047 case AllLanes:
3048 E = Parser.getTok().getLoc();
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003049 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3050 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003051 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3052 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003053 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003054 case IndexedLane:
3055 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003056 LaneIndex,
3057 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003058 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003059 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003060 return MatchOperand_Success;
3061 }
3062 Error(S, "vector register expected");
3063 return MatchOperand_ParseFail;
3064 }
3065
3066 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbach862019c2011-10-18 23:02:30 +00003067 return MatchOperand_NoMatch;
3068
Jim Grosbach862019c2011-10-18 23:02:30 +00003069 Parser.Lex(); // Eat '{' token.
3070 SMLoc RegLoc = Parser.getTok().getLoc();
3071
3072 int Reg = tryParseRegister();
3073 if (Reg == -1) {
3074 Error(RegLoc, "register expected");
3075 return MatchOperand_ParseFail;
3076 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003077 unsigned Count = 1;
Jim Grosbach276ed032011-12-15 21:54:55 +00003078 int Spacing = 0;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003079 unsigned FirstReg = Reg;
3080 // The list is of D registers, but we also allow Q regs and just interpret
3081 // them as the two D sub-registers.
3082 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3083 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003084 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3085 // it's ambiguous with four-register single spaced.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003086 ++Reg;
3087 ++Count;
3088 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00003089 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003090 return MatchOperand_ParseFail;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003091
Jim Grosbache43862b2011-11-15 23:19:15 +00003092 while (Parser.getTok().is(AsmToken::Comma) ||
3093 Parser.getTok().is(AsmToken::Minus)) {
3094 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003095 if (!Spacing)
3096 Spacing = 1; // Register range implies a single spaced list.
3097 else if (Spacing == 2) {
3098 Error(Parser.getTok().getLoc(),
3099 "sequential registers in double spaced list");
3100 return MatchOperand_ParseFail;
3101 }
Jim Grosbache43862b2011-11-15 23:19:15 +00003102 Parser.Lex(); // Eat the minus.
3103 SMLoc EndLoc = Parser.getTok().getLoc();
3104 int EndReg = tryParseRegister();
3105 if (EndReg == -1) {
3106 Error(EndLoc, "register expected");
3107 return MatchOperand_ParseFail;
3108 }
3109 // Allow Q regs and just interpret them as the two D sub-registers.
3110 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3111 EndReg = getDRegFromQReg(EndReg) + 1;
3112 // If the register is the same as the start reg, there's nothing
3113 // more to do.
3114 if (Reg == EndReg)
3115 continue;
3116 // The register must be in the same register class as the first.
3117 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3118 Error(EndLoc, "invalid register in register list");
3119 return MatchOperand_ParseFail;
3120 }
3121 // Ranges must go from low to high.
3122 if (Reg > EndReg) {
3123 Error(EndLoc, "bad range in register list");
3124 return MatchOperand_ParseFail;
3125 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003126 // Parse the lane specifier if present.
3127 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003128 unsigned NextLaneIndex;
3129 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003130 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003131 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003132 Error(EndLoc, "mismatched lane index in register list");
3133 return MatchOperand_ParseFail;
3134 }
3135 EndLoc = Parser.getTok().getLoc();
Jim Grosbache43862b2011-11-15 23:19:15 +00003136
3137 // Add all the registers in the range to the register list.
3138 Count += EndReg - Reg;
3139 Reg = EndReg;
3140 continue;
3141 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003142 Parser.Lex(); // Eat the comma.
3143 RegLoc = Parser.getTok().getLoc();
3144 int OldReg = Reg;
3145 Reg = tryParseRegister();
3146 if (Reg == -1) {
3147 Error(RegLoc, "register expected");
3148 return MatchOperand_ParseFail;
3149 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003150 // vector register lists must be contiguous.
Jim Grosbach862019c2011-10-18 23:02:30 +00003151 // It's OK to use the enumeration values directly here rather, as the
3152 // VFP register classes have the enum sorted properly.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003153 //
3154 // The list is of D registers, but we also allow Q regs and just interpret
3155 // them as the two D sub-registers.
3156 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003157 if (!Spacing)
3158 Spacing = 1; // Register range implies a single spaced list.
3159 else if (Spacing == 2) {
3160 Error(RegLoc,
3161 "invalid register in double-spaced list (must be 'D' register')");
3162 return MatchOperand_ParseFail;
3163 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003164 Reg = getDRegFromQReg(Reg);
3165 if (Reg != OldReg + 1) {
3166 Error(RegLoc, "non-contiguous register range");
3167 return MatchOperand_ParseFail;
3168 }
3169 ++Reg;
3170 Count += 2;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003171 // Parse the lane specifier if present.
3172 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003173 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003174 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003175 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003176 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003177 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003178 Error(EndLoc, "mismatched lane index in register list");
3179 return MatchOperand_ParseFail;
3180 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003181 continue;
3182 }
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003183 // Normal D register.
3184 // Figure out the register spacing (single or double) of the list if
3185 // we don't know it already.
3186 if (!Spacing)
3187 Spacing = 1 + (Reg == OldReg + 2);
3188
3189 // Just check that it's contiguous and keep going.
3190 if (Reg != OldReg + Spacing) {
Jim Grosbach862019c2011-10-18 23:02:30 +00003191 Error(RegLoc, "non-contiguous register range");
3192 return MatchOperand_ParseFail;
3193 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003194 ++Count;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003195 // Parse the lane specifier if present.
3196 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003197 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003198 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003199 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003200 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003201 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003202 Error(EndLoc, "mismatched lane index in register list");
3203 return MatchOperand_ParseFail;
3204 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003205 }
3206
3207 SMLoc E = Parser.getTok().getLoc();
3208 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3209 Error(E, "'}' expected");
3210 return MatchOperand_ParseFail;
3211 }
3212 Parser.Lex(); // Eat '}' token.
3213
Jim Grosbach98b05a52011-11-30 01:09:44 +00003214 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003215 case NoLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003216 // Two-register operands have been converted to the
Jim Grosbachc3384c92012-03-05 21:43:40 +00003217 // composite register classes.
3218 if (Count == 2) {
3219 const MCRegisterClass *RC = (Spacing == 1) ?
3220 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3221 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3222 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3223 }
Jim Grosbach28f08c92012-03-05 19:33:30 +00003224
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003225 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3226 (Spacing == 2), S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003227 break;
3228 case AllLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003229 // Two-register operands have been converted to the
3230 // composite register classes.
Jim Grosbach4d0983a2012-03-06 23:10:38 +00003231 if (Count == 2) {
3232 const MCRegisterClass *RC = (Spacing == 1) ?
3233 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3234 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003235 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3236 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003237 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003238 (Spacing == 2),
Jim Grosbach98b05a52011-11-30 01:09:44 +00003239 S, E));
3240 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003241 case IndexedLane:
3242 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003243 LaneIndex,
3244 (Spacing == 2),
3245 S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003246 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003247 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003248 return MatchOperand_Success;
3249}
3250
Jim Grosbach43904292011-07-25 20:14:50 +00003251/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbachf922c472011-02-12 01:34:40 +00003252ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003253parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003254 SMLoc S = Parser.getTok().getLoc();
3255 const AsmToken &Tok = Parser.getTok();
3256 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3257 StringRef OptStr = Tok.getString();
3258
3259 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()))
3260 .Case("sy", ARM_MB::SY)
3261 .Case("st", ARM_MB::ST)
Jim Grosbach032434d2011-07-13 23:40:38 +00003262 .Case("sh", ARM_MB::ISH)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003263 .Case("ish", ARM_MB::ISH)
Jim Grosbach032434d2011-07-13 23:40:38 +00003264 .Case("shst", ARM_MB::ISHST)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003265 .Case("ishst", ARM_MB::ISHST)
3266 .Case("nsh", ARM_MB::NSH)
Jim Grosbach032434d2011-07-13 23:40:38 +00003267 .Case("un", ARM_MB::NSH)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003268 .Case("nshst", ARM_MB::NSHST)
Jim Grosbach032434d2011-07-13 23:40:38 +00003269 .Case("unst", ARM_MB::NSHST)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003270 .Case("osh", ARM_MB::OSH)
3271 .Case("oshst", ARM_MB::OSHST)
3272 .Default(~0U);
3273
3274 if (Opt == ~0U)
Jim Grosbachf922c472011-02-12 01:34:40 +00003275 return MatchOperand_NoMatch;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003276
3277 Parser.Lex(); // Eat identifier token.
3278 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00003279 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003280}
3281
Jim Grosbach43904292011-07-25 20:14:50 +00003282/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003283ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003284parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003285 SMLoc S = Parser.getTok().getLoc();
3286 const AsmToken &Tok = Parser.getTok();
3287 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3288 StringRef IFlagsStr = Tok.getString();
3289
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003290 // An iflags string of "none" is interpreted to mean that none of the AIF
3291 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003292 unsigned IFlags = 0;
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003293 if (IFlagsStr != "none") {
3294 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3295 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3296 .Case("a", ARM_PROC::A)
3297 .Case("i", ARM_PROC::I)
3298 .Case("f", ARM_PROC::F)
3299 .Default(~0U);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003300
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003301 // If some specific iflag is already set, it means that some letter is
3302 // present more than once, this is not acceptable.
3303 if (Flag == ~0U || (IFlags & Flag))
3304 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003305
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003306 IFlags |= Flag;
3307 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003308 }
3309
3310 Parser.Lex(); // Eat identifier token.
3311 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3312 return MatchOperand_Success;
3313}
3314
Jim Grosbach43904292011-07-25 20:14:50 +00003315/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003316ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003317parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003318 SMLoc S = Parser.getTok().getLoc();
3319 const AsmToken &Tok = Parser.getTok();
3320 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3321 StringRef Mask = Tok.getString();
3322
James Molloyacad68d2011-09-28 14:21:38 +00003323 if (isMClass()) {
3324 // See ARMv6-M 10.1.1
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00003325 std::string Name = Mask.lower();
3326 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderby0fd4f3c2012-05-17 22:18:01 +00003327 // Note: in the documentation:
3328 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3329 // for MSR APSR_nzcvq.
3330 // but we do make it an alias here. This is so to get the "mask encoding"
3331 // bits correct on MSR APSR writes.
3332 //
3333 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3334 // should really only be allowed when writing a special register. Note
3335 // they get dropped in the MRS instruction reading a special register as
3336 // the SYSm field is only 8 bits.
3337 //
3338 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3339 // includes the DSP extension but that is not checked.
3340 .Case("apsr", 0x800)
3341 .Case("apsr_nzcvq", 0x800)
3342 .Case("apsr_g", 0x400)
3343 .Case("apsr_nzcvqg", 0xc00)
3344 .Case("iapsr", 0x801)
3345 .Case("iapsr_nzcvq", 0x801)
3346 .Case("iapsr_g", 0x401)
3347 .Case("iapsr_nzcvqg", 0xc01)
3348 .Case("eapsr", 0x802)
3349 .Case("eapsr_nzcvq", 0x802)
3350 .Case("eapsr_g", 0x402)
3351 .Case("eapsr_nzcvqg", 0xc02)
3352 .Case("xpsr", 0x803)
3353 .Case("xpsr_nzcvq", 0x803)
3354 .Case("xpsr_g", 0x403)
3355 .Case("xpsr_nzcvqg", 0xc03)
James Molloyacad68d2011-09-28 14:21:38 +00003356 .Case("ipsr", 5)
3357 .Case("epsr", 6)
3358 .Case("iepsr", 7)
3359 .Case("msp", 8)
3360 .Case("psp", 9)
3361 .Case("primask", 16)
3362 .Case("basepri", 17)
3363 .Case("basepri_max", 18)
3364 .Case("faultmask", 19)
3365 .Case("control", 20)
3366 .Default(~0U);
Jim Grosbach18c8d122011-12-22 17:17:10 +00003367
James Molloyacad68d2011-09-28 14:21:38 +00003368 if (FlagsVal == ~0U)
3369 return MatchOperand_NoMatch;
3370
3371 if (!hasV7Ops() && FlagsVal >= 17 && FlagsVal <= 19)
3372 // basepri, basepri_max and faultmask only valid for V7m.
3373 return MatchOperand_NoMatch;
Jim Grosbach18c8d122011-12-22 17:17:10 +00003374
James Molloyacad68d2011-09-28 14:21:38 +00003375 Parser.Lex(); // Eat identifier token.
3376 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3377 return MatchOperand_Success;
3378 }
3379
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003380 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3381 size_t Start = 0, Next = Mask.find('_');
3382 StringRef Flags = "";
Benjamin Kramer59085362011-11-06 20:37:06 +00003383 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003384 if (Next != StringRef::npos)
3385 Flags = Mask.slice(Next+1, Mask.size());
3386
3387 // FlagsVal contains the complete mask:
3388 // 3-0: Mask
3389 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3390 unsigned FlagsVal = 0;
3391
3392 if (SpecReg == "apsr") {
3393 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +00003394 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003395 .Case("g", 0x4) // same as CPSR_s
3396 .Case("nzcvqg", 0xc) // same as CPSR_fs
3397 .Default(~0U);
3398
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003399 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003400 if (!Flags.empty())
3401 return MatchOperand_NoMatch;
3402 else
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003403 FlagsVal = 8; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003404 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003405 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbachb657a902012-04-05 03:17:53 +00003406 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3407 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00003408 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003409 for (int i = 0, e = Flags.size(); i != e; ++i) {
3410 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3411 .Case("c", 1)
3412 .Case("x", 2)
3413 .Case("s", 4)
3414 .Case("f", 8)
3415 .Default(~0U);
3416
3417 // If some specific flag is already set, it means that some letter is
3418 // present more than once, this is not acceptable.
3419 if (FlagsVal == ~0U || (FlagsVal & Flag))
3420 return MatchOperand_NoMatch;
3421 FlagsVal |= Flag;
3422 }
3423 } else // No match for special register.
3424 return MatchOperand_NoMatch;
3425
Owen Anderson7784f1d2011-10-21 18:43:28 +00003426 // Special register without flags is NOT equivalent to "fc" flags.
3427 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3428 // two lines would enable gas compatibility at the expense of breaking
3429 // round-tripping.
3430 //
3431 // if (!FlagsVal)
3432 // FlagsVal = 0x9;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003433
3434 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3435 if (SpecReg == "spsr")
3436 FlagsVal |= 16;
3437
3438 Parser.Lex(); // Eat identifier token.
3439 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3440 return MatchOperand_Success;
3441}
3442
Jim Grosbachf6c05252011-07-21 17:23:04 +00003443ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3444parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3445 int Low, int High) {
3446 const AsmToken &Tok = Parser.getTok();
3447 if (Tok.isNot(AsmToken::Identifier)) {
3448 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3449 return MatchOperand_ParseFail;
3450 }
3451 StringRef ShiftName = Tok.getString();
Benjamin Kramer59085362011-11-06 20:37:06 +00003452 std::string LowerOp = Op.lower();
3453 std::string UpperOp = Op.upper();
Jim Grosbachf6c05252011-07-21 17:23:04 +00003454 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3455 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3456 return MatchOperand_ParseFail;
3457 }
3458 Parser.Lex(); // Eat shift type token.
3459
3460 // There must be a '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003461 if (Parser.getTok().isNot(AsmToken::Hash) &&
3462 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbachf6c05252011-07-21 17:23:04 +00003463 Error(Parser.getTok().getLoc(), "'#' expected");
3464 return MatchOperand_ParseFail;
3465 }
3466 Parser.Lex(); // Eat hash token.
3467
3468 const MCExpr *ShiftAmount;
3469 SMLoc Loc = Parser.getTok().getLoc();
3470 if (getParser().ParseExpression(ShiftAmount)) {
3471 Error(Loc, "illegal expression");
3472 return MatchOperand_ParseFail;
3473 }
3474 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3475 if (!CE) {
3476 Error(Loc, "constant expression expected");
3477 return MatchOperand_ParseFail;
3478 }
3479 int Val = CE->getValue();
3480 if (Val < Low || Val > High) {
3481 Error(Loc, "immediate value out of range");
3482 return MatchOperand_ParseFail;
3483 }
3484
3485 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3486
3487 return MatchOperand_Success;
3488}
3489
Jim Grosbachc27d4f92011-07-22 17:44:50 +00003490ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3491parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3492 const AsmToken &Tok = Parser.getTok();
3493 SMLoc S = Tok.getLoc();
3494 if (Tok.isNot(AsmToken::Identifier)) {
3495 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3496 return MatchOperand_ParseFail;
3497 }
3498 int Val = StringSwitch<int>(Tok.getString())
3499 .Case("be", 1)
3500 .Case("le", 0)
3501 .Default(-1);
3502 Parser.Lex(); // Eat the token.
3503
3504 if (Val == -1) {
3505 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3506 return MatchOperand_ParseFail;
3507 }
3508 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3509 getContext()),
3510 S, Parser.getTok().getLoc()));
3511 return MatchOperand_Success;
3512}
3513
Jim Grosbach580f4a92011-07-25 22:20:28 +00003514/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3515/// instructions. Legal values are:
3516/// lsl #n 'n' in [0,31]
3517/// asr #n 'n' in [1,32]
3518/// n == 32 encoded as n == 0.
3519ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3520parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3521 const AsmToken &Tok = Parser.getTok();
3522 SMLoc S = Tok.getLoc();
3523 if (Tok.isNot(AsmToken::Identifier)) {
3524 Error(S, "shift operator 'asr' or 'lsl' expected");
3525 return MatchOperand_ParseFail;
3526 }
3527 StringRef ShiftName = Tok.getString();
3528 bool isASR;
3529 if (ShiftName == "lsl" || ShiftName == "LSL")
3530 isASR = false;
3531 else if (ShiftName == "asr" || ShiftName == "ASR")
3532 isASR = true;
3533 else {
3534 Error(S, "shift operator 'asr' or 'lsl' expected");
3535 return MatchOperand_ParseFail;
3536 }
3537 Parser.Lex(); // Eat the operator.
3538
3539 // A '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003540 if (Parser.getTok().isNot(AsmToken::Hash) &&
3541 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach580f4a92011-07-25 22:20:28 +00003542 Error(Parser.getTok().getLoc(), "'#' expected");
3543 return MatchOperand_ParseFail;
3544 }
3545 Parser.Lex(); // Eat hash token.
3546
3547 const MCExpr *ShiftAmount;
3548 SMLoc E = Parser.getTok().getLoc();
3549 if (getParser().ParseExpression(ShiftAmount)) {
3550 Error(E, "malformed shift expression");
3551 return MatchOperand_ParseFail;
3552 }
3553 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3554 if (!CE) {
3555 Error(E, "shift amount must be an immediate");
3556 return MatchOperand_ParseFail;
3557 }
3558
3559 int64_t Val = CE->getValue();
3560 if (isASR) {
3561 // Shift amount must be in [1,32]
3562 if (Val < 1 || Val > 32) {
3563 Error(E, "'asr' shift amount must be in range [1,32]");
3564 return MatchOperand_ParseFail;
3565 }
Owen Anderson0afa0092011-09-26 21:06:22 +00003566 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3567 if (isThumb() && Val == 32) {
3568 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3569 return MatchOperand_ParseFail;
3570 }
Jim Grosbach580f4a92011-07-25 22:20:28 +00003571 if (Val == 32) Val = 0;
3572 } else {
3573 // Shift amount must be in [1,32]
3574 if (Val < 0 || Val > 31) {
3575 Error(E, "'lsr' shift amount must be in range [0,31]");
3576 return MatchOperand_ParseFail;
3577 }
3578 }
3579
3580 E = Parser.getTok().getLoc();
3581 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3582
3583 return MatchOperand_Success;
3584}
3585
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003586/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3587/// of instructions. Legal values are:
3588/// ror #n 'n' in {0, 8, 16, 24}
3589ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3590parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3591 const AsmToken &Tok = Parser.getTok();
3592 SMLoc S = Tok.getLoc();
Jim Grosbach326efe52011-09-19 20:29:33 +00003593 if (Tok.isNot(AsmToken::Identifier))
3594 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003595 StringRef ShiftName = Tok.getString();
Jim Grosbach326efe52011-09-19 20:29:33 +00003596 if (ShiftName != "ror" && ShiftName != "ROR")
3597 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003598 Parser.Lex(); // Eat the operator.
3599
3600 // A '#' and a rotate amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003601 if (Parser.getTok().isNot(AsmToken::Hash) &&
3602 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003603 Error(Parser.getTok().getLoc(), "'#' expected");
3604 return MatchOperand_ParseFail;
3605 }
3606 Parser.Lex(); // Eat hash token.
3607
3608 const MCExpr *ShiftAmount;
3609 SMLoc E = Parser.getTok().getLoc();
3610 if (getParser().ParseExpression(ShiftAmount)) {
3611 Error(E, "malformed rotate expression");
3612 return MatchOperand_ParseFail;
3613 }
3614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3615 if (!CE) {
3616 Error(E, "rotate amount must be an immediate");
3617 return MatchOperand_ParseFail;
3618 }
3619
3620 int64_t Val = CE->getValue();
3621 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3622 // normally, zero is represented in asm by omitting the rotate operand
3623 // entirely.
3624 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3625 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3626 return MatchOperand_ParseFail;
3627 }
3628
3629 E = Parser.getTok().getLoc();
3630 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3631
3632 return MatchOperand_Success;
3633}
3634
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003635ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3636parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3637 SMLoc S = Parser.getTok().getLoc();
3638 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003639 if (Parser.getTok().isNot(AsmToken::Hash) &&
3640 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003641 Error(Parser.getTok().getLoc(), "'#' expected");
3642 return MatchOperand_ParseFail;
3643 }
3644 Parser.Lex(); // Eat hash token.
3645
3646 const MCExpr *LSBExpr;
3647 SMLoc E = Parser.getTok().getLoc();
3648 if (getParser().ParseExpression(LSBExpr)) {
3649 Error(E, "malformed immediate expression");
3650 return MatchOperand_ParseFail;
3651 }
3652 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3653 if (!CE) {
3654 Error(E, "'lsb' operand must be an immediate");
3655 return MatchOperand_ParseFail;
3656 }
3657
3658 int64_t LSB = CE->getValue();
3659 // The LSB must be in the range [0,31]
3660 if (LSB < 0 || LSB > 31) {
3661 Error(E, "'lsb' operand must be in the range [0,31]");
3662 return MatchOperand_ParseFail;
3663 }
3664 E = Parser.getTok().getLoc();
3665
3666 // Expect another immediate operand.
3667 if (Parser.getTok().isNot(AsmToken::Comma)) {
3668 Error(Parser.getTok().getLoc(), "too few operands");
3669 return MatchOperand_ParseFail;
3670 }
3671 Parser.Lex(); // Eat hash token.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003672 if (Parser.getTok().isNot(AsmToken::Hash) &&
3673 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003674 Error(Parser.getTok().getLoc(), "'#' expected");
3675 return MatchOperand_ParseFail;
3676 }
3677 Parser.Lex(); // Eat hash token.
3678
3679 const MCExpr *WidthExpr;
3680 if (getParser().ParseExpression(WidthExpr)) {
3681 Error(E, "malformed immediate expression");
3682 return MatchOperand_ParseFail;
3683 }
3684 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3685 if (!CE) {
3686 Error(E, "'width' operand must be an immediate");
3687 return MatchOperand_ParseFail;
3688 }
3689
3690 int64_t Width = CE->getValue();
3691 // The LSB must be in the range [1,32-lsb]
3692 if (Width < 1 || Width > 32 - LSB) {
3693 Error(E, "'width' operand must be in the range [1,32-lsb]");
3694 return MatchOperand_ParseFail;
3695 }
3696 E = Parser.getTok().getLoc();
3697
3698 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3699
3700 return MatchOperand_Success;
3701}
3702
Jim Grosbach7ce05792011-08-03 23:50:40 +00003703ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3704parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3705 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003706 // postidx_reg := '+' register {, shift}
3707 // | '-' register {, shift}
3708 // | register {, shift}
Jim Grosbach7ce05792011-08-03 23:50:40 +00003709
3710 // This method must return MatchOperand_NoMatch without consuming any tokens
3711 // in the case where there is no match, as other alternatives take other
3712 // parse methods.
3713 AsmToken Tok = Parser.getTok();
3714 SMLoc S = Tok.getLoc();
3715 bool haveEaten = false;
Jim Grosbach16578b52011-08-05 16:11:38 +00003716 bool isAdd = true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003717 int Reg = -1;
3718 if (Tok.is(AsmToken::Plus)) {
3719 Parser.Lex(); // Eat the '+' token.
3720 haveEaten = true;
3721 } else if (Tok.is(AsmToken::Minus)) {
3722 Parser.Lex(); // Eat the '-' token.
Jim Grosbach16578b52011-08-05 16:11:38 +00003723 isAdd = false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003724 haveEaten = true;
3725 }
3726 if (Parser.getTok().is(AsmToken::Identifier))
3727 Reg = tryParseRegister();
3728 if (Reg == -1) {
3729 if (!haveEaten)
3730 return MatchOperand_NoMatch;
3731 Error(Parser.getTok().getLoc(), "register expected");
3732 return MatchOperand_ParseFail;
3733 }
3734 SMLoc E = Parser.getTok().getLoc();
3735
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003736 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3737 unsigned ShiftImm = 0;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00003738 if (Parser.getTok().is(AsmToken::Comma)) {
3739 Parser.Lex(); // Eat the ','.
3740 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3741 return MatchOperand_ParseFail;
3742 }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003743
3744 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3745 ShiftImm, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003746
3747 return MatchOperand_Success;
3748}
3749
Jim Grosbach251bf252011-08-10 21:56:18 +00003750ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3751parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3752 // Check for a post-index addressing register operand. Specifically:
3753 // am3offset := '+' register
3754 // | '-' register
3755 // | register
3756 // | # imm
3757 // | # + imm
3758 // | # - imm
3759
3760 // This method must return MatchOperand_NoMatch without consuming any tokens
3761 // in the case where there is no match, as other alternatives take other
3762 // parse methods.
3763 AsmToken Tok = Parser.getTok();
3764 SMLoc S = Tok.getLoc();
3765
3766 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003767 if (Parser.getTok().is(AsmToken::Hash) ||
3768 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach251bf252011-08-10 21:56:18 +00003769 Parser.Lex(); // Eat the '#'.
3770 // Explicitly look for a '-', as we need to encode negative zero
3771 // differently.
3772 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3773 const MCExpr *Offset;
3774 if (getParser().ParseExpression(Offset))
3775 return MatchOperand_ParseFail;
3776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3777 if (!CE) {
3778 Error(S, "constant expression expected");
3779 return MatchOperand_ParseFail;
3780 }
3781 SMLoc E = Tok.getLoc();
3782 // Negative zero is encoded as the flag value INT32_MIN.
3783 int32_t Val = CE->getValue();
3784 if (isNegative && Val == 0)
3785 Val = INT32_MIN;
3786
3787 Operands.push_back(
3788 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3789
3790 return MatchOperand_Success;
3791 }
3792
3793
3794 bool haveEaten = false;
3795 bool isAdd = true;
3796 int Reg = -1;
3797 if (Tok.is(AsmToken::Plus)) {
3798 Parser.Lex(); // Eat the '+' token.
3799 haveEaten = true;
3800 } else if (Tok.is(AsmToken::Minus)) {
3801 Parser.Lex(); // Eat the '-' token.
3802 isAdd = false;
3803 haveEaten = true;
3804 }
3805 if (Parser.getTok().is(AsmToken::Identifier))
3806 Reg = tryParseRegister();
3807 if (Reg == -1) {
3808 if (!haveEaten)
3809 return MatchOperand_NoMatch;
3810 Error(Parser.getTok().getLoc(), "register expected");
3811 return MatchOperand_ParseFail;
3812 }
3813 SMLoc E = Parser.getTok().getLoc();
3814
3815 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3816 0, S, E));
3817
3818 return MatchOperand_Success;
3819}
3820
Jim Grosbacha77295d2011-09-08 22:07:06 +00003821/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3822/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3823/// when they refer multiple MIOperands inside a single one.
3824bool ARMAsmParser::
3825cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
3826 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3827 // Rt, Rt2
3828 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3829 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3830 // Create a writeback register dummy placeholder.
3831 Inst.addOperand(MCOperand::CreateReg(0));
3832 // addr
3833 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3834 // pred
3835 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3836 return true;
3837}
3838
3839/// cvtT2StrdPre - Convert parsed operands to MCInst.
3840/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3841/// when they refer multiple MIOperands inside a single one.
3842bool ARMAsmParser::
3843cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
3844 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3845 // Create a writeback register dummy placeholder.
3846 Inst.addOperand(MCOperand::CreateReg(0));
3847 // Rt, Rt2
3848 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3849 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3850 // addr
3851 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3852 // pred
3853 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3854 return true;
3855}
3856
Jim Grosbacheeec0252011-09-08 00:39:19 +00003857/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3858/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3859/// when they refer multiple MIOperands inside a single one.
3860bool ARMAsmParser::
3861cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3862 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3863 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3864
3865 // Create a writeback register dummy placeholder.
3866 Inst.addOperand(MCOperand::CreateImm(0));
3867
3868 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3869 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3870 return true;
3871}
3872
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003873/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3874/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3875/// when they refer multiple MIOperands inside a single one.
3876bool ARMAsmParser::
3877cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3878 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3879 // Create a writeback register dummy placeholder.
3880 Inst.addOperand(MCOperand::CreateImm(0));
3881 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3882 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3883 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3884 return true;
3885}
3886
Jim Grosbach1355cf12011-07-26 17:10:22 +00003887/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003888/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3889/// when they refer multiple MIOperands inside a single one.
3890bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003891cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003892 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3893 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3894
3895 // Create a writeback register dummy placeholder.
3896 Inst.addOperand(MCOperand::CreateImm(0));
3897
Jim Grosbach7ce05792011-08-03 23:50:40 +00003898 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003899 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3900 return true;
3901}
3902
Owen Anderson9ab0f252011-08-26 20:43:14 +00003903/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3904/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3905/// when they refer multiple MIOperands inside a single one.
3906bool ARMAsmParser::
3907cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3908 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3909 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3910
3911 // Create a writeback register dummy placeholder.
3912 Inst.addOperand(MCOperand::CreateImm(0));
3913
3914 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3915 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3916 return true;
3917}
3918
3919
Jim Grosbach548340c2011-08-11 19:22:40 +00003920/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3921/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3922/// when they refer multiple MIOperands inside a single one.
3923bool ARMAsmParser::
3924cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3925 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3926 // Create a writeback register dummy placeholder.
3927 Inst.addOperand(MCOperand::CreateImm(0));
3928 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3929 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3930 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3931 return true;
3932}
3933
Jim Grosbach1355cf12011-07-26 17:10:22 +00003934/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003935/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3936/// when they refer multiple MIOperands inside a single one.
3937bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003938cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003939 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3940 // Create a writeback register dummy placeholder.
3941 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach548340c2011-08-11 19:22:40 +00003942 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3943 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3944 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003945 return true;
3946}
3947
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00003948/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3949/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3950/// when they refer multiple MIOperands inside a single one.
3951bool ARMAsmParser::
3952cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3953 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3954 // Create a writeback register dummy placeholder.
3955 Inst.addOperand(MCOperand::CreateImm(0));
3956 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3957 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3958 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3959 return true;
3960}
3961
Jim Grosbach7ce05792011-08-03 23:50:40 +00003962/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
3963/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3964/// when they refer multiple MIOperands inside a single one.
3965bool ARMAsmParser::
3966cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3967 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3968 // Rt
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003969 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003970 // Create a writeback register dummy placeholder.
3971 Inst.addOperand(MCOperand::CreateImm(0));
3972 // addr
3973 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3974 // offset
3975 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3976 // pred
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003977 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3978 return true;
3979}
3980
Jim Grosbach7ce05792011-08-03 23:50:40 +00003981/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003982/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3983/// when they refer multiple MIOperands inside a single one.
3984bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00003985cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3986 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3987 // Rt
Owen Andersonaa3402e2011-07-28 17:18:57 +00003988 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003989 // Create a writeback register dummy placeholder.
3990 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003991 // addr
3992 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3993 // offset
3994 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3995 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003996 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3997 return true;
3998}
3999
Jim Grosbach7ce05792011-08-03 23:50:40 +00004000/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004001/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4002/// when they refer multiple MIOperands inside a single one.
4003bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004004cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
4005 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004006 // Create a writeback register dummy placeholder.
4007 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004008 // Rt
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004009 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004010 // addr
4011 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4012 // offset
4013 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4014 // pred
4015 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4016 return true;
4017}
4018
4019/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4020/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4021/// when they refer multiple MIOperands inside a single one.
4022bool ARMAsmParser::
4023cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
4024 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4025 // Create a writeback register dummy placeholder.
4026 Inst.addOperand(MCOperand::CreateImm(0));
4027 // Rt
4028 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4029 // addr
4030 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4031 // offset
4032 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4033 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004034 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4035 return true;
4036}
4037
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004038/// cvtLdrdPre - Convert parsed operands to MCInst.
4039/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4040/// when they refer multiple MIOperands inside a single one.
4041bool ARMAsmParser::
4042cvtLdrdPre(MCInst &Inst, unsigned Opcode,
4043 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4044 // Rt, Rt2
4045 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4046 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4047 // Create a writeback register dummy placeholder.
4048 Inst.addOperand(MCOperand::CreateImm(0));
4049 // addr
4050 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4051 // pred
4052 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4053 return true;
4054}
4055
Jim Grosbach14605d12011-08-11 20:28:23 +00004056/// cvtStrdPre - Convert parsed operands to MCInst.
4057/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4058/// when they refer multiple MIOperands inside a single one.
4059bool ARMAsmParser::
4060cvtStrdPre(MCInst &Inst, unsigned Opcode,
4061 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4062 // Create a writeback register dummy placeholder.
4063 Inst.addOperand(MCOperand::CreateImm(0));
4064 // Rt, Rt2
4065 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4066 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4067 // addr
4068 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4069 // pred
4070 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4071 return true;
4072}
4073
Jim Grosbach623a4542011-08-10 22:42:16 +00004074/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4075/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4076/// when they refer multiple MIOperands inside a single one.
4077bool ARMAsmParser::
4078cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
4079 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4080 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4081 // Create a writeback register dummy placeholder.
4082 Inst.addOperand(MCOperand::CreateImm(0));
4083 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4084 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4085 return true;
4086}
4087
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004088/// cvtThumbMultiple- Convert parsed operands to MCInst.
4089/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4090/// when they refer multiple MIOperands inside a single one.
4091bool ARMAsmParser::
4092cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
4093 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4094 // The second source operand must be the same register as the destination
4095 // operand.
4096 if (Operands.size() == 6 &&
Jim Grosbach7a010692011-08-19 22:30:46 +00004097 (((ARMOperand*)Operands[3])->getReg() !=
4098 ((ARMOperand*)Operands[5])->getReg()) &&
4099 (((ARMOperand*)Operands[3])->getReg() !=
4100 ((ARMOperand*)Operands[4])->getReg())) {
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004101 Error(Operands[3]->getStartLoc(),
Jim Grosbach7a010692011-08-19 22:30:46 +00004102 "destination register must match source register");
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004103 return false;
4104 }
4105 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4106 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach1b332862011-11-10 22:10:12 +00004107 // If we have a three-operand form, make sure to set Rn to be the operand
4108 // that isn't the same as Rd.
4109 unsigned RegOp = 4;
4110 if (Operands.size() == 6 &&
4111 ((ARMOperand*)Operands[4])->getReg() ==
4112 ((ARMOperand*)Operands[3])->getReg())
4113 RegOp = 5;
4114 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4115 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004116 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4117
4118 return true;
4119}
Jim Grosbach623a4542011-08-10 22:42:16 +00004120
Jim Grosbach12431322011-10-24 22:16:58 +00004121bool ARMAsmParser::
4122cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
4123 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4124 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004125 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004126 // Create a writeback register dummy placeholder.
4127 Inst.addOperand(MCOperand::CreateImm(0));
4128 // Vn
4129 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4130 // pred
4131 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4132 return true;
4133}
4134
4135bool ARMAsmParser::
4136cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
4137 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4138 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004139 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004140 // Create a writeback register dummy placeholder.
4141 Inst.addOperand(MCOperand::CreateImm(0));
4142 // Vn
4143 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4144 // Vm
4145 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4146 // pred
4147 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4148 return true;
4149}
4150
Jim Grosbach4334e032011-10-31 21:50:31 +00004151bool ARMAsmParser::
4152cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
4153 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4154 // Create a writeback register dummy placeholder.
4155 Inst.addOperand(MCOperand::CreateImm(0));
4156 // Vn
4157 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4158 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004159 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004160 // pred
4161 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4162 return true;
4163}
4164
4165bool ARMAsmParser::
4166cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
4167 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4168 // Create a writeback register dummy placeholder.
4169 Inst.addOperand(MCOperand::CreateImm(0));
4170 // Vn
4171 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4172 // Vm
4173 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4174 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004175 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004176 // pred
4177 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4178 return true;
4179}
4180
Bill Wendlinge7176102010-11-06 22:36:58 +00004181/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004182/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00004183bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004184parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +00004185 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00004186 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00004187 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00004188 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004189 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004190
Sean Callanan18b83232010-01-19 21:44:56 +00004191 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbach1355cf12011-07-26 17:10:22 +00004192 int BaseRegNum = tryParseRegister();
Jim Grosbach7ce05792011-08-03 23:50:40 +00004193 if (BaseRegNum == -1)
4194 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004195
Daniel Dunbar05710932011-01-18 05:34:17 +00004196 // The next token must either be a comma or a closing bracket.
4197 const AsmToken &Tok = Parser.getTok();
4198 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004199 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar05710932011-01-18 05:34:17 +00004200
Jim Grosbach7ce05792011-08-03 23:50:40 +00004201 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan76264762010-04-02 22:27:05 +00004202 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004203 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004204
Jim Grosbach7ce05792011-08-03 23:50:40 +00004205 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004206 0, 0, false, S, E));
Jim Grosbach03f44a02010-11-29 23:18:01 +00004207
Jim Grosbachfb12f352011-09-19 18:42:21 +00004208 // If there's a pre-indexing writeback marker, '!', just add it as a token
4209 // operand. It's rather odd, but syntactically valid.
4210 if (Parser.getTok().is(AsmToken::Exclaim)) {
4211 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4212 Parser.Lex(); // Eat the '!'.
4213 }
4214
Jim Grosbach7ce05792011-08-03 23:50:40 +00004215 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004216 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004217
Jim Grosbach7ce05792011-08-03 23:50:40 +00004218 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4219 Parser.Lex(); // Eat the comma.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004220
Jim Grosbach57dcb852011-10-11 17:29:55 +00004221 // If we have a ':', it's an alignment specifier.
4222 if (Parser.getTok().is(AsmToken::Colon)) {
4223 Parser.Lex(); // Eat the ':'.
4224 E = Parser.getTok().getLoc();
4225
4226 const MCExpr *Expr;
4227 if (getParser().ParseExpression(Expr))
4228 return true;
4229
4230 // The expression has to be a constant. Memory references with relocations
4231 // don't come through here, as they use the <label> forms of the relevant
4232 // instructions.
4233 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4234 if (!CE)
4235 return Error (E, "constant expression expected");
4236
4237 unsigned Align = 0;
4238 switch (CE->getValue()) {
4239 default:
Jim Grosbacheeaf1c12011-12-19 18:31:43 +00004240 return Error(E,
4241 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4242 case 16: Align = 2; break;
4243 case 32: Align = 4; break;
Jim Grosbach57dcb852011-10-11 17:29:55 +00004244 case 64: Align = 8; break;
4245 case 128: Align = 16; break;
4246 case 256: Align = 32; break;
4247 }
4248
4249 // Now we should have the closing ']'
4250 E = Parser.getTok().getLoc();
4251 if (Parser.getTok().isNot(AsmToken::RBrac))
4252 return Error(E, "']' expected");
4253 Parser.Lex(); // Eat right bracket token.
4254
4255 // Don't worry about range checking the value here. That's handled by
4256 // the is*() predicates.
4257 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4258 ARM_AM::no_shift, 0, Align,
4259 false, S, E));
4260
4261 // If there's a pre-indexing writeback marker, '!', just add it as a token
4262 // operand.
4263 if (Parser.getTok().is(AsmToken::Exclaim)) {
4264 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4265 Parser.Lex(); // Eat the '!'.
4266 }
4267
4268 return false;
4269 }
4270
4271 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004272 // offset. Be friendly and also accept a plain integer (without a leading
4273 // hash) for gas compatibility.
4274 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004275 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004276 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004277 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004278 Parser.Lex(); // Eat the '#'.
Jim Grosbach7ce05792011-08-03 23:50:40 +00004279 E = Parser.getTok().getLoc();
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004280
Owen Anderson0da10cf2011-08-29 19:36:44 +00004281 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004282 const MCExpr *Offset;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004283 if (getParser().ParseExpression(Offset))
4284 return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004285
4286 // The expression has to be a constant. Memory references with relocations
4287 // don't come through here, as they use the <label> forms of the relevant
4288 // instructions.
4289 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4290 if (!CE)
4291 return Error (E, "constant expression expected");
4292
Owen Anderson0da10cf2011-08-29 19:36:44 +00004293 // If the constant was #-0, represent it as INT32_MIN.
4294 int32_t Val = CE->getValue();
4295 if (isNegative && Val == 0)
4296 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4297
Jim Grosbach7ce05792011-08-03 23:50:40 +00004298 // Now we should have the closing ']'
4299 E = Parser.getTok().getLoc();
4300 if (Parser.getTok().isNot(AsmToken::RBrac))
4301 return Error(E, "']' expected");
4302 Parser.Lex(); // Eat right bracket token.
4303
4304 // Don't worry about range checking the value here. That's handled by
4305 // the is*() predicates.
4306 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004307 ARM_AM::no_shift, 0, 0,
4308 false, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004309
4310 // If there's a pre-indexing writeback marker, '!', just add it as a token
4311 // operand.
4312 if (Parser.getTok().is(AsmToken::Exclaim)) {
4313 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4314 Parser.Lex(); // Eat the '!'.
4315 }
4316
4317 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004318 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004319
4320 // The register offset is optionally preceded by a '+' or '-'
4321 bool isNegative = false;
4322 if (Parser.getTok().is(AsmToken::Minus)) {
4323 isNegative = true;
4324 Parser.Lex(); // Eat the '-'.
4325 } else if (Parser.getTok().is(AsmToken::Plus)) {
4326 // Nothing to do.
4327 Parser.Lex(); // Eat the '+'.
4328 }
4329
4330 E = Parser.getTok().getLoc();
4331 int OffsetRegNum = tryParseRegister();
4332 if (OffsetRegNum == -1)
4333 return Error(E, "register expected");
4334
4335 // If there's a shift operator, handle it.
4336 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004337 unsigned ShiftImm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004338 if (Parser.getTok().is(AsmToken::Comma)) {
4339 Parser.Lex(); // Eat the ','.
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004340 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004341 return true;
4342 }
4343
4344 // Now we should have the closing ']'
4345 E = Parser.getTok().getLoc();
4346 if (Parser.getTok().isNot(AsmToken::RBrac))
4347 return Error(E, "']' expected");
4348 Parser.Lex(); // Eat right bracket token.
4349
4350 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004351 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004352 S, E));
4353
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00004354 // If there's a pre-indexing writeback marker, '!', just add it as a token
4355 // operand.
4356 if (Parser.getTok().is(AsmToken::Exclaim)) {
4357 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4358 Parser.Lex(); // Eat the '!'.
4359 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004360
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004361 return false;
4362}
4363
Jim Grosbach7ce05792011-08-03 23:50:40 +00004364/// parseMemRegOffsetShift - one of these two:
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004365/// ( lsl | lsr | asr | ror ) , # shift_amount
4366/// rrx
Jim Grosbach7ce05792011-08-03 23:50:40 +00004367/// return true if it parses a shift otherwise it returns false.
4368bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4369 unsigned &Amount) {
4370 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan18b83232010-01-19 21:44:56 +00004371 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004372 if (Tok.isNot(AsmToken::Identifier))
4373 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00004374 StringRef ShiftName = Tok.getString();
Jim Grosbachaf4edea2011-12-07 23:40:58 +00004375 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4376 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson00828302011-03-18 22:50:18 +00004377 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004378 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00004379 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004380 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00004381 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004382 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00004383 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004384 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00004385 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004386 else
Jim Grosbach7ce05792011-08-03 23:50:40 +00004387 return Error(Loc, "illegal shift operator");
Sean Callananb9a25b72010-01-19 20:27:46 +00004388 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004389
Jim Grosbach7ce05792011-08-03 23:50:40 +00004390 // rrx stands alone.
4391 Amount = 0;
4392 if (St != ARM_AM::rrx) {
4393 Loc = Parser.getTok().getLoc();
4394 // A '#' and a shift amount.
4395 const AsmToken &HashTok = Parser.getTok();
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004396 if (HashTok.isNot(AsmToken::Hash) &&
4397 HashTok.isNot(AsmToken::Dollar))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004398 return Error(HashTok.getLoc(), "'#' expected");
4399 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004400
Jim Grosbach7ce05792011-08-03 23:50:40 +00004401 const MCExpr *Expr;
4402 if (getParser().ParseExpression(Expr))
4403 return true;
4404 // Range check the immediate.
4405 // lsl, ror: 0 <= imm <= 31
4406 // lsr, asr: 0 <= imm <= 32
4407 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4408 if (!CE)
4409 return Error(Loc, "shift amount must be an immediate");
4410 int64_t Imm = CE->getValue();
4411 if (Imm < 0 ||
4412 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4413 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4414 return Error(Loc, "immediate shift value out of range");
4415 Amount = Imm;
4416 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004417
4418 return false;
4419}
4420
Jim Grosbach9d390362011-10-03 23:38:36 +00004421/// parseFPImm - A floating point immediate expression operand.
4422ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4423parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004424 // Anything that can accept a floating point constant as an operand
4425 // needs to go through here, as the regular ParseExpression is
4426 // integer only.
4427 //
4428 // This routine still creates a generic Immediate operand, containing
4429 // a bitcast of the 64-bit floating point value. The various operands
4430 // that accept floats can check whether the value is valid for them
4431 // via the standard is*() predicates.
4432
Jim Grosbach9d390362011-10-03 23:38:36 +00004433 SMLoc S = Parser.getTok().getLoc();
4434
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004435 if (Parser.getTok().isNot(AsmToken::Hash) &&
4436 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbach9d390362011-10-03 23:38:36 +00004437 return MatchOperand_NoMatch;
Jim Grosbach0e387b22011-10-17 22:26:03 +00004438
4439 // Disambiguate the VMOV forms that can accept an FP immediate.
4440 // vmov.f32 <sreg>, #imm
4441 // vmov.f64 <dreg>, #imm
4442 // vmov.f32 <dreg>, #imm @ vector f32x2
4443 // vmov.f32 <qreg>, #imm @ vector f32x4
4444 //
4445 // There are also the NEON VMOV instructions which expect an
4446 // integer constant. Make sure we don't try to parse an FPImm
4447 // for these:
4448 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4449 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4450 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4451 TyOp->getToken() != ".f64"))
4452 return MatchOperand_NoMatch;
4453
Jim Grosbach9d390362011-10-03 23:38:36 +00004454 Parser.Lex(); // Eat the '#'.
4455
4456 // Handle negation, as that still comes through as a separate token.
4457 bool isNegative = false;
4458 if (Parser.getTok().is(AsmToken::Minus)) {
4459 isNegative = true;
4460 Parser.Lex();
4461 }
4462 const AsmToken &Tok = Parser.getTok();
Jim Grosbachae69f702012-01-19 02:47:30 +00004463 SMLoc Loc = Tok.getLoc();
Jim Grosbach9d390362011-10-03 23:38:36 +00004464 if (Tok.is(AsmToken::Real)) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004465 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbach9d390362011-10-03 23:38:36 +00004466 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4467 // If we had a '-' in front, toggle the sign bit.
Jim Grosbach51222d12012-01-20 18:09:51 +00004468 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbach9d390362011-10-03 23:38:36 +00004469 Parser.Lex(); // Eat the token.
Jim Grosbach51222d12012-01-20 18:09:51 +00004470 Operands.push_back(ARMOperand::CreateImm(
4471 MCConstantExpr::Create(IntVal, getContext()),
4472 S, Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004473 return MatchOperand_Success;
4474 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004475 // Also handle plain integers. Instructions which allow floating point
4476 // immediates also allow a raw encoded 8-bit value.
Jim Grosbach9d390362011-10-03 23:38:36 +00004477 if (Tok.is(AsmToken::Integer)) {
4478 int64_t Val = Tok.getIntVal();
4479 Parser.Lex(); // Eat the token.
4480 if (Val > 255 || Val < 0) {
Jim Grosbachae69f702012-01-19 02:47:30 +00004481 Error(Loc, "encoded floating point value out of range");
Jim Grosbach9d390362011-10-03 23:38:36 +00004482 return MatchOperand_ParseFail;
4483 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004484 double RealVal = ARM_AM::getFPImmFloat(Val);
4485 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4486 Operands.push_back(ARMOperand::CreateImm(
4487 MCConstantExpr::Create(Val, getContext()), S,
4488 Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004489 return MatchOperand_Success;
4490 }
4491
Jim Grosbachae69f702012-01-19 02:47:30 +00004492 Error(Loc, "invalid floating point immediate");
Jim Grosbach9d390362011-10-03 23:38:36 +00004493 return MatchOperand_ParseFail;
4494}
Jim Grosbach51222d12012-01-20 18:09:51 +00004495
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004496/// Parse a arm instruction operand. For now this parses the operand regardless
4497/// of the mnemonic.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004498bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004499 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00004500 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004501
4502 // Check if the current operand has a custom associated parser, if so, try to
4503 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00004504 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4505 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004506 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00004507 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4508 // there was a match, but an error occurred, in which case, just return that
4509 // the operand parsing failed.
4510 if (ResTy == MatchOperand_ParseFail)
4511 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004512
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004513 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00004514 default:
4515 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00004516 return true;
Jim Grosbach19906722011-07-13 18:49:30 +00004517 case AsmToken::Identifier: {
Jim Grosbach1355cf12011-07-26 17:10:22 +00004518 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling50d0f582010-11-18 23:43:05 +00004519 return false;
Jim Grosbach0d87ec22011-07-26 20:41:24 +00004520 int Res = tryParseShiftRegister(Operands);
Jim Grosbach19906722011-07-13 18:49:30 +00004521 if (Res == 0) // success
Owen Anderson00828302011-03-18 22:50:18 +00004522 return false;
Jim Grosbach19906722011-07-13 18:49:30 +00004523 else if (Res == -1) // irrecoverable error
4524 return true;
Jim Grosbach3cbe43f2011-12-20 22:26:38 +00004525 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004526 if (Mnemonic == "vmrs" &&
4527 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004528 S = Parser.getTok().getLoc();
4529 Parser.Lex();
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004530 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004531 return false;
4532 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00004533
4534 // Fall though for the Identifier case that is not a register or a
4535 // special name.
Jim Grosbach19906722011-07-13 18:49:30 +00004536 }
Jim Grosbach758a5192011-10-26 21:14:08 +00004537 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderby67b212e2011-01-13 20:32:36 +00004538 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach6284afc2011-11-01 22:38:31 +00004539 case AsmToken::String: // quoted label names.
Kevin Enderby67b212e2011-01-13 20:32:36 +00004540 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00004541 // This was not a register so parse other operands that start with an
4542 // identifier (like labels) as expressions and create them as immediates.
4543 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00004544 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00004545 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004546 return true;
Sean Callanan76264762010-04-02 22:27:05 +00004547 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004548 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4549 return false;
4550 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004551 case AsmToken::LBrac:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004552 return parseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00004553 case AsmToken::LCurly:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004554 return parseRegisterList(Operands);
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004555 case AsmToken::Dollar:
Owen Anderson63553c72011-08-29 17:17:09 +00004556 case AsmToken::Hash: {
Kevin Enderby079469f2009-10-13 23:33:38 +00004557 // #42 -> immediate.
Sean Callanan76264762010-04-02 22:27:05 +00004558 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004559 Parser.Lex();
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004560
4561 if (Parser.getTok().isNot(AsmToken::Colon)) {
4562 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4563 const MCExpr *ImmVal;
4564 if (getParser().ParseExpression(ImmVal))
4565 return true;
4566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4567 if (CE) {
4568 int32_t Val = CE->getValue();
4569 if (isNegative && Val == 0)
4570 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4571 }
4572 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4573 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4574 return false;
Owen Anderson63553c72011-08-29 17:17:09 +00004575 }
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004576 // w/ a ':' after the '#', it's just like a plain ':'.
4577 // FALLTHROUGH
Owen Anderson63553c72011-08-29 17:17:09 +00004578 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004579 case AsmToken::Colon: {
4580 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00004581 // FIXME: Check it's an expression prefix,
4582 // e.g. (FOO - :lower16:BAR) isn't legal.
4583 ARMMCExpr::VariantKind RefKind;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004584 if (parsePrefix(RefKind))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004585 return true;
4586
Evan Cheng75972122011-01-13 07:58:56 +00004587 const MCExpr *SubExprVal;
4588 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004589 return true;
4590
Evan Cheng75972122011-01-13 07:58:56 +00004591 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4592 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00004593 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00004594 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00004595 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004596 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004597 }
4598}
4599
Jim Grosbach1355cf12011-07-26 17:10:22 +00004600// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng75972122011-01-13 07:58:56 +00004601// :lower16: and :upper16:.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004602bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng75972122011-01-13 07:58:56 +00004603 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004604
4605 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00004606 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00004607 Parser.Lex(); // Eat ':'
4608
4609 if (getLexer().isNot(AsmToken::Identifier)) {
4610 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4611 return true;
4612 }
4613
4614 StringRef IDVal = Parser.getTok().getIdentifier();
4615 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00004616 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004617 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00004618 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004619 } else {
4620 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4621 return true;
4622 }
4623 Parser.Lex();
4624
4625 if (getLexer().isNot(AsmToken::Colon)) {
4626 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4627 return true;
4628 }
4629 Parser.Lex(); // Eat the last ':'
4630 return false;
4631}
4632
Daniel Dunbar352e1482011-01-11 15:59:50 +00004633/// \brief Given a mnemonic, split out possible predication code and carry
4634/// setting letters to form a canonical mnemonic and flags.
4635//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004636// FIXME: Would be nice to autogen this.
Jim Grosbach89df9962011-08-26 21:43:41 +00004637// FIXME: This is a bit of a maze of special cases.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004638StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5f160572011-07-19 20:10:31 +00004639 unsigned &PredicationCode,
4640 bool &CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004641 unsigned &ProcessorIMod,
4642 StringRef &ITMask) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004643 PredicationCode = ARMCC::AL;
4644 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004645 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004646
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004647 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00004648 //
4649 // FIXME: Would be nice to autogen this.
Jim Grosbach5f160572011-07-19 20:10:31 +00004650 if ((Mnemonic == "movs" && isThumb()) ||
4651 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4652 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4653 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4654 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4655 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4656 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbach68490192011-12-19 19:43:50 +00004657 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4658 Mnemonic == "fmuls")
Daniel Dunbar352e1482011-01-11 15:59:50 +00004659 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00004660
Jim Grosbach3f00e312011-07-11 17:09:57 +00004661 // First, split out any predication code. Ignore mnemonics we know aren't
4662 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbachab40f4b2011-07-20 18:20:31 +00004663 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach71725a02011-07-27 21:58:11 +00004664 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach04d55f12011-08-22 23:55:58 +00004665 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbach2f25d9b2011-09-01 18:22:13 +00004666 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbach3f00e312011-07-11 17:09:57 +00004667 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4668 .Case("eq", ARMCC::EQ)
4669 .Case("ne", ARMCC::NE)
4670 .Case("hs", ARMCC::HS)
4671 .Case("cs", ARMCC::HS)
4672 .Case("lo", ARMCC::LO)
4673 .Case("cc", ARMCC::LO)
4674 .Case("mi", ARMCC::MI)
4675 .Case("pl", ARMCC::PL)
4676 .Case("vs", ARMCC::VS)
4677 .Case("vc", ARMCC::VC)
4678 .Case("hi", ARMCC::HI)
4679 .Case("ls", ARMCC::LS)
4680 .Case("ge", ARMCC::GE)
4681 .Case("lt", ARMCC::LT)
4682 .Case("gt", ARMCC::GT)
4683 .Case("le", ARMCC::LE)
4684 .Case("al", ARMCC::AL)
4685 .Default(~0U);
4686 if (CC != ~0U) {
4687 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4688 PredicationCode = CC;
4689 }
Bill Wendling52925b62010-10-29 23:50:21 +00004690 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004691
Daniel Dunbar352e1482011-01-11 15:59:50 +00004692 // Next, determine if we have a carry setting bit. We explicitly ignore all
4693 // the instructions we know end in 's'.
4694 if (Mnemonic.endswith("s") &&
Jim Grosbach00f5d982011-08-17 22:49:09 +00004695 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5f160572011-07-19 20:10:31 +00004696 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4697 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4698 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach67ca1ad2011-12-08 00:49:29 +00004699 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach48171e72011-12-10 00:01:02 +00004700 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach9c397892011-12-19 19:02:41 +00004701 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbach6357cae2012-03-15 20:48:18 +00004702 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004703 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbache1cf5902011-07-29 20:26:09 +00004704 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004705 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4706 CarrySetting = true;
4707 }
4708
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004709 // The "cps" instruction can have a interrupt mode operand which is glued into
4710 // the mnemonic. Check if this is the case, split it and parse the imod op
4711 if (Mnemonic.startswith("cps")) {
4712 // Split out any imod code.
4713 unsigned IMod =
4714 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4715 .Case("ie", ARM_PROC::IE)
4716 .Case("id", ARM_PROC::ID)
4717 .Default(~0U);
4718 if (IMod != ~0U) {
4719 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4720 ProcessorIMod = IMod;
4721 }
4722 }
4723
Jim Grosbach89df9962011-08-26 21:43:41 +00004724 // The "it" instruction has the condition mask on the end of the mnemonic.
4725 if (Mnemonic.startswith("it")) {
4726 ITMask = Mnemonic.slice(2, Mnemonic.size());
4727 Mnemonic = Mnemonic.slice(0, 2);
4728 }
4729
Daniel Dunbar352e1482011-01-11 15:59:50 +00004730 return Mnemonic;
4731}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004732
4733/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4734/// inclusion of carry set or predication code operands.
4735//
4736// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004737void ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00004738getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004739 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004740 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4741 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004742 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004743 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004744 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004745 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004746 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004747 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004748 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004749 Mnemonic == "mla" || Mnemonic == "smlal" ||
4750 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004751 CanAcceptCarrySet = true;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004752 } else
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004753 CanAcceptCarrySet = false;
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004754
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004755 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4756 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4757 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4758 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbachad2dad92011-09-06 20:27:04 +00004759 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4760 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach0780b632011-08-19 23:24:36 +00004761 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach2bd01182011-10-11 21:55:36 +00004762 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4763 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4764 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbach4af54a42011-08-26 22:21:51 +00004765 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4766 !isThumb()) ||
Jim Grosbach1ad60c22011-09-10 00:15:36 +00004767 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004768 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004769 } else
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004770 CanAcceptPredicationCode = true;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004771
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004772 if (isThumb()) {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004773 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00004774 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004775 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004776 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004777}
4778
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004779bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4780 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004781 // FIXME: This is all horribly hacky. We really need a better way to deal
4782 // with optional operands like this in the matcher table.
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004783
4784 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4785 // another does not. Specifically, the MOVW instruction does not. So we
4786 // special case it here and remove the defaulted (non-setting) cc_out
4787 // operand if that's the instruction we're trying to match.
4788 //
4789 // We do this as post-processing of the explicit operands rather than just
4790 // conditionally adding the cc_out in the first place because we need
4791 // to check the type of the parsed immediate operand.
Owen Anderson8adf6202011-09-14 22:46:14 +00004792 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004793 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4794 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4795 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4796 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004797
4798 // Register-register 'add' for thumb does not have a cc_out operand
4799 // when there are only two register operands.
4800 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4801 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4802 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4803 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4804 return true;
Jim Grosbach72f39f82011-08-24 21:22:15 +00004805 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004806 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4807 // have to check the immediate range here since Thumb2 has a variant
4808 // that can handle a different range and has a cc_out operand.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004809 if (((isThumb() && Mnemonic == "add") ||
4810 (isThumbTwo() && Mnemonic == "sub")) &&
4811 Operands.size() == 6 &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004812 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4813 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4814 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004815 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004816 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004817 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004818 return true;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004819 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4820 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004821 // selecting via the generic "add" mnemonic, so to know that we
4822 // should remove the cc_out operand, we have to explicitly check that
4823 // it's not one of the other variants. Ugh.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004824 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4825 Operands.size() == 6 &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004826 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4827 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4828 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4829 // Nest conditions rather than one big 'if' statement for readability.
4830 //
4831 // If either register is a high reg, it's either one of the SP
4832 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach12a88632012-01-21 00:07:56 +00004833 // check against T3. If the second register is the PC, this is an
4834 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004835 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4836 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach12a88632012-01-21 00:07:56 +00004837 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004838 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4839 return false;
4840 // If both registers are low, we're in an IT block, and the immediate is
4841 // in range, we should use encoding T1 instead, which has a cc_out.
4842 if (inITBlock() &&
Jim Grosbach64944f42011-09-14 21:00:40 +00004843 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004844 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4845 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4846 return false;
4847
4848 // Otherwise, we use encoding T4, which does not have a cc_out
4849 // operand.
4850 return true;
4851 }
4852
Jim Grosbach64944f42011-09-14 21:00:40 +00004853 // The thumb2 multiply instruction doesn't have a CCOut register, so
4854 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4855 // use the 16-bit encoding or not.
4856 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4857 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4858 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4859 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4860 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4861 // If the registers aren't low regs, the destination reg isn't the
4862 // same as one of the source regs, or the cc_out operand is zero
4863 // outside of an IT block, we have to use the 32-bit encoding, so
4864 // remove the cc_out operand.
4865 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4866 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach1de0bd12011-11-15 19:29:45 +00004867 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach64944f42011-09-14 21:00:40 +00004868 !inITBlock() ||
4869 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4870 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4871 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4872 static_cast<ARMOperand*>(Operands[4])->getReg())))
4873 return true;
4874
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004875 // Also check the 'mul' syntax variant that doesn't specify an explicit
4876 // destination register.
4877 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4878 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4879 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4880 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4881 // If the registers aren't low regs or the cc_out operand is zero
4882 // outside of an IT block, we have to use the 32-bit encoding, so
4883 // remove the cc_out operand.
4884 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4885 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4886 !inITBlock()))
4887 return true;
4888
Jim Grosbach64944f42011-09-14 21:00:40 +00004889
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004890
Jim Grosbachf69c8042011-08-24 21:42:27 +00004891 // Register-register 'add/sub' for thumb does not have a cc_out operand
4892 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4893 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4894 // right, this will result in better diagnostics (which operand is off)
4895 // anyway.
4896 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4897 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004898 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4899 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004900 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4901 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4902 (Operands.size() == 6 &&
4903 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004904 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004905
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004906 return false;
4907}
4908
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004909static bool isDataTypeToken(StringRef Tok) {
4910 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4911 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4912 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4913 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4914 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4915 Tok == ".f" || Tok == ".d";
4916}
4917
4918// FIXME: This bit should probably be handled via an explicit match class
4919// in the .td files that matches the suffix instead of having it be
4920// a literal string token the way it is now.
4921static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4922 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4923}
4924
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004925static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004926/// Parse an arm instruction mnemonic followed by its operands.
4927bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4928 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004929 // Apply mnemonic aliases before doing anything else, as the destination
4930 // mnemnonic may include suffices and we want to handle them normally.
4931 // The generic tblgen'erated code does this later, at the start of
4932 // MatchInstructionImpl(), but that's too late for aliases that include
4933 // any sort of suffix.
4934 unsigned AvailableFeatures = getAvailableFeatures();
4935 applyMnemonicAliases(Name, AvailableFeatures);
4936
Jim Grosbacha39cda72011-12-14 02:16:11 +00004937 // First check for the ARM-specific .req directive.
4938 if (Parser.getTok().is(AsmToken::Identifier) &&
4939 Parser.getTok().getIdentifier() == ".req") {
4940 parseDirectiveReq(Name, NameLoc);
4941 // We always return 'error' for this, as we're done with this
4942 // statement and don't need to match the 'instruction."
4943 return true;
4944 }
4945
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004946 // Create the leading tokens for the mnemonic, split by '.' characters.
4947 size_t Start = 0, Next = Name.find('.');
Jim Grosbachffa32252011-07-19 19:13:28 +00004948 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004949
Daniel Dunbar352e1482011-01-11 15:59:50 +00004950 // Split out the predication code and carry setting flag from the mnemonic.
4951 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004952 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004953 bool CarrySetting;
Jim Grosbach89df9962011-08-26 21:43:41 +00004954 StringRef ITMask;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004955 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004956 ProcessorIMod, ITMask);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004957
Jim Grosbach0c49ac02011-08-25 17:23:55 +00004958 // In Thumb1, only the branch (B) instruction can be predicated.
4959 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4960 Parser.EatToEndOfStatement();
4961 return Error(NameLoc, "conditional execution not supported in Thumb1");
4962 }
4963
Jim Grosbachffa32252011-07-19 19:13:28 +00004964 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4965
Jim Grosbach89df9962011-08-26 21:43:41 +00004966 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4967 // is the mask as it will be for the IT encoding if the conditional
4968 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4969 // where the conditional bit0 is zero, the instruction post-processing
4970 // will adjust the mask accordingly.
4971 if (Mnemonic == "it") {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004972 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4973 if (ITMask.size() > 3) {
4974 Parser.EatToEndOfStatement();
4975 return Error(Loc, "too many conditions on IT instruction");
4976 }
Jim Grosbach89df9962011-08-26 21:43:41 +00004977 unsigned Mask = 8;
4978 for (unsigned i = ITMask.size(); i != 0; --i) {
4979 char pos = ITMask[i - 1];
4980 if (pos != 't' && pos != 'e') {
4981 Parser.EatToEndOfStatement();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004982 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach89df9962011-08-26 21:43:41 +00004983 }
4984 Mask >>= 1;
4985 if (ITMask[i - 1] == 't')
4986 Mask |= 8;
4987 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004988 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach89df9962011-08-26 21:43:41 +00004989 }
4990
Jim Grosbachffa32252011-07-19 19:13:28 +00004991 // FIXME: This is all a pretty gross hack. We should automatically handle
4992 // optional operands like this via tblgen.
Bill Wendling9717fa92010-11-21 10:56:05 +00004993
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004994 // Next, add the CCOut and ConditionCode operands, if needed.
4995 //
4996 // For mnemonics which can ever incorporate a carry setting bit or predication
4997 // code, our matching model involves us always generating CCOut and
4998 // ConditionCode operands to match the mnemonic "as written" and then we let
4999 // the matcher deal with finding the right instruction or generating an
5000 // appropriate error.
5001 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbach1355cf12011-07-26 17:10:22 +00005002 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005003
Jim Grosbach33c16a22011-07-14 22:04:21 +00005004 // If we had a carry-set on an instruction that can't do that, issue an
5005 // error.
5006 if (!CanAcceptCarrySet && CarrySetting) {
5007 Parser.EatToEndOfStatement();
Jim Grosbachffa32252011-07-19 19:13:28 +00005008 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach33c16a22011-07-14 22:04:21 +00005009 "' can not set flags, but 's' suffix specified");
5010 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +00005011 // If we had a predication code on an instruction that can't do that, issue an
5012 // error.
5013 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5014 Parser.EatToEndOfStatement();
5015 return Error(NameLoc, "instruction '" + Mnemonic +
5016 "' is not predicable, but condition code specified");
5017 }
Jim Grosbach33c16a22011-07-14 22:04:21 +00005018
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005019 // Add the carry setting operand, if necessary.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005020 if (CanAcceptCarrySet) {
5021 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005022 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005023 Loc));
5024 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005025
5026 // Add the predication code operand, if necessary.
5027 if (CanAcceptPredicationCode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005028 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5029 CarrySetting);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005030 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005031 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00005032 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005033
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005034 // Add the processor imod operand, if necessary.
5035 if (ProcessorIMod) {
5036 Operands.push_back(ARMOperand::CreateImm(
5037 MCConstantExpr::Create(ProcessorIMod, getContext()),
5038 NameLoc, NameLoc));
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005039 }
5040
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005041 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00005042 while (Next != StringRef::npos) {
5043 Start = Next;
5044 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005045 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005046
Jim Grosbach7aef99b2011-11-11 23:08:10 +00005047 // Some NEON instructions have an optional datatype suffix that is
5048 // completely ignored. Check for that.
5049 if (isDataTypeToken(ExtraToken) &&
5050 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5051 continue;
5052
Jim Grosbach81d2e392011-09-07 16:06:04 +00005053 if (ExtraToken != ".n") {
5054 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5055 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5056 }
Daniel Dunbar5747b132010-08-11 06:37:16 +00005057 }
5058
5059 // Read the remaining operands.
5060 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005061 // Read the first operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005062 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005063 Parser.EatToEndOfStatement();
5064 return true;
5065 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005066
5067 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00005068 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005069
5070 // Parse and remember the operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005071 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005072 Parser.EatToEndOfStatement();
5073 return true;
5074 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005075 }
5076 }
Jim Grosbach16c74252010-10-29 14:46:02 +00005077
Chris Lattnercbf8a982010-09-11 16:18:25 +00005078 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbach186ffac2011-10-07 18:27:04 +00005079 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00005080 Parser.EatToEndOfStatement();
Jim Grosbach186ffac2011-10-07 18:27:04 +00005081 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00005082 }
Bill Wendling146018f2010-11-06 21:42:12 +00005083
Chris Lattner34e53142010-09-08 05:10:46 +00005084 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbachffa32252011-07-19 19:13:28 +00005085
Jim Grosbachd54b4e62011-08-16 21:12:37 +00005086 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5087 // do and don't have a cc_out optional-def operand. With some spot-checks
5088 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach20ed2e72011-09-01 00:28:52 +00005089 // parse and adjust accordingly before actually matching. We shouldn't ever
5090 // try to remove a cc_out operand that was explicitly set on the the
5091 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5092 // table driven matcher doesn't fit well with the ARM instruction set.
5093 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbachffa32252011-07-19 19:13:28 +00005094 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5095 Operands.erase(Operands.begin() + 1);
5096 delete Op;
5097 }
5098
Jim Grosbachcf121c32011-07-28 21:57:55 +00005099 // ARM mode 'blx' need special handling, as the register operand version
5100 // is predicable, but the label operand version is not. So, we can't rely
5101 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach21ff17c2011-10-07 23:24:09 +00005102 // a k_CondCode operand in the list. If we're trying to match the label
5103 // version, remove the k_CondCode operand here.
Jim Grosbachcf121c32011-07-28 21:57:55 +00005104 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5105 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5106 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5107 Operands.erase(Operands.begin() + 1);
5108 delete Op;
5109 }
Jim Grosbach857e1a72011-08-11 23:51:13 +00005110
5111 // The vector-compare-to-zero instructions have a literal token "#0" at
5112 // the end that comes to here as an immediate operand. Convert it to a
5113 // token to play nicely with the matcher.
5114 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5115 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5116 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5117 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5118 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5119 if (CE && CE->getValue() == 0) {
5120 Operands.erase(Operands.begin() + 5);
5121 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5122 delete Op;
5123 }
5124 }
Jim Grosbach68259142011-10-03 22:30:24 +00005125 // VCMP{E} does the same thing, but with a different operand count.
5126 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5127 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5128 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5129 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5130 if (CE && CE->getValue() == 0) {
5131 Operands.erase(Operands.begin() + 4);
5132 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5133 delete Op;
5134 }
5135 }
Jim Grosbach934755a2011-08-22 23:47:13 +00005136 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach55b02f22011-12-13 20:50:38 +00005137 // end. Convert it to a token here. Take care not to convert those
5138 // that should hit the Thumb2 encoding.
Jim Grosbach934755a2011-08-22 23:47:13 +00005139 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach55b02f22011-12-13 20:50:38 +00005140 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5141 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbach934755a2011-08-22 23:47:13 +00005142 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5143 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5144 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach55b02f22011-12-13 20:50:38 +00005145 if (CE && CE->getValue() == 0 &&
5146 (isThumbOne() ||
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005147 // The cc_out operand matches the IT block.
5148 ((inITBlock() != CarrySetting) &&
5149 // Neither register operand is a high register.
Jim Grosbach55b02f22011-12-13 20:50:38 +00005150 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005151 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbach934755a2011-08-22 23:47:13 +00005152 Operands.erase(Operands.begin() + 5);
5153 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5154 delete Op;
5155 }
5156 }
5157
Chris Lattner98986712010-01-14 22:21:20 +00005158 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00005159}
5160
Jim Grosbach189610f2011-07-26 18:25:39 +00005161// Validate context-sensitive operand constraints.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005162
5163// return 'true' if register list contains non-low GPR registers,
5164// 'false' otherwise. If Reg is in the register list or is HiReg, set
5165// 'containsReg' to true.
5166static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5167 unsigned HiReg, bool &containsReg) {
5168 containsReg = false;
5169 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5170 unsigned OpReg = Inst.getOperand(i).getReg();
5171 if (OpReg == Reg)
5172 containsReg = true;
5173 // Anything other than a low register isn't legal here.
5174 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5175 return true;
5176 }
5177 return false;
5178}
5179
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005180// Check if the specified regisgter is in the register list of the inst,
5181// starting at the indicated operand number.
5182static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5183 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5184 unsigned OpReg = Inst.getOperand(i).getReg();
5185 if (OpReg == Reg)
5186 return true;
5187 }
5188 return false;
5189}
5190
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005191// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5192// the ARMInsts array) instead. Getting that here requires awkward
5193// API changes, though. Better way?
5194namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005195extern const MCInstrDesc ARMInsts[];
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005196}
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005197static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005198 return ARMInsts[Opcode];
5199}
5200
Jim Grosbach189610f2011-07-26 18:25:39 +00005201// FIXME: We would really like to be able to tablegen'erate this.
5202bool ARMAsmParser::
5203validateInstruction(MCInst &Inst,
5204 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005205 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005206 SMLoc Loc = Operands[0]->getStartLoc();
5207 // Check the IT block state first.
Jim Grosbach74423e32012-01-25 19:52:01 +00005208 // NOTE: BKPT instruction has the interesting property of being
5209 // allowed in IT blocks, but not being predicable. It just always
Owen Andersonb6b7f512011-09-13 17:59:19 +00005210 // executes.
Jim Grosbach74423e32012-01-25 19:52:01 +00005211 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5212 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005213 unsigned bit = 1;
5214 if (ITState.FirstCond)
5215 ITState.FirstCond = false;
5216 else
Jim Grosbacha1109882011-09-02 23:22:08 +00005217 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005218 // The instruction must be predicable.
5219 if (!MCID.isPredicable())
5220 return Error(Loc, "instructions in IT block must be predicable");
5221 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5222 unsigned ITCond = bit ? ITState.Cond :
5223 ARMCC::getOppositeCondition(ITState.Cond);
5224 if (Cond != ITCond) {
5225 // Find the condition code Operand to get its SMLoc information.
5226 SMLoc CondLoc;
5227 for (unsigned i = 1; i < Operands.size(); ++i)
5228 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5229 CondLoc = Operands[i]->getStartLoc();
5230 return Error(CondLoc, "incorrect condition in IT block; got '" +
5231 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5232 "', but expected '" +
5233 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5234 }
Jim Grosbachc9a9b442011-08-31 18:29:05 +00005235 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005236 } else if (isThumbTwo() && MCID.isPredicable() &&
5237 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson51f6a7a2011-09-09 21:48:23 +00005238 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5239 Inst.getOpcode() != ARM::t2B)
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005240 return Error(Loc, "predicated instructions must be in IT block");
5241
Jim Grosbach189610f2011-07-26 18:25:39 +00005242 switch (Inst.getOpcode()) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00005243 case ARM::LDRD:
5244 case ARM::LDRD_PRE:
5245 case ARM::LDRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005246 case ARM::LDREXD: {
5247 // Rt2 must be Rt + 1.
5248 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5249 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5250 if (Rt2 != Rt + 1)
5251 return Error(Operands[3]->getStartLoc(),
5252 "destination operands must be sequential");
5253 return false;
5254 }
Jim Grosbach14605d12011-08-11 20:28:23 +00005255 case ARM::STRD: {
5256 // Rt2 must be Rt + 1.
5257 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5258 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5259 if (Rt2 != Rt + 1)
5260 return Error(Operands[3]->getStartLoc(),
5261 "source operands must be sequential");
5262 return false;
5263 }
Jim Grosbach53642c52011-08-10 20:49:18 +00005264 case ARM::STRD_PRE:
5265 case ARM::STRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005266 case ARM::STREXD: {
5267 // Rt2 must be Rt + 1.
5268 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5269 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(2).getReg());
5270 if (Rt2 != Rt + 1)
Jim Grosbach14605d12011-08-11 20:28:23 +00005271 return Error(Operands[3]->getStartLoc(),
Jim Grosbach189610f2011-07-26 18:25:39 +00005272 "source operands must be sequential");
5273 return false;
5274 }
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005275 case ARM::SBFX:
5276 case ARM::UBFX: {
5277 // width must be in range [1, 32-lsb]
5278 unsigned lsb = Inst.getOperand(2).getImm();
5279 unsigned widthm1 = Inst.getOperand(3).getImm();
5280 if (widthm1 >= 32 - lsb)
5281 return Error(Operands[5]->getStartLoc(),
5282 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach00c9a512011-08-16 21:42:31 +00005283 return false;
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005284 }
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005285 case ARM::tLDMIA: {
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005286 // If we're parsing Thumb2, the .w variant is available and handles
5287 // most cases that are normally illegal for a Thumb1 LDM
5288 // instruction. We'll make the transformation in processInstruction()
5289 // if necessary.
5290 //
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005291 // Thumb LDM instructions are writeback iff the base register is not
5292 // in the register list.
5293 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005294 bool hasWritebackToken =
5295 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5296 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbachaa875f82011-08-23 18:13:04 +00005297 bool listContainsBase;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005298 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005299 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5300 "registers must be in range r0-r7");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005301 // If we should have writeback, then there should be a '!' token.
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005302 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005303 return Error(Operands[2]->getStartLoc(),
5304 "writeback operator '!' expected");
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005305 // If we should not have writeback, there must not be a '!'. This is
5306 // true even for the 32-bit wide encodings.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005307 if (listContainsBase && hasWritebackToken)
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005308 return Error(Operands[3]->getStartLoc(),
5309 "writeback operator '!' not allowed when base register "
5310 "in register list");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005311
5312 break;
5313 }
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005314 case ARM::t2LDMIA_UPD: {
5315 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5316 return Error(Operands[4]->getStartLoc(),
5317 "writeback operator '!' not allowed when base register "
5318 "in register list");
5319 break;
5320 }
Jim Grosbach54026372011-11-10 23:17:11 +00005321 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5322 // so only issue a diagnostic for thumb1. The instructions will be
5323 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005324 case ARM::tPOP: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005325 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005326 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5327 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005328 return Error(Operands[2]->getStartLoc(),
5329 "registers must be in range r0-r7 or pc");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005330 break;
5331 }
5332 case ARM::tPUSH: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005333 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005334 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5335 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005336 return Error(Operands[2]->getStartLoc(),
5337 "registers must be in range r0-r7 or lr");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005338 break;
5339 }
Jim Grosbach1e84f192011-08-23 18:15:37 +00005340 case ARM::tSTMIA_UPD: {
5341 bool listContainsBase;
Jim Grosbach8213c962011-09-16 20:50:13 +00005342 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach1e84f192011-08-23 18:15:37 +00005343 return Error(Operands[4]->getStartLoc(),
5344 "registers must be in range r0-r7");
5345 break;
5346 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00005347 case ARM::tADDrSP: {
5348 // If the non-SP source operand and the destination operand are not the
5349 // same, we need thumb2 (for the wide encoding), or we have an error.
5350 if (!isThumbTwo() &&
5351 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5352 return Error(Operands[4]->getStartLoc(),
5353 "source register must be the same as destination");
5354 }
5355 break;
5356 }
Jim Grosbach189610f2011-07-26 18:25:39 +00005357 }
5358
5359 return false;
5360}
5361
Jim Grosbachd7433e22012-01-23 23:45:44 +00005362static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach84defb52011-12-02 22:34:51 +00005363 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005364 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005365 // VST1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005366 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5367 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5368 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5369 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5370 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5371 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5372 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5373 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5374 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005375
5376 // VST2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005377 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5378 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5379 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5380 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5381 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005382
Jim Grosbach7945ead2012-01-24 00:43:12 +00005383 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5384 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5385 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5386 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5387 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005388
Jim Grosbach7945ead2012-01-24 00:43:12 +00005389 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5390 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5391 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5392 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5393 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005394
Jim Grosbach4adb1822012-01-24 00:07:41 +00005395 // VST3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005396 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5397 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5398 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5399 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5400 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5401 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5402 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5403 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5404 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5405 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5406 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5407 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5408 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5409 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5410 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbach4adb1822012-01-24 00:07:41 +00005411
Jim Grosbachd7433e22012-01-23 23:45:44 +00005412 // VST3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005413 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5414 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5415 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5416 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5417 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5418 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5419 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5420 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5421 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5422 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5423 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5424 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5425 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5426 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5427 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5428 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5429 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5430 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbach539aab72012-01-24 00:58:13 +00005431
Jim Grosbach88a54de2012-01-24 18:53:13 +00005432 // VST4LN
5433 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5434 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5435 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5436 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5437 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5438 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5439 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5440 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5441 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5442 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5443 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5444 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5445 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5446 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5447 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5448
Jim Grosbach539aab72012-01-24 00:58:13 +00005449 // VST4
5450 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5451 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5452 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5453 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5454 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5455 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5456 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5457 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5458 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5459 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5460 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5461 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5462 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5463 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5464 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5465 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5466 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5467 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbach84defb52011-12-02 22:34:51 +00005468 }
5469}
5470
Jim Grosbachd7433e22012-01-23 23:45:44 +00005471static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00005472 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005473 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005474 // VLD1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005475 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5476 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5477 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5478 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5479 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5480 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5481 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5482 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5483 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005484
5485 // VLD2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005486 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5487 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5488 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5489 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5490 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5491 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5492 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5493 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5494 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5495 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5496 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5497 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5498 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5499 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5500 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbach3a678af2012-01-23 21:53:26 +00005501
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00005502 // VLD3DUP
5503 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5504 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5505 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5506 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5507 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5508 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5509 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5510 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5511 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5512 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5513 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5514 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5515 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5516 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5517 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5518 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5519 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5520 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5521
Jim Grosbach3a678af2012-01-23 21:53:26 +00005522 // VLD3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005523 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5524 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5525 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5526 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5527 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5528 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5529 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5530 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5531 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5532 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5533 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5534 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5535 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5536 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5537 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachc387fc62012-01-23 23:20:46 +00005538
5539 // VLD3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005540 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5541 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5542 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5543 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5544 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5545 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5546 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5547 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5548 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5549 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5550 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5551 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5552 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5553 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5554 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5555 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5556 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5557 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005558
Jim Grosbache983a132012-01-24 18:37:25 +00005559 // VLD4LN
5560 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5561 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5562 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5563 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5564 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5565 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5566 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5567 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5568 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5569 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5570 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5571 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5572 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5573 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5574 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5575
Jim Grosbacha57a36a2012-01-25 00:01:08 +00005576 // VLD4DUP
5577 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5578 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5579 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5580 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5581 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5582 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5583 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5584 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5585 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5586 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5587 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5588 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5589 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5590 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5591 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5592 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5593 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5594 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5595
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005596 // VLD4
5597 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5598 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5599 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5600 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5601 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5602 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5603 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5604 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5605 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5606 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5607 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5608 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5609 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5610 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5611 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5612 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5613 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5614 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach7636bf62011-12-02 00:35:16 +00005615 }
5616}
5617
Jim Grosbach83ec8772011-11-10 23:42:14 +00005618bool ARMAsmParser::
Jim Grosbachf8fce712011-08-11 17:35:48 +00005619processInstruction(MCInst &Inst,
5620 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5621 switch (Inst.getOpcode()) {
Jim Grosbach0b4c6732012-01-18 22:46:46 +00005622 // Aliases for alternate PC+imm syntax of LDR instructions.
5623 case ARM::t2LDRpcrel:
5624 Inst.setOpcode(ARM::t2LDRpci);
5625 return true;
5626 case ARM::t2LDRBpcrel:
5627 Inst.setOpcode(ARM::t2LDRBpci);
5628 return true;
5629 case ARM::t2LDRHpcrel:
5630 Inst.setOpcode(ARM::t2LDRHpci);
5631 return true;
5632 case ARM::t2LDRSBpcrel:
5633 Inst.setOpcode(ARM::t2LDRSBpci);
5634 return true;
5635 case ARM::t2LDRSHpcrel:
5636 Inst.setOpcode(ARM::t2LDRSHpci);
5637 return true;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005638 // Handle NEON VST complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005639 case ARM::VST1LNdWB_register_Asm_8:
5640 case ARM::VST1LNdWB_register_Asm_16:
5641 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005642 MCInst TmpInst;
5643 // Shuffle the operands around so the lane index operand is in the
5644 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005645 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005646 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005647 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5648 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5649 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5650 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5651 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5652 TmpInst.addOperand(Inst.getOperand(1)); // lane
5653 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5654 TmpInst.addOperand(Inst.getOperand(6));
5655 Inst = TmpInst;
5656 return true;
5657 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005658
Jim Grosbach8b31f952012-01-23 19:39:08 +00005659 case ARM::VST2LNdWB_register_Asm_8:
5660 case ARM::VST2LNdWB_register_Asm_16:
5661 case ARM::VST2LNdWB_register_Asm_32:
5662 case ARM::VST2LNqWB_register_Asm_16:
5663 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005664 MCInst TmpInst;
5665 // Shuffle the operands around so the lane index operand is in the
5666 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005667 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005668 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005669 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5670 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5671 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5672 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5673 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5675 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005676 TmpInst.addOperand(Inst.getOperand(1)); // lane
5677 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5678 TmpInst.addOperand(Inst.getOperand(6));
5679 Inst = TmpInst;
5680 return true;
5681 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005682
5683 case ARM::VST3LNdWB_register_Asm_8:
5684 case ARM::VST3LNdWB_register_Asm_16:
5685 case ARM::VST3LNdWB_register_Asm_32:
5686 case ARM::VST3LNqWB_register_Asm_16:
5687 case ARM::VST3LNqWB_register_Asm_32: {
5688 MCInst TmpInst;
5689 // Shuffle the operands around so the lane index operand is in the
5690 // right place.
5691 unsigned Spacing;
5692 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5693 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5694 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5695 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5696 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5697 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5699 Spacing));
5700 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5701 Spacing * 2));
5702 TmpInst.addOperand(Inst.getOperand(1)); // lane
5703 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5704 TmpInst.addOperand(Inst.getOperand(6));
5705 Inst = TmpInst;
5706 return true;
5707 }
5708
Jim Grosbach88a54de2012-01-24 18:53:13 +00005709 case ARM::VST4LNdWB_register_Asm_8:
5710 case ARM::VST4LNdWB_register_Asm_16:
5711 case ARM::VST4LNdWB_register_Asm_32:
5712 case ARM::VST4LNqWB_register_Asm_16:
5713 case ARM::VST4LNqWB_register_Asm_32: {
5714 MCInst TmpInst;
5715 // Shuffle the operands around so the lane index operand is in the
5716 // right place.
5717 unsigned Spacing;
5718 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5719 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5720 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5721 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5722 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5723 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5725 Spacing));
5726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5727 Spacing * 2));
5728 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5729 Spacing * 3));
5730 TmpInst.addOperand(Inst.getOperand(1)); // lane
5731 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5732 TmpInst.addOperand(Inst.getOperand(6));
5733 Inst = TmpInst;
5734 return true;
5735 }
5736
Jim Grosbach8b31f952012-01-23 19:39:08 +00005737 case ARM::VST1LNdWB_fixed_Asm_8:
5738 case ARM::VST1LNdWB_fixed_Asm_16:
5739 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005740 MCInst TmpInst;
5741 // Shuffle the operands around so the lane index operand is in the
5742 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005743 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005744 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005745 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5746 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5747 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5748 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5749 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5750 TmpInst.addOperand(Inst.getOperand(1)); // lane
5751 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5752 TmpInst.addOperand(Inst.getOperand(5));
5753 Inst = TmpInst;
5754 return true;
5755 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005756
Jim Grosbach8b31f952012-01-23 19:39:08 +00005757 case ARM::VST2LNdWB_fixed_Asm_8:
5758 case ARM::VST2LNdWB_fixed_Asm_16:
5759 case ARM::VST2LNdWB_fixed_Asm_32:
5760 case ARM::VST2LNqWB_fixed_Asm_16:
5761 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005762 MCInst TmpInst;
5763 // Shuffle the operands around so the lane index operand is in the
5764 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005765 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005766 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005767 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5768 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5769 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5770 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5771 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005772 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5773 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005774 TmpInst.addOperand(Inst.getOperand(1)); // lane
5775 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5776 TmpInst.addOperand(Inst.getOperand(5));
5777 Inst = TmpInst;
5778 return true;
5779 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005780
5781 case ARM::VST3LNdWB_fixed_Asm_8:
5782 case ARM::VST3LNdWB_fixed_Asm_16:
5783 case ARM::VST3LNdWB_fixed_Asm_32:
5784 case ARM::VST3LNqWB_fixed_Asm_16:
5785 case ARM::VST3LNqWB_fixed_Asm_32: {
5786 MCInst TmpInst;
5787 // Shuffle the operands around so the lane index operand is in the
5788 // right place.
5789 unsigned Spacing;
5790 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5791 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5792 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5793 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5794 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5795 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5796 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5797 Spacing));
5798 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5799 Spacing * 2));
5800 TmpInst.addOperand(Inst.getOperand(1)); // lane
5801 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5802 TmpInst.addOperand(Inst.getOperand(5));
5803 Inst = TmpInst;
5804 return true;
5805 }
5806
Jim Grosbach88a54de2012-01-24 18:53:13 +00005807 case ARM::VST4LNdWB_fixed_Asm_8:
5808 case ARM::VST4LNdWB_fixed_Asm_16:
5809 case ARM::VST4LNdWB_fixed_Asm_32:
5810 case ARM::VST4LNqWB_fixed_Asm_16:
5811 case ARM::VST4LNqWB_fixed_Asm_32: {
5812 MCInst TmpInst;
5813 // Shuffle the operands around so the lane index operand is in the
5814 // right place.
5815 unsigned Spacing;
5816 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5817 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5818 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5819 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5820 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5821 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5822 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5823 Spacing));
5824 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5825 Spacing * 2));
5826 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5827 Spacing * 3));
5828 TmpInst.addOperand(Inst.getOperand(1)); // lane
5829 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5830 TmpInst.addOperand(Inst.getOperand(5));
5831 Inst = TmpInst;
5832 return true;
5833 }
5834
Jim Grosbach8b31f952012-01-23 19:39:08 +00005835 case ARM::VST1LNdAsm_8:
5836 case ARM::VST1LNdAsm_16:
5837 case ARM::VST1LNdAsm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005838 MCInst TmpInst;
5839 // Shuffle the operands around so the lane index operand is in the
5840 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005841 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005842 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005843 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5844 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5845 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5846 TmpInst.addOperand(Inst.getOperand(1)); // lane
5847 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5848 TmpInst.addOperand(Inst.getOperand(5));
5849 Inst = TmpInst;
5850 return true;
5851 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005852
Jim Grosbach8b31f952012-01-23 19:39:08 +00005853 case ARM::VST2LNdAsm_8:
5854 case ARM::VST2LNdAsm_16:
5855 case ARM::VST2LNdAsm_32:
5856 case ARM::VST2LNqAsm_16:
5857 case ARM::VST2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005858 MCInst TmpInst;
5859 // Shuffle the operands around so the lane index operand is in the
5860 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005861 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005862 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005863 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5864 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5865 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005866 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5867 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005868 TmpInst.addOperand(Inst.getOperand(1)); // lane
5869 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5870 TmpInst.addOperand(Inst.getOperand(5));
5871 Inst = TmpInst;
5872 return true;
5873 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005874
5875 case ARM::VST3LNdAsm_8:
5876 case ARM::VST3LNdAsm_16:
5877 case ARM::VST3LNdAsm_32:
5878 case ARM::VST3LNqAsm_16:
5879 case ARM::VST3LNqAsm_32: {
5880 MCInst TmpInst;
5881 // Shuffle the operands around so the lane index operand is in the
5882 // right place.
5883 unsigned Spacing;
5884 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5885 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5886 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5887 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5888 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5889 Spacing));
5890 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5891 Spacing * 2));
5892 TmpInst.addOperand(Inst.getOperand(1)); // lane
5893 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5894 TmpInst.addOperand(Inst.getOperand(5));
5895 Inst = TmpInst;
5896 return true;
5897 }
5898
Jim Grosbach88a54de2012-01-24 18:53:13 +00005899 case ARM::VST4LNdAsm_8:
5900 case ARM::VST4LNdAsm_16:
5901 case ARM::VST4LNdAsm_32:
5902 case ARM::VST4LNqAsm_16:
5903 case ARM::VST4LNqAsm_32: {
5904 MCInst TmpInst;
5905 // Shuffle the operands around so the lane index operand is in the
5906 // right place.
5907 unsigned Spacing;
5908 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5909 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5910 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5911 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5912 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5913 Spacing));
5914 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5915 Spacing * 2));
5916 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5917 Spacing * 3));
5918 TmpInst.addOperand(Inst.getOperand(1)); // lane
5919 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5920 TmpInst.addOperand(Inst.getOperand(5));
5921 Inst = TmpInst;
5922 return true;
5923 }
5924
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005925 // Handle NEON VLD complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005926 case ARM::VLD1LNdWB_register_Asm_8:
5927 case ARM::VLD1LNdWB_register_Asm_16:
5928 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005929 MCInst TmpInst;
5930 // Shuffle the operands around so the lane index operand is in the
5931 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005932 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005933 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005934 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5935 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5936 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5937 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5938 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5939 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5940 TmpInst.addOperand(Inst.getOperand(1)); // lane
5941 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5942 TmpInst.addOperand(Inst.getOperand(6));
5943 Inst = TmpInst;
5944 return true;
5945 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005946
Jim Grosbach8b31f952012-01-23 19:39:08 +00005947 case ARM::VLD2LNdWB_register_Asm_8:
5948 case ARM::VLD2LNdWB_register_Asm_16:
5949 case ARM::VLD2LNdWB_register_Asm_32:
5950 case ARM::VLD2LNqWB_register_Asm_16:
5951 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005952 MCInst TmpInst;
5953 // Shuffle the operands around so the lane index operand is in the
5954 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005955 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005956 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005957 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005958 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5959 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005960 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5961 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5962 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5963 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5964 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005965 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5966 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005967 TmpInst.addOperand(Inst.getOperand(1)); // lane
5968 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5969 TmpInst.addOperand(Inst.getOperand(6));
5970 Inst = TmpInst;
5971 return true;
5972 }
5973
Jim Grosbach3a678af2012-01-23 21:53:26 +00005974 case ARM::VLD3LNdWB_register_Asm_8:
5975 case ARM::VLD3LNdWB_register_Asm_16:
5976 case ARM::VLD3LNdWB_register_Asm_32:
5977 case ARM::VLD3LNqWB_register_Asm_16:
5978 case ARM::VLD3LNqWB_register_Asm_32: {
5979 MCInst TmpInst;
5980 // Shuffle the operands around so the lane index operand is in the
5981 // right place.
5982 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005983 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005984 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5985 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5986 Spacing));
5987 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005988 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005989 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5990 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5991 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5992 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5993 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5994 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5995 Spacing));
5996 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005997 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005998 TmpInst.addOperand(Inst.getOperand(1)); // lane
5999 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6000 TmpInst.addOperand(Inst.getOperand(6));
6001 Inst = TmpInst;
6002 return true;
6003 }
6004
Jim Grosbache983a132012-01-24 18:37:25 +00006005 case ARM::VLD4LNdWB_register_Asm_8:
6006 case ARM::VLD4LNdWB_register_Asm_16:
6007 case ARM::VLD4LNdWB_register_Asm_32:
6008 case ARM::VLD4LNqWB_register_Asm_16:
6009 case ARM::VLD4LNqWB_register_Asm_32: {
6010 MCInst TmpInst;
6011 // Shuffle the operands around so the lane index operand is in the
6012 // right place.
6013 unsigned Spacing;
6014 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6015 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6017 Spacing));
6018 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6019 Spacing * 2));
6020 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6021 Spacing * 3));
6022 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)
6027 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6028 Spacing));
6029 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6030 Spacing * 2));
6031 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6032 Spacing * 3));
6033 TmpInst.addOperand(Inst.getOperand(1)); // lane
6034 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6035 TmpInst.addOperand(Inst.getOperand(6));
6036 Inst = TmpInst;
6037 return true;
6038 }
6039
Jim Grosbach8b31f952012-01-23 19:39:08 +00006040 case ARM::VLD1LNdWB_fixed_Asm_8:
6041 case ARM::VLD1LNdWB_fixed_Asm_16:
6042 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00006043 MCInst TmpInst;
6044 // Shuffle the operands around so the lane index operand is in the
6045 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006046 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006047 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00006048 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6049 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6050 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6051 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6052 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6053 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6054 TmpInst.addOperand(Inst.getOperand(1)); // lane
6055 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6056 TmpInst.addOperand(Inst.getOperand(5));
6057 Inst = TmpInst;
6058 return true;
6059 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006060
Jim Grosbach8b31f952012-01-23 19:39:08 +00006061 case ARM::VLD2LNdWB_fixed_Asm_8:
6062 case ARM::VLD2LNdWB_fixed_Asm_16:
6063 case ARM::VLD2LNdWB_fixed_Asm_32:
6064 case ARM::VLD2LNqWB_fixed_Asm_16:
6065 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006066 MCInst TmpInst;
6067 // Shuffle the operands around so the lane index operand is in the
6068 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006069 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006070 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006071 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006072 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6073 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006074 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6075 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6076 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6077 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6078 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006079 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6080 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006081 TmpInst.addOperand(Inst.getOperand(1)); // lane
6082 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6083 TmpInst.addOperand(Inst.getOperand(5));
6084 Inst = TmpInst;
6085 return true;
6086 }
6087
Jim Grosbach3a678af2012-01-23 21:53:26 +00006088 case ARM::VLD3LNdWB_fixed_Asm_8:
6089 case ARM::VLD3LNdWB_fixed_Asm_16:
6090 case ARM::VLD3LNdWB_fixed_Asm_32:
6091 case ARM::VLD3LNqWB_fixed_Asm_16:
6092 case ARM::VLD3LNqWB_fixed_Asm_32: {
6093 MCInst TmpInst;
6094 // Shuffle the operands around so the lane index operand is in the
6095 // right place.
6096 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006097 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006098 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6099 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6100 Spacing));
6101 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006102 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006103 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6104 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6105 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6106 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6107 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6108 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6109 Spacing));
6110 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006111 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006112 TmpInst.addOperand(Inst.getOperand(1)); // lane
6113 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6114 TmpInst.addOperand(Inst.getOperand(5));
6115 Inst = TmpInst;
6116 return true;
6117 }
6118
Jim Grosbache983a132012-01-24 18:37:25 +00006119 case ARM::VLD4LNdWB_fixed_Asm_8:
6120 case ARM::VLD4LNdWB_fixed_Asm_16:
6121 case ARM::VLD4LNdWB_fixed_Asm_32:
6122 case ARM::VLD4LNqWB_fixed_Asm_16:
6123 case ARM::VLD4LNqWB_fixed_Asm_32: {
6124 MCInst TmpInst;
6125 // Shuffle the operands around so the lane index operand is in the
6126 // right place.
6127 unsigned Spacing;
6128 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6129 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6130 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6131 Spacing));
6132 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6133 Spacing * 2));
6134 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6135 Spacing * 3));
6136 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)
6141 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6142 Spacing));
6143 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6144 Spacing * 2));
6145 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6146 Spacing * 3));
6147 TmpInst.addOperand(Inst.getOperand(1)); // lane
6148 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6149 TmpInst.addOperand(Inst.getOperand(5));
6150 Inst = TmpInst;
6151 return true;
6152 }
6153
Jim Grosbach8b31f952012-01-23 19:39:08 +00006154 case ARM::VLD1LNdAsm_8:
6155 case ARM::VLD1LNdAsm_16:
6156 case ARM::VLD1LNdAsm_32: {
Jim Grosbach7636bf62011-12-02 00:35:16 +00006157 MCInst TmpInst;
6158 // Shuffle the operands around so the lane index operand is in the
6159 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006160 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006161 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach7636bf62011-12-02 00:35:16 +00006162 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6163 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6164 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6165 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6166 TmpInst.addOperand(Inst.getOperand(1)); // lane
6167 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6168 TmpInst.addOperand(Inst.getOperand(5));
6169 Inst = TmpInst;
6170 return true;
6171 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006172
Jim Grosbach8b31f952012-01-23 19:39:08 +00006173 case ARM::VLD2LNdAsm_8:
6174 case ARM::VLD2LNdAsm_16:
6175 case ARM::VLD2LNdAsm_32:
6176 case ARM::VLD2LNqAsm_16:
6177 case ARM::VLD2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006178 MCInst TmpInst;
6179 // Shuffle the operands around so the lane index operand is in the
6180 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006181 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006182 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006183 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006184 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6185 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006186 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6187 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6188 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6190 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006191 TmpInst.addOperand(Inst.getOperand(1)); // lane
6192 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6193 TmpInst.addOperand(Inst.getOperand(5));
6194 Inst = TmpInst;
6195 return true;
6196 }
Jim Grosbach3a678af2012-01-23 21:53:26 +00006197
6198 case ARM::VLD3LNdAsm_8:
6199 case ARM::VLD3LNdAsm_16:
6200 case ARM::VLD3LNdAsm_32:
6201 case ARM::VLD3LNqAsm_16:
6202 case ARM::VLD3LNqAsm_32: {
6203 MCInst TmpInst;
6204 // Shuffle the operands around so the lane index operand is in the
6205 // right place.
6206 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006207 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006208 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6209 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6210 Spacing));
6211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006212 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006213 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6214 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6215 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6216 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6217 Spacing));
6218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006219 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006220 TmpInst.addOperand(Inst.getOperand(1)); // lane
6221 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6222 TmpInst.addOperand(Inst.getOperand(5));
6223 Inst = TmpInst;
6224 return true;
6225 }
6226
Jim Grosbache983a132012-01-24 18:37:25 +00006227 case ARM::VLD4LNdAsm_8:
6228 case ARM::VLD4LNdAsm_16:
6229 case ARM::VLD4LNdAsm_32:
6230 case ARM::VLD4LNqAsm_16:
6231 case ARM::VLD4LNqAsm_32: {
6232 MCInst TmpInst;
6233 // Shuffle the operands around so the lane index operand is in the
6234 // right place.
6235 unsigned Spacing;
6236 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6237 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6238 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6239 Spacing));
6240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6241 Spacing * 2));
6242 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6243 Spacing * 3));
6244 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6245 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6246 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6248 Spacing));
6249 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6250 Spacing * 2));
6251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6252 Spacing * 3));
6253 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 }
6259
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00006260 // VLD3DUP single 3-element structure to all lanes instructions.
6261 case ARM::VLD3DUPdAsm_8:
6262 case ARM::VLD3DUPdAsm_16:
6263 case ARM::VLD3DUPdAsm_32:
6264 case ARM::VLD3DUPqAsm_8:
6265 case ARM::VLD3DUPqAsm_16:
6266 case ARM::VLD3DUPqAsm_32: {
6267 MCInst TmpInst;
6268 unsigned Spacing;
6269 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6270 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() +
6274 Spacing * 2));
6275 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6276 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6277 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6278 TmpInst.addOperand(Inst.getOperand(4));
6279 Inst = TmpInst;
6280 return true;
6281 }
6282
6283 case ARM::VLD3DUPdWB_fixed_Asm_8:
6284 case ARM::VLD3DUPdWB_fixed_Asm_16:
6285 case ARM::VLD3DUPdWB_fixed_Asm_32:
6286 case ARM::VLD3DUPqWB_fixed_Asm_8:
6287 case ARM::VLD3DUPqWB_fixed_Asm_16:
6288 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6289 MCInst TmpInst;
6290 unsigned Spacing;
6291 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6292 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6293 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6294 Spacing));
6295 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6296 Spacing * 2));
6297 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6298 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6299 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6300 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6301 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6302 TmpInst.addOperand(Inst.getOperand(4));
6303 Inst = TmpInst;
6304 return true;
6305 }
6306
6307 case ARM::VLD3DUPdWB_register_Asm_8:
6308 case ARM::VLD3DUPdWB_register_Asm_16:
6309 case ARM::VLD3DUPdWB_register_Asm_32:
6310 case ARM::VLD3DUPqWB_register_Asm_8:
6311 case ARM::VLD3DUPqWB_register_Asm_16:
6312 case ARM::VLD3DUPqWB_register_Asm_32: {
6313 MCInst TmpInst;
6314 unsigned Spacing;
6315 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6316 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6317 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6318 Spacing));
6319 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6320 Spacing * 2));
6321 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6322 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6323 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6324 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6325 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6326 TmpInst.addOperand(Inst.getOperand(5));
6327 Inst = TmpInst;
6328 return true;
6329 }
6330
Jim Grosbachc387fc62012-01-23 23:20:46 +00006331 // VLD3 multiple 3-element structure instructions.
6332 case ARM::VLD3dAsm_8:
6333 case ARM::VLD3dAsm_16:
6334 case ARM::VLD3dAsm_32:
6335 case ARM::VLD3qAsm_8:
6336 case ARM::VLD3qAsm_16:
6337 case ARM::VLD3qAsm_32: {
6338 MCInst TmpInst;
6339 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006340 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006341 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6342 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6343 Spacing));
6344 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6345 Spacing * 2));
6346 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6347 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6348 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6349 TmpInst.addOperand(Inst.getOperand(4));
6350 Inst = TmpInst;
6351 return true;
6352 }
6353
6354 case ARM::VLD3dWB_fixed_Asm_8:
6355 case ARM::VLD3dWB_fixed_Asm_16:
6356 case ARM::VLD3dWB_fixed_Asm_32:
6357 case ARM::VLD3qWB_fixed_Asm_8:
6358 case ARM::VLD3qWB_fixed_Asm_16:
6359 case ARM::VLD3qWB_fixed_Asm_32: {
6360 MCInst TmpInst;
6361 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006362 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006363 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6365 Spacing));
6366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6367 Spacing * 2));
6368 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6369 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6370 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6371 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6372 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6373 TmpInst.addOperand(Inst.getOperand(4));
6374 Inst = TmpInst;
6375 return true;
6376 }
6377
6378 case ARM::VLD3dWB_register_Asm_8:
6379 case ARM::VLD3dWB_register_Asm_16:
6380 case ARM::VLD3dWB_register_Asm_32:
6381 case ARM::VLD3qWB_register_Asm_8:
6382 case ARM::VLD3qWB_register_Asm_16:
6383 case ARM::VLD3qWB_register_Asm_32: {
6384 MCInst TmpInst;
6385 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006386 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006387 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6388 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6389 Spacing));
6390 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6391 Spacing * 2));
6392 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6393 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6394 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6395 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6396 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6397 TmpInst.addOperand(Inst.getOperand(5));
6398 Inst = TmpInst;
6399 return true;
6400 }
6401
Jim Grosbacha57a36a2012-01-25 00:01:08 +00006402 // VLD4DUP single 3-element structure to all lanes instructions.
6403 case ARM::VLD4DUPdAsm_8:
6404 case ARM::VLD4DUPdAsm_16:
6405 case ARM::VLD4DUPdAsm_32:
6406 case ARM::VLD4DUPqAsm_8:
6407 case ARM::VLD4DUPqAsm_16:
6408 case ARM::VLD4DUPqAsm_32: {
6409 MCInst TmpInst;
6410 unsigned Spacing;
6411 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6412 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6413 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6414 Spacing));
6415 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6416 Spacing * 2));
6417 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6418 Spacing * 3));
6419 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6420 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6421 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6422 TmpInst.addOperand(Inst.getOperand(4));
6423 Inst = TmpInst;
6424 return true;
6425 }
6426
6427 case ARM::VLD4DUPdWB_fixed_Asm_8:
6428 case ARM::VLD4DUPdWB_fixed_Asm_16:
6429 case ARM::VLD4DUPdWB_fixed_Asm_32:
6430 case ARM::VLD4DUPqWB_fixed_Asm_8:
6431 case ARM::VLD4DUPqWB_fixed_Asm_16:
6432 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6433 MCInst TmpInst;
6434 unsigned Spacing;
6435 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6436 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6437 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6438 Spacing));
6439 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6440 Spacing * 2));
6441 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6442 Spacing * 3));
6443 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6444 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6445 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6446 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6447 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6448 TmpInst.addOperand(Inst.getOperand(4));
6449 Inst = TmpInst;
6450 return true;
6451 }
6452
6453 case ARM::VLD4DUPdWB_register_Asm_8:
6454 case ARM::VLD4DUPdWB_register_Asm_16:
6455 case ARM::VLD4DUPdWB_register_Asm_32:
6456 case ARM::VLD4DUPqWB_register_Asm_8:
6457 case ARM::VLD4DUPqWB_register_Asm_16:
6458 case ARM::VLD4DUPqWB_register_Asm_32: {
6459 MCInst TmpInst;
6460 unsigned Spacing;
6461 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6462 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6463 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6464 Spacing));
6465 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6466 Spacing * 2));
6467 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6468 Spacing * 3));
6469 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6470 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6471 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6472 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6473 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6474 TmpInst.addOperand(Inst.getOperand(5));
6475 Inst = TmpInst;
6476 return true;
6477 }
6478
6479 // VLD4 multiple 4-element structure instructions.
Jim Grosbach8abe7e32012-01-24 00:43:17 +00006480 case ARM::VLD4dAsm_8:
6481 case ARM::VLD4dAsm_16:
6482 case ARM::VLD4dAsm_32:
6483 case ARM::VLD4qAsm_8:
6484 case ARM::VLD4qAsm_16:
6485 case ARM::VLD4qAsm_32: {
6486 MCInst TmpInst;
6487 unsigned Spacing;
6488 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6489 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6490 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6491 Spacing));
6492 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6493 Spacing * 2));
6494 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6495 Spacing * 3));
6496 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6497 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6498 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6499 TmpInst.addOperand(Inst.getOperand(4));
6500 Inst = TmpInst;
6501 return true;
6502 }
6503
6504 case ARM::VLD4dWB_fixed_Asm_8:
6505 case ARM::VLD4dWB_fixed_Asm_16:
6506 case ARM::VLD4dWB_fixed_Asm_32:
6507 case ARM::VLD4qWB_fixed_Asm_8:
6508 case ARM::VLD4qWB_fixed_Asm_16:
6509 case ARM::VLD4qWB_fixed_Asm_32: {
6510 MCInst TmpInst;
6511 unsigned Spacing;
6512 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6513 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6514 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6515 Spacing));
6516 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6517 Spacing * 2));
6518 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6519 Spacing * 3));
6520 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6521 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6522 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6523 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6524 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6525 TmpInst.addOperand(Inst.getOperand(4));
6526 Inst = TmpInst;
6527 return true;
6528 }
6529
6530 case ARM::VLD4dWB_register_Asm_8:
6531 case ARM::VLD4dWB_register_Asm_16:
6532 case ARM::VLD4dWB_register_Asm_32:
6533 case ARM::VLD4qWB_register_Asm_8:
6534 case ARM::VLD4qWB_register_Asm_16:
6535 case ARM::VLD4qWB_register_Asm_32: {
6536 MCInst TmpInst;
6537 unsigned Spacing;
6538 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6539 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6540 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6541 Spacing));
6542 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6543 Spacing * 2));
6544 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6545 Spacing * 3));
6546 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6547 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6548 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6549 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6550 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6551 TmpInst.addOperand(Inst.getOperand(5));
6552 Inst = TmpInst;
6553 return true;
6554 }
6555
Jim Grosbachd7433e22012-01-23 23:45:44 +00006556 // VST3 multiple 3-element structure instructions.
6557 case ARM::VST3dAsm_8:
6558 case ARM::VST3dAsm_16:
6559 case ARM::VST3dAsm_32:
6560 case ARM::VST3qAsm_8:
6561 case ARM::VST3qAsm_16:
6562 case ARM::VST3qAsm_32: {
6563 MCInst TmpInst;
6564 unsigned Spacing;
6565 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6566 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6567 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6568 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6569 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6570 Spacing));
6571 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6572 Spacing * 2));
6573 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6574 TmpInst.addOperand(Inst.getOperand(4));
6575 Inst = TmpInst;
6576 return true;
6577 }
6578
6579 case ARM::VST3dWB_fixed_Asm_8:
6580 case ARM::VST3dWB_fixed_Asm_16:
6581 case ARM::VST3dWB_fixed_Asm_32:
6582 case ARM::VST3qWB_fixed_Asm_8:
6583 case ARM::VST3qWB_fixed_Asm_16:
6584 case ARM::VST3qWB_fixed_Asm_32: {
6585 MCInst TmpInst;
6586 unsigned Spacing;
6587 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6588 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6589 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6590 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6591 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6592 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6593 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6594 Spacing));
6595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6596 Spacing * 2));
6597 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6598 TmpInst.addOperand(Inst.getOperand(4));
6599 Inst = TmpInst;
6600 return true;
6601 }
6602
6603 case ARM::VST3dWB_register_Asm_8:
6604 case ARM::VST3dWB_register_Asm_16:
6605 case ARM::VST3dWB_register_Asm_32:
6606 case ARM::VST3qWB_register_Asm_8:
6607 case ARM::VST3qWB_register_Asm_16:
6608 case ARM::VST3qWB_register_Asm_32: {
6609 MCInst TmpInst;
6610 unsigned Spacing;
6611 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6612 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6613 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6614 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6615 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6616 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6617 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6618 Spacing));
6619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6620 Spacing * 2));
6621 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6622 TmpInst.addOperand(Inst.getOperand(5));
6623 Inst = TmpInst;
6624 return true;
6625 }
6626
Jim Grosbach539aab72012-01-24 00:58:13 +00006627 // VST4 multiple 3-element structure instructions.
6628 case ARM::VST4dAsm_8:
6629 case ARM::VST4dAsm_16:
6630 case ARM::VST4dAsm_32:
6631 case ARM::VST4qAsm_8:
6632 case ARM::VST4qAsm_16:
6633 case ARM::VST4qAsm_32: {
6634 MCInst TmpInst;
6635 unsigned Spacing;
6636 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6637 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6638 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6639 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6640 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6641 Spacing));
6642 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6643 Spacing * 2));
6644 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6645 Spacing * 3));
6646 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6647 TmpInst.addOperand(Inst.getOperand(4));
6648 Inst = TmpInst;
6649 return true;
6650 }
6651
6652 case ARM::VST4dWB_fixed_Asm_8:
6653 case ARM::VST4dWB_fixed_Asm_16:
6654 case ARM::VST4dWB_fixed_Asm_32:
6655 case ARM::VST4qWB_fixed_Asm_8:
6656 case ARM::VST4qWB_fixed_Asm_16:
6657 case ARM::VST4qWB_fixed_Asm_32: {
6658 MCInst TmpInst;
6659 unsigned Spacing;
6660 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6661 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6662 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6663 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6664 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6665 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6666 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6667 Spacing));
6668 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6669 Spacing * 2));
6670 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6671 Spacing * 3));
6672 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6673 TmpInst.addOperand(Inst.getOperand(4));
6674 Inst = TmpInst;
6675 return true;
6676 }
6677
6678 case ARM::VST4dWB_register_Asm_8:
6679 case ARM::VST4dWB_register_Asm_16:
6680 case ARM::VST4dWB_register_Asm_32:
6681 case ARM::VST4qWB_register_Asm_8:
6682 case ARM::VST4qWB_register_Asm_16:
6683 case ARM::VST4qWB_register_Asm_32: {
6684 MCInst TmpInst;
6685 unsigned Spacing;
6686 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6687 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6688 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6689 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6690 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6691 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6692 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6693 Spacing));
6694 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6695 Spacing * 2));
6696 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6697 Spacing * 3));
6698 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6699 TmpInst.addOperand(Inst.getOperand(5));
6700 Inst = TmpInst;
6701 return true;
6702 }
6703
Jim Grosbacha5378eb2012-04-11 00:15:16 +00006704 // Handle encoding choice for the shift-immediate instructions.
6705 case ARM::t2LSLri:
6706 case ARM::t2LSRri:
6707 case ARM::t2ASRri: {
6708 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6709 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6710 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6711 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6712 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6713 unsigned NewOpc;
6714 switch (Inst.getOpcode()) {
6715 default: llvm_unreachable("unexpected opcode");
6716 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6717 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6718 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6719 }
6720 // The Thumb1 operands aren't in the same order. Awesome, eh?
6721 MCInst TmpInst;
6722 TmpInst.setOpcode(NewOpc);
6723 TmpInst.addOperand(Inst.getOperand(0));
6724 TmpInst.addOperand(Inst.getOperand(5));
6725 TmpInst.addOperand(Inst.getOperand(1));
6726 TmpInst.addOperand(Inst.getOperand(2));
6727 TmpInst.addOperand(Inst.getOperand(3));
6728 TmpInst.addOperand(Inst.getOperand(4));
6729 Inst = TmpInst;
6730 return true;
6731 }
6732 return false;
6733 }
6734
Jim Grosbach863d2af2011-12-13 22:45:11 +00006735 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00006736 case ARM::t2MOVsr:
6737 case ARM::t2MOVSsr: {
6738 // Which instruction to expand to depends on the CCOut operand and
6739 // whether we're in an IT block if the register operands are low
6740 // registers.
6741 bool isNarrow = false;
6742 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6743 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6744 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6745 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6746 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6747 isNarrow = true;
6748 MCInst TmpInst;
6749 unsigned newOpc;
6750 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6751 default: llvm_unreachable("unexpected opcode!");
6752 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6753 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6754 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6755 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6756 }
6757 TmpInst.setOpcode(newOpc);
6758 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6759 if (isNarrow)
6760 TmpInst.addOperand(MCOperand::CreateReg(
6761 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6762 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6763 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6764 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6765 TmpInst.addOperand(Inst.getOperand(5));
6766 if (!isNarrow)
6767 TmpInst.addOperand(MCOperand::CreateReg(
6768 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6769 Inst = TmpInst;
6770 return true;
6771 }
Jim Grosbach863d2af2011-12-13 22:45:11 +00006772 case ARM::t2MOVsi:
6773 case ARM::t2MOVSsi: {
6774 // Which instruction to expand to depends on the CCOut operand and
6775 // whether we're in an IT block if the register operands are low
6776 // registers.
6777 bool isNarrow = false;
6778 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6779 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6780 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6781 isNarrow = true;
6782 MCInst TmpInst;
6783 unsigned newOpc;
6784 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6785 default: llvm_unreachable("unexpected opcode!");
6786 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6787 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6788 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6789 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach520dc782011-12-21 21:04:19 +00006790 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006791 }
6792 unsigned Ammount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6793 if (Ammount == 32) Ammount = 0;
6794 TmpInst.setOpcode(newOpc);
6795 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6796 if (isNarrow)
6797 TmpInst.addOperand(MCOperand::CreateReg(
6798 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6799 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach520dc782011-12-21 21:04:19 +00006800 if (newOpc != ARM::t2RRX)
6801 TmpInst.addOperand(MCOperand::CreateImm(Ammount));
Jim Grosbach863d2af2011-12-13 22:45:11 +00006802 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6803 TmpInst.addOperand(Inst.getOperand(4));
6804 if (!isNarrow)
6805 TmpInst.addOperand(MCOperand::CreateReg(
6806 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6807 Inst = TmpInst;
6808 return true;
6809 }
6810 // Handle the ARM mode MOV complex aliases.
Jim Grosbach23f22072011-11-16 18:31:45 +00006811 case ARM::ASRr:
6812 case ARM::LSRr:
6813 case ARM::LSLr:
6814 case ARM::RORr: {
6815 ARM_AM::ShiftOpc ShiftTy;
6816 switch(Inst.getOpcode()) {
6817 default: llvm_unreachable("unexpected opcode!");
6818 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6819 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6820 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6821 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6822 }
Jim Grosbach23f22072011-11-16 18:31:45 +00006823 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6824 MCInst TmpInst;
6825 TmpInst.setOpcode(ARM::MOVsr);
6826 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6827 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6828 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6829 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6830 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6831 TmpInst.addOperand(Inst.getOperand(4));
6832 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6833 Inst = TmpInst;
6834 return true;
6835 }
Jim Grosbachee10ff82011-11-10 19:18:01 +00006836 case ARM::ASRi:
6837 case ARM::LSRi:
6838 case ARM::LSLi:
6839 case ARM::RORi: {
6840 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006841 switch(Inst.getOpcode()) {
6842 default: llvm_unreachable("unexpected opcode!");
6843 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6844 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6845 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6846 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6847 }
6848 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach48b368b2011-11-16 19:05:59 +00006849 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachee10ff82011-11-10 19:18:01 +00006850 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonb56e4112012-04-25 18:00:18 +00006851 // A shift by 32 should be encoded as 0 when permitted
6852 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6853 Amt = 0;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006854 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006855 MCInst TmpInst;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006856 TmpInst.setOpcode(Opc);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006857 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6858 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachee10ff82011-11-10 19:18:01 +00006859 if (Opc == ARM::MOVsi)
6860 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach71810ab2011-11-10 16:44:55 +00006861 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6862 TmpInst.addOperand(Inst.getOperand(4));
6863 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6864 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006865 return true;
Jim Grosbach71810ab2011-11-10 16:44:55 +00006866 }
Jim Grosbach48b368b2011-11-16 19:05:59 +00006867 case ARM::RRXi: {
6868 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6869 MCInst TmpInst;
6870 TmpInst.setOpcode(ARM::MOVsi);
6871 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6872 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6873 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6874 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6875 TmpInst.addOperand(Inst.getOperand(3));
6876 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6877 Inst = TmpInst;
6878 return true;
6879 }
Jim Grosbach0352b462011-11-10 23:58:34 +00006880 case ARM::t2LDMIA_UPD: {
6881 // If this is a load of a single register, then we should use
6882 // a post-indexed LDR instruction instead, per the ARM ARM.
6883 if (Inst.getNumOperands() != 5)
6884 return false;
6885 MCInst TmpInst;
6886 TmpInst.setOpcode(ARM::t2LDR_POST);
6887 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6888 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6889 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6890 TmpInst.addOperand(MCOperand::CreateImm(4));
6891 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6892 TmpInst.addOperand(Inst.getOperand(3));
6893 Inst = TmpInst;
6894 return true;
6895 }
6896 case ARM::t2STMDB_UPD: {
6897 // If this is a store of a single register, then we should use
6898 // a pre-indexed STR instruction instead, per the ARM ARM.
6899 if (Inst.getNumOperands() != 5)
6900 return false;
6901 MCInst TmpInst;
6902 TmpInst.setOpcode(ARM::t2STR_PRE);
6903 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6904 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6905 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6906 TmpInst.addOperand(MCOperand::CreateImm(-4));
6907 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6908 TmpInst.addOperand(Inst.getOperand(3));
6909 Inst = TmpInst;
6910 return true;
6911 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00006912 case ARM::LDMIA_UPD:
6913 // If this is a load of a single register via a 'pop', then we should use
6914 // a post-indexed LDR instruction instead, per the ARM ARM.
6915 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6916 Inst.getNumOperands() == 5) {
6917 MCInst TmpInst;
6918 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6919 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6920 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6921 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6922 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6923 TmpInst.addOperand(MCOperand::CreateImm(4));
6924 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6925 TmpInst.addOperand(Inst.getOperand(3));
6926 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006927 return true;
Jim Grosbachf8fce712011-08-11 17:35:48 +00006928 }
6929 break;
Jim Grosbachf6713912011-08-11 18:07:11 +00006930 case ARM::STMDB_UPD:
6931 // If this is a store of a single register via a 'push', then we should use
6932 // a pre-indexed STR instruction instead, per the ARM ARM.
6933 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6934 Inst.getNumOperands() == 5) {
6935 MCInst TmpInst;
6936 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6937 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6938 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6939 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6940 TmpInst.addOperand(MCOperand::CreateImm(-4));
6941 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6942 TmpInst.addOperand(Inst.getOperand(3));
6943 Inst = TmpInst;
6944 }
6945 break;
Jim Grosbachda847862011-12-05 21:06:26 +00006946 case ARM::t2ADDri12:
6947 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6948 // mnemonic was used (not "addw"), encoding T3 is preferred.
6949 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6950 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6951 break;
6952 Inst.setOpcode(ARM::t2ADDri);
6953 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6954 break;
6955 case ARM::t2SUBri12:
6956 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6957 // mnemonic was used (not "subw"), encoding T3 is preferred.
6958 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6959 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6960 break;
6961 Inst.setOpcode(ARM::t2SUBri);
6962 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6963 break;
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006964 case ARM::tADDi8:
Jim Grosbach0f3abd82011-08-31 17:07:33 +00006965 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6966 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6967 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6968 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00006969 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006970 Inst.setOpcode(ARM::tADDi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006971 return true;
6972 }
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006973 break;
Jim Grosbachf67e8552011-09-16 22:58:42 +00006974 case ARM::tSUBi8:
6975 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6976 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6977 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6978 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00006979 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachf67e8552011-09-16 22:58:42 +00006980 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006981 return true;
6982 }
Jim Grosbachf67e8552011-09-16 22:58:42 +00006983 break;
Jim Grosbach2d30d942012-03-30 17:20:40 +00006984 case ARM::t2ADDri:
6985 case ARM::t2SUBri: {
6986 // If the destination and first source operand are the same, and
6987 // the flags are compatible with the current IT status, use encoding T2
6988 // instead of T3. For compatibility with the system 'as'. Make sure the
6989 // wide encoding wasn't explicit.
6990 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach8f1148b2012-03-30 18:39:43 +00006991 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbach2d30d942012-03-30 17:20:40 +00006992 (unsigned)Inst.getOperand(2).getImm() > 255 ||
6993 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
6994 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
6995 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6996 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
6997 break;
6998 MCInst TmpInst;
6999 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7000 ARM::tADDi8 : ARM::tSUBi8);
7001 TmpInst.addOperand(Inst.getOperand(0));
7002 TmpInst.addOperand(Inst.getOperand(5));
7003 TmpInst.addOperand(Inst.getOperand(0));
7004 TmpInst.addOperand(Inst.getOperand(2));
7005 TmpInst.addOperand(Inst.getOperand(3));
7006 TmpInst.addOperand(Inst.getOperand(4));
7007 Inst = TmpInst;
7008 return true;
7009 }
Jim Grosbach927b9df2011-12-05 22:16:39 +00007010 case ARM::t2ADDrr: {
7011 // If the destination and first source operand are the same, and
7012 // there's no setting of the flags, use encoding T2 instead of T3.
7013 // Note that this is only for ADD, not SUB. This mirrors the system
7014 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7015 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7016 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbach713c7022011-12-05 22:27:04 +00007017 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7018 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbach927b9df2011-12-05 22:16:39 +00007019 break;
7020 MCInst TmpInst;
7021 TmpInst.setOpcode(ARM::tADDhirr);
7022 TmpInst.addOperand(Inst.getOperand(0));
7023 TmpInst.addOperand(Inst.getOperand(0));
7024 TmpInst.addOperand(Inst.getOperand(2));
7025 TmpInst.addOperand(Inst.getOperand(3));
7026 TmpInst.addOperand(Inst.getOperand(4));
7027 Inst = TmpInst;
7028 return true;
7029 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00007030 case ARM::tADDrSP: {
7031 // If the non-SP source operand and the destination operand are not the
7032 // same, we need to use the 32-bit encoding if it's available.
7033 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7034 Inst.setOpcode(ARM::t2ADDrr);
7035 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7036 return true;
7037 }
7038 break;
7039 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007040 case ARM::tB:
7041 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007042 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007043 Inst.setOpcode(ARM::tBcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007044 return true;
7045 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007046 break;
7047 case ARM::t2B:
7048 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007049 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007050 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007051 return true;
7052 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007053 break;
Jim Grosbachc0755102011-08-31 21:17:31 +00007054 case ARM::t2Bcc:
Jim Grosbacha1109882011-09-02 23:22:08 +00007055 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007056 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbachc0755102011-08-31 21:17:31 +00007057 Inst.setOpcode(ARM::t2B);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007058 return true;
7059 }
Jim Grosbachc0755102011-08-31 21:17:31 +00007060 break;
Jim Grosbach395b4532011-08-17 22:57:40 +00007061 case ARM::tBcc:
7062 // If the conditional is AL, we really want tB.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007063 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbach395b4532011-08-17 22:57:40 +00007064 Inst.setOpcode(ARM::tB);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007065 return true;
7066 }
Jim Grosbach3ce23d32011-08-18 16:08:39 +00007067 break;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007068 case ARM::tLDMIA: {
7069 // If the register list contains any high registers, or if the writeback
7070 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7071 // instead if we're in Thumb2. Otherwise, this should have generated
7072 // an error in validateInstruction().
7073 unsigned Rn = Inst.getOperand(0).getReg();
7074 bool hasWritebackToken =
7075 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7076 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7077 bool listContainsBase;
7078 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7079 (!listContainsBase && !hasWritebackToken) ||
7080 (listContainsBase && hasWritebackToken)) {
7081 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7082 assert (isThumbTwo());
7083 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7084 // If we're switching to the updating version, we need to insert
7085 // the writeback tied operand.
7086 if (hasWritebackToken)
7087 Inst.insert(Inst.begin(),
7088 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007089 return true;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007090 }
7091 break;
7092 }
Jim Grosbach8213c962011-09-16 20:50:13 +00007093 case ARM::tSTMIA_UPD: {
7094 // If the register list contains any high registers, we need to use
7095 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7096 // should have generated an error in validateInstruction().
7097 unsigned Rn = Inst.getOperand(0).getReg();
7098 bool listContainsBase;
7099 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7100 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7101 assert (isThumbTwo());
7102 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007103 return true;
Jim Grosbach8213c962011-09-16 20:50:13 +00007104 }
7105 break;
7106 }
Jim Grosbach54026372011-11-10 23:17:11 +00007107 case ARM::tPOP: {
7108 bool listContainsBase;
7109 // If the register list contains any high registers, we need to use
7110 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7111 // should have generated an error in validateInstruction().
7112 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007113 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007114 assert (isThumbTwo());
7115 Inst.setOpcode(ARM::t2LDMIA_UPD);
7116 // Add the base register and writeback operands.
7117 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7118 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007119 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007120 }
7121 case ARM::tPUSH: {
7122 bool listContainsBase;
7123 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007124 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007125 assert (isThumbTwo());
7126 Inst.setOpcode(ARM::t2STMDB_UPD);
7127 // Add the base register and writeback operands.
7128 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7129 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007130 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007131 }
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007132 case ARM::t2MOVi: {
7133 // If we can use the 16-bit encoding and the user didn't explicitly
7134 // request the 32-bit variant, transform it here.
7135 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbachc0164f82012-03-30 16:31:31 +00007136 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbachc2d31642011-09-14 19:12:11 +00007137 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7138 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7139 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007140 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7141 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7142 // The operands aren't in the same order for tMOVi8...
7143 MCInst TmpInst;
7144 TmpInst.setOpcode(ARM::tMOVi8);
7145 TmpInst.addOperand(Inst.getOperand(0));
7146 TmpInst.addOperand(Inst.getOperand(4));
7147 TmpInst.addOperand(Inst.getOperand(1));
7148 TmpInst.addOperand(Inst.getOperand(2));
7149 TmpInst.addOperand(Inst.getOperand(3));
7150 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007151 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007152 }
7153 break;
7154 }
7155 case ARM::t2MOVr: {
7156 // If we can use the 16-bit encoding and the user didn't explicitly
7157 // request the 32-bit variant, transform it here.
7158 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7159 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7160 Inst.getOperand(2).getImm() == ARMCC::AL &&
7161 Inst.getOperand(4).getReg() == ARM::CPSR &&
7162 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7163 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7164 // The operands aren't the same for tMOV[S]r... (no cc_out)
7165 MCInst TmpInst;
7166 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7167 TmpInst.addOperand(Inst.getOperand(0));
7168 TmpInst.addOperand(Inst.getOperand(1));
7169 TmpInst.addOperand(Inst.getOperand(2));
7170 TmpInst.addOperand(Inst.getOperand(3));
7171 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007172 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007173 }
7174 break;
7175 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007176 case ARM::t2SXTH:
Jim Grosbach50f1c372011-09-20 00:46:54 +00007177 case ARM::t2SXTB:
7178 case ARM::t2UXTH:
7179 case ARM::t2UXTB: {
Jim Grosbach326efe52011-09-19 20:29:33 +00007180 // If we can use the 16-bit encoding and the user didn't explicitly
7181 // request the 32-bit variant, transform it here.
7182 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7183 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7184 Inst.getOperand(2).getImm() == 0 &&
7185 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7186 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbach50f1c372011-09-20 00:46:54 +00007187 unsigned NewOpc;
7188 switch (Inst.getOpcode()) {
7189 default: llvm_unreachable("Illegal opcode!");
7190 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7191 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7192 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7193 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7194 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007195 // The operands aren't the same for thumb1 (no rotate operand).
7196 MCInst TmpInst;
7197 TmpInst.setOpcode(NewOpc);
7198 TmpInst.addOperand(Inst.getOperand(0));
7199 TmpInst.addOperand(Inst.getOperand(1));
7200 TmpInst.addOperand(Inst.getOperand(3));
7201 TmpInst.addOperand(Inst.getOperand(4));
7202 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007203 return true;
Jim Grosbach326efe52011-09-19 20:29:33 +00007204 }
7205 break;
7206 }
Jim Grosbach04b5d932011-12-20 00:59:38 +00007207 case ARM::MOVsi: {
7208 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonb56e4112012-04-25 18:00:18 +00007209 // rrx shifts and asr/lsr of #32 is encoded as 0
7210 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7211 return false;
Jim Grosbach04b5d932011-12-20 00:59:38 +00007212 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7213 // Shifting by zero is accepted as a vanilla 'MOVr'
7214 MCInst TmpInst;
7215 TmpInst.setOpcode(ARM::MOVr);
7216 TmpInst.addOperand(Inst.getOperand(0));
7217 TmpInst.addOperand(Inst.getOperand(1));
7218 TmpInst.addOperand(Inst.getOperand(3));
7219 TmpInst.addOperand(Inst.getOperand(4));
7220 TmpInst.addOperand(Inst.getOperand(5));
7221 Inst = TmpInst;
7222 return true;
7223 }
7224 return false;
7225 }
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007226 case ARM::ANDrsi:
7227 case ARM::ORRrsi:
7228 case ARM::EORrsi:
7229 case ARM::BICrsi:
7230 case ARM::SUBrsi:
7231 case ARM::ADDrsi: {
7232 unsigned newOpc;
7233 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7234 if (SOpc == ARM_AM::rrx) return false;
7235 switch (Inst.getOpcode()) {
Craig Topperbc219812012-02-07 02:50:20 +00007236 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007237 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7238 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7239 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7240 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7241 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7242 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7243 }
7244 // If the shift is by zero, use the non-shifted instruction definition.
7245 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0) {
7246 MCInst TmpInst;
7247 TmpInst.setOpcode(newOpc);
7248 TmpInst.addOperand(Inst.getOperand(0));
7249 TmpInst.addOperand(Inst.getOperand(1));
7250 TmpInst.addOperand(Inst.getOperand(2));
7251 TmpInst.addOperand(Inst.getOperand(4));
7252 TmpInst.addOperand(Inst.getOperand(5));
7253 TmpInst.addOperand(Inst.getOperand(6));
7254 Inst = TmpInst;
7255 return true;
7256 }
7257 return false;
7258 }
Jim Grosbach74423e32012-01-25 19:52:01 +00007259 case ARM::ITasm:
Jim Grosbach89df9962011-08-26 21:43:41 +00007260 case ARM::t2IT: {
7261 // The mask bits for all but the first condition are represented as
7262 // the low bit of the condition code value implies 't'. We currently
7263 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Barton4d2f0772012-04-27 08:42:59 +00007264 // of the condition code is zero.
Jim Grosbach89df9962011-08-26 21:43:41 +00007265 MCOperand &MO = Inst.getOperand(1);
7266 unsigned Mask = MO.getImm();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007267 unsigned OrigMask = Mask;
7268 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach89df9962011-08-26 21:43:41 +00007269 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach89df9962011-08-26 21:43:41 +00007270 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7271 for (unsigned i = 3; i != TZ; --i)
7272 Mask ^= 1 << i;
Richard Barton4d2f0772012-04-27 08:42:59 +00007273 }
Jim Grosbach89df9962011-08-26 21:43:41 +00007274 MO.setImm(Mask);
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007275
7276 // Set up the IT block state according to the IT instruction we just
7277 // matched.
7278 assert(!inITBlock() && "nested IT blocks?!");
7279 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7280 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7281 ITState.CurPosition = 0;
7282 ITState.FirstCond = true;
Jim Grosbach89df9962011-08-26 21:43:41 +00007283 break;
7284 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00007285 }
Jim Grosbach83ec8772011-11-10 23:42:14 +00007286 return false;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007287}
7288
Jim Grosbach47a0d522011-08-16 20:45:50 +00007289unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7290 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7291 // suffix depending on whether they're in an IT block or not.
Jim Grosbach194bd892011-08-16 22:20:01 +00007292 unsigned Opc = Inst.getOpcode();
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00007293 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach47a0d522011-08-16 20:45:50 +00007294 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7295 assert(MCID.hasOptionalDef() &&
7296 "optionally flag setting instruction missing optional def operand");
7297 assert(MCID.NumOperands == Inst.getNumOperands() &&
7298 "operand count mismatch!");
7299 // Find the optional-def operand (cc_out).
7300 unsigned OpNo;
7301 for (OpNo = 0;
7302 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7303 ++OpNo)
7304 ;
7305 // If we're parsing Thumb1, reject it completely.
7306 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7307 return Match_MnemonicFail;
7308 // If we're parsing Thumb2, which form is legal depends on whether we're
7309 // in an IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007310 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7311 !inITBlock())
Jim Grosbach47a0d522011-08-16 20:45:50 +00007312 return Match_RequiresITBlock;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007313 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7314 inITBlock())
7315 return Match_RequiresNotITBlock;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007316 }
Jim Grosbach194bd892011-08-16 22:20:01 +00007317 // Some high-register supporting Thumb1 encodings only allow both registers
7318 // to be from r0-r7 when in Thumb2.
7319 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7320 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7321 isARMLowRegister(Inst.getOperand(2).getReg()))
7322 return Match_RequiresThumb2;
7323 // Others only require ARMv6 or later.
Jim Grosbach4ec6e882011-08-19 20:46:54 +00007324 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbach194bd892011-08-16 22:20:01 +00007325 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7326 isARMLowRegister(Inst.getOperand(1).getReg()))
7327 return Match_RequiresV6;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007328 return Match_Success;
7329}
7330
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007331static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007332bool ARMAsmParser::
7333MatchAndEmitInstruction(SMLoc IDLoc,
7334 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7335 MCStreamer &Out) {
7336 MCInst Inst;
7337 unsigned ErrorInfo;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007338 unsigned MatchResult;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007339 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007340 switch (MatchResult) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007341 default: break;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007342 case Match_Success:
Jim Grosbach189610f2011-07-26 18:25:39 +00007343 // Context sensitive operand constraints aren't handled by the matcher,
7344 // so check them here.
Jim Grosbacha1109882011-09-02 23:22:08 +00007345 if (validateInstruction(Inst, Operands)) {
7346 // Still progress the IT block, otherwise one wrong condition causes
7347 // nasty cascading errors.
7348 forwardITPosition();
Jim Grosbach189610f2011-07-26 18:25:39 +00007349 return true;
Jim Grosbacha1109882011-09-02 23:22:08 +00007350 }
Jim Grosbach189610f2011-07-26 18:25:39 +00007351
Jim Grosbachf8fce712011-08-11 17:35:48 +00007352 // Some instructions need post-processing to, for example, tweak which
Jim Grosbach83ec8772011-11-10 23:42:14 +00007353 // encoding is selected. Loop on it while changes happen so the
7354 // individual transformations can chain off each other. E.g.,
7355 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7356 while (processInstruction(Inst, Operands))
7357 ;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007358
Jim Grosbacha1109882011-09-02 23:22:08 +00007359 // Only move forward at the very end so that everything in validate
7360 // and process gets a consistent answer about whether we're in an IT
7361 // block.
7362 forwardITPosition();
7363
Jim Grosbach74423e32012-01-25 19:52:01 +00007364 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7365 // doesn't actually encode.
7366 if (Inst.getOpcode() == ARM::ITasm)
7367 return false;
7368
Jim Grosbach42e6bd32012-01-26 23:20:15 +00007369 Inst.setLoc(IDLoc);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007370 Out.EmitInstruction(Inst);
7371 return false;
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007372 case Match_MissingFeature: {
7373 assert(ErrorInfo && "Unknown missing feature!");
7374 // Special case the error message for the very common case where only
7375 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7376 std::string Msg = "instruction requires:";
7377 unsigned Mask = 1;
7378 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7379 if (ErrorInfo & Mask) {
7380 Msg += " ";
7381 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7382 }
7383 Mask <<= 1;
7384 }
7385 return Error(IDLoc, Msg);
7386 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007387 case Match_InvalidOperand: {
7388 SMLoc ErrorLoc = IDLoc;
7389 if (ErrorInfo != ~0U) {
7390 if (ErrorInfo >= Operands.size())
7391 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00007392
Chris Lattnere73d4f82010-10-28 21:41:58 +00007393 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7394 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7395 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007396
Chris Lattnere73d4f82010-10-28 21:41:58 +00007397 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007398 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007399 case Match_MnemonicFail:
Benjamin Kramer362a05a2012-04-15 17:04:27 +00007400 return Error(IDLoc, "invalid instruction",
7401 ((ARMOperand*)Operands[0])->getLocRange());
Daniel Dunbarb4129152011-02-04 17:12:23 +00007402 case Match_ConversionFail:
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00007403 // The converter function will have already emited a diagnostic.
7404 return true;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007405 case Match_RequiresNotITBlock:
7406 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach47a0d522011-08-16 20:45:50 +00007407 case Match_RequiresITBlock:
7408 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbach194bd892011-08-16 22:20:01 +00007409 case Match_RequiresV6:
7410 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7411 case Match_RequiresThumb2:
7412 return Error(IDLoc, "instruction variant requires Thumb2");
Chris Lattnere73d4f82010-10-28 21:41:58 +00007413 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007414
Eric Christopherc223e2b2010-10-29 09:26:59 +00007415 llvm_unreachable("Implement any new match types added!");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007416}
7417
Jim Grosbach1355cf12011-07-26 17:10:22 +00007418/// parseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007419bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7420 StringRef IDVal = DirectiveID.getIdentifier();
7421 if (IDVal == ".word")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007422 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007423 else if (IDVal == ".thumb")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007424 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach9a70df92011-12-07 18:04:19 +00007425 else if (IDVal == ".arm")
7426 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007427 else if (IDVal == ".thumb_func")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007428 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007429 else if (IDVal == ".code")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007430 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007431 else if (IDVal == ".syntax")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007432 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbacha39cda72011-12-14 02:16:11 +00007433 else if (IDVal == ".unreq")
7434 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kimd7c9e082011-12-20 17:38:12 +00007435 else if (IDVal == ".arch")
7436 return parseDirectiveArch(DirectiveID.getLoc());
7437 else if (IDVal == ".eabi_attribute")
7438 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007439 return true;
7440}
7441
Jim Grosbach1355cf12011-07-26 17:10:22 +00007442/// parseDirectiveWord
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007443/// ::= .word [ expression (, expression)* ]
Jim Grosbach1355cf12011-07-26 17:10:22 +00007444bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007445 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7446 for (;;) {
7447 const MCExpr *Value;
7448 if (getParser().ParseExpression(Value))
7449 return true;
7450
Chris Lattneraaec2052010-01-19 19:46:13 +00007451 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007452
7453 if (getLexer().is(AsmToken::EndOfStatement))
7454 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00007455
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007456 // FIXME: Improve diagnostic.
7457 if (getLexer().isNot(AsmToken::Comma))
7458 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007459 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007460 }
7461 }
7462
Sean Callananb9a25b72010-01-19 20:27:46 +00007463 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007464 return false;
7465}
7466
Jim Grosbach1355cf12011-07-26 17:10:22 +00007467/// parseDirectiveThumb
Kevin Enderby515d5092009-10-15 20:48:48 +00007468/// ::= .thumb
Jim Grosbach1355cf12011-07-26 17:10:22 +00007469bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby515d5092009-10-15 20:48:48 +00007470 if (getLexer().isNot(AsmToken::EndOfStatement))
7471 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007472 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007473
Jim Grosbach9a70df92011-12-07 18:04:19 +00007474 if (!isThumb())
7475 SwitchMode();
7476 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7477 return false;
7478}
7479
7480/// parseDirectiveARM
7481/// ::= .arm
7482bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7483 if (getLexer().isNot(AsmToken::EndOfStatement))
7484 return Error(L, "unexpected token in directive");
7485 Parser.Lex();
7486
7487 if (isThumb())
7488 SwitchMode();
7489 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby515d5092009-10-15 20:48:48 +00007490 return false;
7491}
7492
Jim Grosbach1355cf12011-07-26 17:10:22 +00007493/// parseDirectiveThumbFunc
Kevin Enderby515d5092009-10-15 20:48:48 +00007494/// ::= .thumbfunc symbol_name
Jim Grosbach1355cf12011-07-26 17:10:22 +00007495bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00007496 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7497 bool isMachO = MAI.hasSubsectionsViaSymbols();
7498 StringRef Name;
Jim Grosbachde4d8392011-12-21 22:30:16 +00007499 bool needFuncName = true;
Rafael Espindola64695402011-05-16 16:17:21 +00007500
Jim Grosbachde4d8392011-12-21 22:30:16 +00007501 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindola64695402011-05-16 16:17:21 +00007502 // ELF doesn't
7503 if (isMachO) {
7504 const AsmToken &Tok = Parser.getTok();
Jim Grosbachde4d8392011-12-21 22:30:16 +00007505 if (Tok.isNot(AsmToken::EndOfStatement)) {
7506 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7507 return Error(L, "unexpected token in .thumb_func directive");
7508 Name = Tok.getIdentifier();
7509 Parser.Lex(); // Consume the identifier token.
7510 needFuncName = false;
7511 }
Rafael Espindola64695402011-05-16 16:17:21 +00007512 }
7513
Jim Grosbachde4d8392011-12-21 22:30:16 +00007514 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby515d5092009-10-15 20:48:48 +00007515 return Error(L, "unexpected token in directive");
Jim Grosbachde4d8392011-12-21 22:30:16 +00007516
7517 // Eat the end of statement and any blank lines that follow.
7518 while (getLexer().is(AsmToken::EndOfStatement))
7519 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007520
Rafael Espindola64695402011-05-16 16:17:21 +00007521 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbachde4d8392011-12-21 22:30:16 +00007522 // We really should be checking the next symbol definition even if there's
7523 // stuff in between.
7524 if (needFuncName) {
Jim Grosbachd475f862011-11-10 20:48:53 +00007525 Name = Parser.getTok().getIdentifier();
Rafael Espindola64695402011-05-16 16:17:21 +00007526 }
7527
Jim Grosbach642fc9c2010-11-05 22:33:53 +00007528 // Mark symbol as a thumb symbol.
7529 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7530 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00007531 return false;
7532}
7533
Jim Grosbach1355cf12011-07-26 17:10:22 +00007534/// parseDirectiveSyntax
Kevin Enderby515d5092009-10-15 20:48:48 +00007535/// ::= .syntax unified | divided
Jim Grosbach1355cf12011-07-26 17:10:22 +00007536bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007537 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007538 if (Tok.isNot(AsmToken::Identifier))
7539 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00007540 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00007541 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00007542 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007543 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00007544 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00007545 else
7546 return Error(L, "unrecognized syntax mode in .syntax directive");
7547
7548 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007549 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007550 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007551
7552 // TODO tell the MC streamer the mode
7553 // getParser().getStreamer().Emit???();
7554 return false;
7555}
7556
Jim Grosbach1355cf12011-07-26 17:10:22 +00007557/// parseDirectiveCode
Kevin Enderby515d5092009-10-15 20:48:48 +00007558/// ::= .code 16 | 32
Jim Grosbach1355cf12011-07-26 17:10:22 +00007559bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007560 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007561 if (Tok.isNot(AsmToken::Integer))
7562 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00007563 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00007564 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00007565 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007566 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00007567 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007568 else
7569 return Error(L, "invalid operand to .code directive");
7570
7571 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007572 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007573 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007574
Evan Cheng32869202011-07-08 22:36:29 +00007575 if (Val == 16) {
Jim Grosbach98447da2011-09-06 18:46:23 +00007576 if (!isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007577 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007578 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng32869202011-07-08 22:36:29 +00007579 } else {
Jim Grosbach98447da2011-09-06 18:46:23 +00007580 if (isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007581 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007582 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Chengeb0caa12011-07-08 22:49:55 +00007583 }
Jim Grosbach2a301702010-11-05 22:40:53 +00007584
Kevin Enderby515d5092009-10-15 20:48:48 +00007585 return false;
7586}
7587
Jim Grosbacha39cda72011-12-14 02:16:11 +00007588/// parseDirectiveReq
7589/// ::= name .req registername
7590bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7591 Parser.Lex(); // Eat the '.req' token.
7592 unsigned Reg;
7593 SMLoc SRegLoc, ERegLoc;
7594 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7595 Parser.EatToEndOfStatement();
7596 return Error(SRegLoc, "register name expected");
7597 }
7598
7599 // Shouldn't be anything else.
7600 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7601 Parser.EatToEndOfStatement();
7602 return Error(Parser.getTok().getLoc(),
7603 "unexpected input in .req directive.");
7604 }
7605
7606 Parser.Lex(); // Consume the EndOfStatement
7607
7608 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7609 return Error(SRegLoc, "redefinition of '" + Name +
7610 "' does not match original.");
7611
7612 return false;
7613}
7614
7615/// parseDirectiveUneq
7616/// ::= .unreq registername
7617bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7618 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7619 Parser.EatToEndOfStatement();
7620 return Error(L, "unexpected input in .unreq directive.");
7621 }
7622 RegisterReqs.erase(Parser.getTok().getIdentifier());
7623 Parser.Lex(); // Eat the identifier.
7624 return false;
7625}
7626
Jason W Kimd7c9e082011-12-20 17:38:12 +00007627/// parseDirectiveArch
7628/// ::= .arch token
7629bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7630 return true;
7631}
7632
7633/// parseDirectiveEabiAttr
7634/// ::= .eabi_attribute int, int
7635bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7636 return true;
7637}
7638
Sean Callanan90b70972010-04-07 20:29:34 +00007639extern "C" void LLVMInitializeARMAsmLexer();
7640
Kevin Enderby9c41fa82009-10-30 22:55:57 +00007641/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007642extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng94b95502011-07-26 00:24:13 +00007643 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7644 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00007645 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007646}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007647
Chris Lattner0692ee62010-09-06 19:11:01 +00007648#define GET_REGISTER_MATCHER
Craig Topper8030e1a2012-04-25 06:56:34 +00007649#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner0692ee62010-09-06 19:11:01 +00007650#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007651#include "ARMGenAsmMatcher.inc"