blob: 94604c948337259a7ccf88cbab1c6221e5e8e933 [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;
47
Jim Grosbacha39cda72011-12-14 02:16:11 +000048 // Map of register aliases registers via the .req directive.
49 StringMap<unsigned> RegisterReqs;
50
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +000051 struct {
52 ARMCC::CondCodes Cond; // Condition for IT block.
53 unsigned Mask:4; // Condition mask for instructions.
54 // Starting at first 1 (from lsb).
55 // '1' condition as indicated in IT.
56 // '0' inverse of condition (else).
57 // Count of instructions in IT block is
58 // 4 - trailingzeroes(mask)
59
60 bool FirstCond; // Explicit flag for when we're parsing the
61 // First instruction in the IT block. It's
62 // implied in the mask, so needs special
63 // handling.
64
65 unsigned CurPosition; // Current position in parsing of IT
66 // block. In range [0,3]. Initialized
67 // according to count of instructions in block.
68 // ~0U if no active IT block.
69 } ITState;
70 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha1109882011-09-02 23:22:08 +000071 void forwardITPosition() {
72 if (!inITBlock()) return;
73 // Move to the next instruction in the IT block, if there is one. If not,
74 // mark the block as done.
75 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
76 if (++ITState.CurPosition == 5 - TZ)
77 ITState.CurPosition = ~0U; // Done with the IT block after this.
78 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +000079
80
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000081 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000082 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
83
84 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000085 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
86
Jim Grosbach1355cf12011-07-26 17:10:22 +000087 int tryParseRegister();
88 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d87ec22011-07-26 20:41:24 +000089 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +000090 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7ce05792011-08-03 23:50:40 +000091 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +000092 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
93 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbach7ce05792011-08-03 23:50:40 +000094 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
95 unsigned &ShiftAmount);
Jim Grosbach1355cf12011-07-26 17:10:22 +000096 bool parseDirectiveWord(unsigned Size, SMLoc L);
97 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach9a70df92011-12-07 18:04:19 +000098 bool parseDirectiveARM(SMLoc L);
Jim Grosbach1355cf12011-07-26 17:10:22 +000099 bool parseDirectiveThumbFunc(SMLoc L);
100 bool parseDirectiveCode(SMLoc L);
101 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbacha39cda72011-12-14 02:16:11 +0000102 bool parseDirectiveReq(StringRef Name, SMLoc L);
103 bool parseDirectiveUnreq(SMLoc L);
Jason W Kimd7c9e082011-12-20 17:38:12 +0000104 bool parseDirectiveArch(SMLoc L);
105 bool parseDirectiveEabiAttr(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +0000106
Jim Grosbach1355cf12011-07-26 17:10:22 +0000107 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach89df9962011-08-26 21:43:41 +0000108 bool &CarrySetting, unsigned &ProcessorIMod,
109 StringRef &ITMask);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000110 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +0000111 bool &CanAcceptPredicationCode);
Jim Grosbach16c74252010-10-29 14:46:02 +0000112
Evan Chengebdeeab2011-07-08 01:53:10 +0000113 bool isThumb() const {
114 // FIXME: Can tablegen auto-generate this?
Evan Chengffc0e732011-07-09 05:47:46 +0000115 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Chengebdeeab2011-07-08 01:53:10 +0000116 }
Evan Chengebdeeab2011-07-08 01:53:10 +0000117 bool isThumbOne() const {
Evan Chengffc0e732011-07-09 05:47:46 +0000118 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Chengebdeeab2011-07-08 01:53:10 +0000119 }
Jim Grosbach47a0d522011-08-16 20:45:50 +0000120 bool isThumbTwo() const {
121 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
122 }
Jim Grosbach194bd892011-08-16 22:20:01 +0000123 bool hasV6Ops() const {
124 return STI.getFeatureBits() & ARM::HasV6Ops;
125 }
James Molloyacad68d2011-09-28 14:21:38 +0000126 bool hasV7Ops() const {
127 return STI.getFeatureBits() & ARM::HasV7Ops;
128 }
Evan Cheng32869202011-07-08 22:36:29 +0000129 void SwitchMode() {
Evan Chengffc0e732011-07-09 05:47:46 +0000130 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
131 setAvailableFeatures(FB);
Evan Cheng32869202011-07-08 22:36:29 +0000132 }
James Molloyacad68d2011-09-28 14:21:38 +0000133 bool isMClass() const {
134 return STI.getFeatureBits() & ARM::FeatureMClass;
135 }
Evan Chengebdeeab2011-07-08 01:53:10 +0000136
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000137 /// @name Auto-generated Match Functions
138 /// {
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000139
Chris Lattner0692ee62010-09-06 19:11:01 +0000140#define GET_ASSEMBLER_HEADER
141#include "ARMGenAsmMatcher.inc"
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000142
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000143 /// }
144
Jim Grosbach89df9962011-08-26 21:43:41 +0000145 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000146 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbachf922c472011-02-12 01:34:40 +0000147 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000148 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbachf922c472011-02-12 01:34:40 +0000149 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000150 OperandMatchResultTy parseCoprocOptionOperand(
151 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000152 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000153 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000154 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000155 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000156 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000157 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachf6c05252011-07-21 17:23:04 +0000158 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
159 StringRef Op, int Low, int High);
160 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
161 return parsePKHImm(O, "lsl", 0, 31);
162 }
163 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
164 return parsePKHImm(O, "asr", 1, 32);
165 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000166 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach580f4a92011-07-25 22:20:28 +0000167 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000168 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000169 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000170 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach251bf252011-08-10 21:56:18 +0000171 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach9d390362011-10-03 23:38:36 +0000172 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach862019c2011-10-18 23:02:30 +0000173 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7636bf62011-12-02 00:35:16 +0000174 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000175
176 // Asm Match Converter Methods
Jim Grosbacha77295d2011-09-08 22:07:06 +0000177 bool cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
178 const SmallVectorImpl<MCParsedAsmOperand*> &);
179 bool cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
180 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheeec0252011-09-08 00:39:19 +0000181 bool cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
182 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachee2c2a42011-09-16 21:55:56 +0000183 bool cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
184 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000185 bool cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000186 const SmallVectorImpl<MCParsedAsmOperand*> &);
Owen Anderson9ab0f252011-08-26 20:43:14 +0000187 bool cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
188 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach548340c2011-08-11 19:22:40 +0000189 bool cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
190 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000191 bool cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000192 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7b8f46c2011-08-11 21:17:22 +0000193 bool cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
194 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000195 bool cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
196 const SmallVectorImpl<MCParsedAsmOperand*> &);
197 bool cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
198 const SmallVectorImpl<MCParsedAsmOperand*> &);
199 bool cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
200 const SmallVectorImpl<MCParsedAsmOperand*> &);
201 bool cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
202 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000203 bool cvtLdrdPre(MCInst &Inst, unsigned Opcode,
204 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach14605d12011-08-11 20:28:23 +0000205 bool cvtStrdPre(MCInst &Inst, unsigned Opcode,
206 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach623a4542011-08-10 22:42:16 +0000207 bool cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
208 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach88ae2bc2011-08-19 22:07:46 +0000209 bool cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
210 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach12431322011-10-24 22:16:58 +0000211 bool cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
212 const SmallVectorImpl<MCParsedAsmOperand*> &);
213 bool cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
214 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach4334e032011-10-31 21:50:31 +0000215 bool cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
216 const SmallVectorImpl<MCParsedAsmOperand*> &);
217 bool cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
218 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach189610f2011-07-26 18:25:39 +0000219
220 bool validateInstruction(MCInst &Inst,
221 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach83ec8772011-11-10 23:42:14 +0000222 bool processInstruction(MCInst &Inst,
Jim Grosbachf8fce712011-08-11 17:35:48 +0000223 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachd54b4e62011-08-16 21:12:37 +0000224 bool shouldOmitCCOutOperand(StringRef Mnemonic,
225 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach189610f2011-07-26 18:25:39 +0000226
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000227public:
Jim Grosbach47a0d522011-08-16 20:45:50 +0000228 enum ARMMatchResultTy {
Jim Grosbach194bd892011-08-16 22:20:01 +0000229 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000230 Match_RequiresNotITBlock,
Jim Grosbach194bd892011-08-16 22:20:01 +0000231 Match_RequiresV6,
232 Match_RequiresThumb2
Jim Grosbach47a0d522011-08-16 20:45:50 +0000233 };
234
Evan Chengffc0e732011-07-09 05:47:46 +0000235 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Evan Cheng94b95502011-07-26 00:24:13 +0000236 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
Evan Chengebdeeab2011-07-08 01:53:10 +0000237 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng32869202011-07-08 22:36:29 +0000238
Evan Chengebdeeab2011-07-08 01:53:10 +0000239 // Initialize the set of available features.
Evan Chengffc0e732011-07-09 05:47:46 +0000240 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000241
242 // Not in an ITBlock to start with.
243 ITState.CurPosition = ~0U;
Evan Chengebdeeab2011-07-08 01:53:10 +0000244 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000245
Jim Grosbach1355cf12011-07-26 17:10:22 +0000246 // Implementation of the MCTargetAsmParser interface:
247 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
248 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Jim Grosbach189610f2011-07-26 18:25:39 +0000249 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000250 bool ParseDirective(AsmToken DirectiveID);
251
Jim Grosbach47a0d522011-08-16 20:45:50 +0000252 unsigned checkTargetMatchPredicate(MCInst &Inst);
253
Jim Grosbach1355cf12011-07-26 17:10:22 +0000254 bool MatchAndEmitInstruction(SMLoc IDLoc,
255 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
256 MCStreamer &Out);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000257};
Jim Grosbach16c74252010-10-29 14:46:02 +0000258} // end anonymous namespace
259
Chris Lattner3a697562010-10-28 17:20:03 +0000260namespace {
261
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000262/// ARMOperand - Instances of this class represent a parsed ARM machine
263/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000264class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000265 enum KindTy {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000266 k_CondCode,
267 k_CCOut,
268 k_ITCondMask,
269 k_CoprocNum,
270 k_CoprocReg,
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000271 k_CoprocOption,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000272 k_Immediate,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000273 k_MemBarrierOpt,
274 k_Memory,
275 k_PostIndexRegister,
276 k_MSRMask,
277 k_ProcIFlags,
Jim Grosbach460a9052011-10-07 23:56:00 +0000278 k_VectorIndex,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000279 k_Register,
280 k_RegisterList,
281 k_DPRRegisterList,
282 k_SPRRegisterList,
Jim Grosbach862019c2011-10-18 23:02:30 +0000283 k_VectorList,
Jim Grosbach98b05a52011-11-30 01:09:44 +0000284 k_VectorListAllLanes,
Jim Grosbach7636bf62011-12-02 00:35:16 +0000285 k_VectorListIndexed,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000286 k_ShiftedRegister,
287 k_ShiftedImmediate,
288 k_ShifterImmediate,
289 k_RotateImmediate,
290 k_BitfieldDescriptor,
291 k_Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000292 } Kind;
293
Sean Callanan76264762010-04-02 22:27:05 +0000294 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000295 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000296
297 union {
298 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000299 ARMCC::CondCodes Val;
300 } CC;
301
302 struct {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000303 unsigned Val;
304 } Cop;
305
306 struct {
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000307 unsigned Val;
308 } CoprocOption;
309
310 struct {
Jim Grosbach89df9962011-08-26 21:43:41 +0000311 unsigned Mask:4;
312 } ITMask;
313
314 struct {
315 ARM_MB::MemBOpt Val;
316 } MBOpt;
317
318 struct {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000319 ARM_PROC::IFlags Val;
320 } IFlags;
321
322 struct {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000323 unsigned Val;
324 } MMask;
325
326 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000327 const char *Data;
328 unsigned Length;
329 } Tok;
330
331 struct {
332 unsigned RegNum;
333 } Reg;
334
Jim Grosbach862019c2011-10-18 23:02:30 +0000335 // A vector register list is a sequential list of 1 to 4 registers.
336 struct {
337 unsigned RegNum;
338 unsigned Count;
Jim Grosbach7636bf62011-12-02 00:35:16 +0000339 unsigned LaneIndex;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +0000340 bool isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +0000341 } VectorList;
342
Bill Wendling8155e5b2010-11-06 22:19:43 +0000343 struct {
Jim Grosbach460a9052011-10-07 23:56:00 +0000344 unsigned Val;
345 } VectorIndex;
346
347 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000348 const MCExpr *Val;
349 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000350
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000351 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000352 struct {
353 unsigned BaseRegNum;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000354 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
355 // was specified.
356 const MCConstantExpr *OffsetImm; // Offset immediate value
357 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
358 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbach57dcb852011-10-11 17:29:55 +0000359 unsigned ShiftImm; // shift for OffsetReg.
360 unsigned Alignment; // 0 = no alignment specified
Jim Grosbacheeaf1c12011-12-19 18:31:43 +0000361 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbach7ce05792011-08-03 23:50:40 +0000362 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbache53c87b2011-10-11 15:59:20 +0000363 } Memory;
Owen Anderson00828302011-03-18 22:50:18 +0000364
365 struct {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000366 unsigned RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000367 bool isAdd;
368 ARM_AM::ShiftOpc ShiftTy;
369 unsigned ShiftImm;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000370 } PostIdxReg;
371
372 struct {
Jim Grosbach580f4a92011-07-25 22:20:28 +0000373 bool isASR;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000374 unsigned Imm;
Jim Grosbach580f4a92011-07-25 22:20:28 +0000375 } ShifterImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000376 struct {
377 ARM_AM::ShiftOpc ShiftTy;
378 unsigned SrcReg;
379 unsigned ShiftReg;
380 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000381 } RegShiftedReg;
Owen Anderson92a20222011-07-21 18:54:16 +0000382 struct {
383 ARM_AM::ShiftOpc ShiftTy;
384 unsigned SrcReg;
385 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000386 } RegShiftedImm;
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000387 struct {
388 unsigned Imm;
389 } RotImm;
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000390 struct {
391 unsigned LSB;
392 unsigned Width;
393 } Bitfield;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000394 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000395
Bill Wendling146018f2010-11-06 21:42:12 +0000396 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
397public:
Sean Callanan76264762010-04-02 22:27:05 +0000398 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
399 Kind = o.Kind;
400 StartLoc = o.StartLoc;
401 EndLoc = o.EndLoc;
402 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000403 case k_CondCode:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000404 CC = o.CC;
405 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000406 case k_ITCondMask:
Jim Grosbach89df9962011-08-26 21:43:41 +0000407 ITMask = o.ITMask;
408 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000409 case k_Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000410 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000411 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000412 case k_CCOut:
413 case k_Register:
Sean Callanan76264762010-04-02 22:27:05 +0000414 Reg = o.Reg;
415 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000416 case k_RegisterList:
417 case k_DPRRegisterList:
418 case k_SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000419 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000420 break;
Jim Grosbach862019c2011-10-18 23:02:30 +0000421 case k_VectorList:
Jim Grosbach98b05a52011-11-30 01:09:44 +0000422 case k_VectorListAllLanes:
Jim Grosbach7636bf62011-12-02 00:35:16 +0000423 case k_VectorListIndexed:
Jim Grosbach862019c2011-10-18 23:02:30 +0000424 VectorList = o.VectorList;
425 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000426 case k_CoprocNum:
427 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000428 Cop = o.Cop;
429 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000430 case k_CoprocOption:
431 CoprocOption = o.CoprocOption;
432 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000433 case k_Immediate:
Sean Callanan76264762010-04-02 22:27:05 +0000434 Imm = o.Imm;
435 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000436 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000437 MBOpt = o.MBOpt;
438 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000439 case k_Memory:
Jim Grosbache53c87b2011-10-11 15:59:20 +0000440 Memory = o.Memory;
Sean Callanan76264762010-04-02 22:27:05 +0000441 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000442 case k_PostIndexRegister:
Jim Grosbach7ce05792011-08-03 23:50:40 +0000443 PostIdxReg = o.PostIdxReg;
444 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000445 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000446 MMask = o.MMask;
447 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000448 case k_ProcIFlags:
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000449 IFlags = o.IFlags;
Owen Anderson00828302011-03-18 22:50:18 +0000450 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000451 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +0000452 ShifterImm = o.ShifterImm;
Owen Anderson00828302011-03-18 22:50:18 +0000453 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000454 case k_ShiftedRegister:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000455 RegShiftedReg = o.RegShiftedReg;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000456 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000457 case k_ShiftedImmediate:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000458 RegShiftedImm = o.RegShiftedImm;
Owen Anderson92a20222011-07-21 18:54:16 +0000459 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000460 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000461 RotImm = o.RotImm;
462 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000463 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000464 Bitfield = o.Bitfield;
465 break;
Jim Grosbach460a9052011-10-07 23:56:00 +0000466 case k_VectorIndex:
467 VectorIndex = o.VectorIndex;
468 break;
Sean Callanan76264762010-04-02 22:27:05 +0000469 }
470 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000471
Sean Callanan76264762010-04-02 22:27:05 +0000472 /// getStartLoc - Get the location of the first token of this operand.
473 SMLoc getStartLoc() const { return StartLoc; }
474 /// getEndLoc - Get the location of the last token of this operand.
475 SMLoc getEndLoc() const { return EndLoc; }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000476
Daniel Dunbar8462b302010-08-11 06:36:53 +0000477 ARMCC::CondCodes getCondCode() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000478 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000479 return CC.Val;
480 }
481
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000482 unsigned getCoproc() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000483 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000484 return Cop.Val;
485 }
486
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000487 StringRef getToken() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000488 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000489 return StringRef(Tok.Data, Tok.Length);
490 }
491
492 unsigned getReg() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000493 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000494 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000495 }
496
Bill Wendling5fa22a12010-11-09 23:28:44 +0000497 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000498 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
499 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000500 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000501 }
502
Kevin Enderbycfe07242009-10-13 22:19:02 +0000503 const MCExpr *getImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000504 assert(isImm() && "Invalid access!");
Kevin Enderbycfe07242009-10-13 22:19:02 +0000505 return Imm.Val;
506 }
507
Jim Grosbach460a9052011-10-07 23:56:00 +0000508 unsigned getVectorIndex() const {
509 assert(Kind == k_VectorIndex && "Invalid access!");
510 return VectorIndex.Val;
511 }
512
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000513 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000514 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000515 return MBOpt.Val;
516 }
517
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000518 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000519 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000520 return IFlags.Val;
521 }
522
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000523 unsigned getMSRMask() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000524 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000525 return MMask.Val;
526 }
527
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000528 bool isCoprocNum() const { return Kind == k_CoprocNum; }
529 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000530 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000531 bool isCondCode() const { return Kind == k_CondCode; }
532 bool isCCOut() const { return Kind == k_CCOut; }
533 bool isITMask() const { return Kind == k_ITCondMask; }
534 bool isITCondCode() const { return Kind == k_CondCode; }
535 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbach51222d12012-01-20 18:09:51 +0000536 bool isFPImm() const {
537 if (!isImm()) return false;
538 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
539 if (!CE) return false;
540 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
541 return Val != -1;
542 }
Jim Grosbach4050bc42011-12-22 22:19:05 +0000543 bool isFBits16() const {
544 if (!isImm()) return false;
545 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
546 if (!CE) return false;
547 int64_t Value = CE->getValue();
548 return Value >= 0 && Value <= 16;
549 }
550 bool isFBits32() const {
551 if (!isImm()) return false;
552 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
553 if (!CE) return false;
554 int64_t Value = CE->getValue();
555 return Value >= 1 && Value <= 32;
556 }
Jim Grosbacha77295d2011-09-08 22:07:06 +0000557 bool isImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000558 if (!isImm()) return false;
Jim Grosbacha77295d2011-09-08 22:07:06 +0000559 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
560 if (!CE) return false;
561 int64_t Value = CE->getValue();
562 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
563 }
Jim Grosbach72f39f82011-08-24 21:22:15 +0000564 bool isImm0_1020s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000565 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
567 if (!CE) return false;
568 int64_t Value = CE->getValue();
569 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
570 }
571 bool isImm0_508s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000572 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000573 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
574 if (!CE) return false;
575 int64_t Value = CE->getValue();
576 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
577 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000578 bool isImm0_255() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000579 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000580 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
581 if (!CE) return false;
582 int64_t Value = CE->getValue();
583 return Value >= 0 && Value < 256;
584 }
Jim Grosbach587f5062011-12-02 23:34:39 +0000585 bool isImm0_1() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000586 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
588 if (!CE) return false;
589 int64_t Value = CE->getValue();
590 return Value >= 0 && Value < 2;
591 }
592 bool isImm0_3() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000593 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000594 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
595 if (!CE) return false;
596 int64_t Value = CE->getValue();
597 return Value >= 0 && Value < 4;
598 }
Jim Grosbach83ab0702011-07-13 22:01:08 +0000599 bool isImm0_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000600 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000601 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
602 if (!CE) return false;
603 int64_t Value = CE->getValue();
604 return Value >= 0 && Value < 8;
605 }
606 bool isImm0_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000607 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000608 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
609 if (!CE) return false;
610 int64_t Value = CE->getValue();
611 return Value >= 0 && Value < 16;
612 }
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000613 bool isImm0_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000614 if (!isImm()) return false;
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000615 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
616 if (!CE) return false;
617 int64_t Value = CE->getValue();
618 return Value >= 0 && Value < 32;
619 }
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000620 bool isImm0_63() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000621 if (!isImm()) return false;
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000622 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
623 if (!CE) return false;
624 int64_t Value = CE->getValue();
625 return Value >= 0 && Value < 64;
626 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000627 bool isImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000628 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
630 if (!CE) return false;
631 int64_t Value = CE->getValue();
632 return Value == 8;
633 }
634 bool isImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000635 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000636 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
637 if (!CE) return false;
638 int64_t Value = CE->getValue();
639 return Value == 16;
640 }
641 bool isImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000642 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000643 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
644 if (!CE) return false;
645 int64_t Value = CE->getValue();
646 return Value == 32;
647 }
Jim Grosbach6b044c22011-12-08 22:06:06 +0000648 bool isShrImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000649 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000650 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
651 if (!CE) return false;
652 int64_t Value = CE->getValue();
653 return Value > 0 && Value <= 8;
654 }
655 bool isShrImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000656 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000657 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
658 if (!CE) return false;
659 int64_t Value = CE->getValue();
660 return Value > 0 && Value <= 16;
661 }
662 bool isShrImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000663 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
665 if (!CE) return false;
666 int64_t Value = CE->getValue();
667 return Value > 0 && Value <= 32;
668 }
669 bool isShrImm64() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000670 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
672 if (!CE) return false;
673 int64_t Value = CE->getValue();
674 return Value > 0 && Value <= 64;
675 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000676 bool isImm1_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000677 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
679 if (!CE) return false;
680 int64_t Value = CE->getValue();
681 return Value > 0 && Value < 8;
682 }
683 bool isImm1_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000684 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000685 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
686 if (!CE) return false;
687 int64_t Value = CE->getValue();
688 return Value > 0 && Value < 16;
689 }
690 bool isImm1_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000691 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000692 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
693 if (!CE) return false;
694 int64_t Value = CE->getValue();
695 return Value > 0 && Value < 32;
696 }
Jim Grosbachf4943352011-07-25 23:09:14 +0000697 bool isImm1_16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000698 if (!isImm()) return false;
Jim Grosbachf4943352011-07-25 23:09:14 +0000699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
700 if (!CE) return false;
701 int64_t Value = CE->getValue();
702 return Value > 0 && Value < 17;
703 }
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000704 bool isImm1_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000705 if (!isImm()) return false;
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
707 if (!CE) return false;
708 int64_t Value = CE->getValue();
709 return Value > 0 && Value < 33;
710 }
Jim Grosbachee10ff82011-11-10 19:18:01 +0000711 bool isImm0_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000712 if (!isImm()) return false;
Jim Grosbachee10ff82011-11-10 19:18:01 +0000713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
714 if (!CE) return false;
715 int64_t Value = CE->getValue();
716 return Value >= 0 && Value < 33;
717 }
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000718 bool isImm0_65535() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000719 if (!isImm()) return false;
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
721 if (!CE) return false;
722 int64_t Value = CE->getValue();
723 return Value >= 0 && Value < 65536;
724 }
Jim Grosbachffa32252011-07-19 19:13:28 +0000725 bool isImm0_65535Expr() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000726 if (!isImm()) return false;
Jim Grosbachffa32252011-07-19 19:13:28 +0000727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
728 // If it's not a constant expression, it'll generate a fixup and be
729 // handled later.
730 if (!CE) return true;
731 int64_t Value = CE->getValue();
732 return Value >= 0 && Value < 65536;
733 }
Jim Grosbached838482011-07-26 16:24:27 +0000734 bool isImm24bit() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000735 if (!isImm()) return false;
Jim Grosbached838482011-07-26 16:24:27 +0000736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
737 if (!CE) return false;
738 int64_t Value = CE->getValue();
739 return Value >= 0 && Value <= 0xffffff;
740 }
Jim Grosbach70939ee2011-08-17 21:51:27 +0000741 bool isImmThumbSR() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000742 if (!isImm()) return false;
Jim Grosbach70939ee2011-08-17 21:51:27 +0000743 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
744 if (!CE) return false;
745 int64_t Value = CE->getValue();
746 return Value > 0 && Value < 33;
747 }
Jim Grosbachf6c05252011-07-21 17:23:04 +0000748 bool isPKHLSLImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000749 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000750 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
751 if (!CE) return false;
752 int64_t Value = CE->getValue();
753 return Value >= 0 && Value < 32;
754 }
755 bool isPKHASRImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000756 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000757 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
758 if (!CE) return false;
759 int64_t Value = CE->getValue();
760 return Value > 0 && Value <= 32;
761 }
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000762 bool isARMSOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000763 if (!isImm()) return false;
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
765 if (!CE) return false;
766 int64_t Value = CE->getValue();
767 return ARM_AM::getSOImmVal(Value) != -1;
768 }
Jim Grosbache70ec842011-10-28 22:50:54 +0000769 bool isARMSOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000770 if (!isImm()) return false;
Jim Grosbache70ec842011-10-28 22:50:54 +0000771 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
772 if (!CE) return false;
773 int64_t Value = CE->getValue();
774 return ARM_AM::getSOImmVal(~Value) != -1;
775 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000776 bool isARMSOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000777 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
779 if (!CE) return false;
780 int64_t Value = CE->getValue();
781 return ARM_AM::getSOImmVal(-Value) != -1;
782 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000783 bool isT2SOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000784 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
786 if (!CE) return false;
787 int64_t Value = CE->getValue();
788 return ARM_AM::getT2SOImmVal(Value) != -1;
789 }
Jim Grosbach89a63372011-10-28 22:36:30 +0000790 bool isT2SOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000791 if (!isImm()) return false;
Jim Grosbach89a63372011-10-28 22:36:30 +0000792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
793 if (!CE) return false;
794 int64_t Value = CE->getValue();
795 return ARM_AM::getT2SOImmVal(~Value) != -1;
796 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000797 bool isT2SOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000798 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000799 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
800 if (!CE) return false;
801 int64_t Value = CE->getValue();
802 return ARM_AM::getT2SOImmVal(-Value) != -1;
803 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000804 bool isSetEndImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000805 if (!isImm()) return false;
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
807 if (!CE) return false;
808 int64_t Value = CE->getValue();
809 return Value == 1 || Value == 0;
810 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000811 bool isReg() const { return Kind == k_Register; }
812 bool isRegList() const { return Kind == k_RegisterList; }
813 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
814 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
815 bool isToken() const { return Kind == k_Token; }
816 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
817 bool isMemory() const { return Kind == k_Memory; }
818 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
819 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
820 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
821 bool isRotImm() const { return Kind == k_RotateImmediate; }
822 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
823 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000824 bool isPostIdxReg() const {
Jim Grosbach430052b2011-11-14 17:52:47 +0000825 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000826 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000827 bool isMemNoOffset(bool alignOK = false) const {
Jim Grosbachf6c35c52011-10-10 23:06:42 +0000828 if (!isMemory())
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000829 return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000830 // No offset of any kind.
Jim Grosbach57dcb852011-10-11 17:29:55 +0000831 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
832 (alignOK || Memory.Alignment == 0);
833 }
Jim Grosbach0b4c6732012-01-18 22:46:46 +0000834 bool isMemPCRelImm12() const {
835 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
836 return false;
837 // Base register must be PC.
838 if (Memory.BaseRegNum != ARM::PC)
839 return false;
840 // Immediate offset in range [-4095, 4095].
841 if (!Memory.OffsetImm) return true;
842 int64_t Val = Memory.OffsetImm->getValue();
843 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
844 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000845 bool isAlignedMemory() const {
846 return isMemNoOffset(true);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000847 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000848 bool isAddrMode2() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000849 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000850 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000851 if (Memory.OffsetRegNum) return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000852 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000853 if (!Memory.OffsetImm) return true;
854 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach7ce05792011-08-03 23:50:40 +0000855 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000856 }
Jim Grosbach039c2e12011-08-04 23:01:30 +0000857 bool isAM2OffsetImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000858 if (!isImm()) return false;
Jim Grosbach039c2e12011-08-04 23:01:30 +0000859 // Immediate offset in range [-4095, 4095].
860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
861 if (!CE) return false;
862 int64_t Val = CE->getValue();
863 return Val > -4096 && Val < 4096;
864 }
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000865 bool isAddrMode3() const {
Jim Grosbach2f196742011-12-19 23:06:24 +0000866 // If we have an immediate that's not a constant, treat it as a label
867 // reference needing a fixup. If it is a constant, it's something else
868 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000869 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +0000870 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000871 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000872 // No shifts are legal for AM3.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000873 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000874 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000875 if (Memory.OffsetRegNum) return true;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000876 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000877 if (!Memory.OffsetImm) return true;
878 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000879 return Val > -256 && Val < 256;
880 }
881 bool isAM3Offset() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000882 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000883 return false;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000884 if (Kind == k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000885 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
886 // Immediate offset in range [-255, 255].
887 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
888 if (!CE) return false;
889 int64_t Val = CE->getValue();
Jim Grosbach251bf252011-08-10 21:56:18 +0000890 // Special case, #-0 is INT32_MIN.
891 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000892 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000893 bool isAddrMode5() const {
Jim Grosbach681460f2011-11-01 01:24:45 +0000894 // If we have an immediate that's not a constant, treat it as a label
895 // reference needing a fixup. If it is a constant, it's something else
896 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000897 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach681460f2011-11-01 01:24:45 +0000898 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000899 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000900 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000901 if (Memory.OffsetRegNum) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000902 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000903 if (!Memory.OffsetImm) return true;
904 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +0000905 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbach681460f2011-11-01 01:24:45 +0000906 Val == INT32_MIN;
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000907 }
Jim Grosbach7f739be2011-09-19 22:21:13 +0000908 bool isMemTBB() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000909 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000910 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach7f739be2011-09-19 22:21:13 +0000911 return false;
912 return true;
913 }
914 bool isMemTBH() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000915 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000916 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
917 Memory.Alignment != 0 )
Jim Grosbach7f739be2011-09-19 22:21:13 +0000918 return false;
919 return true;
920 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000921 bool isMemRegOffset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000922 if (!isMemory() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendlingf4caf692010-12-14 03:36:38 +0000923 return false;
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000924 return true;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000925 }
Jim Grosbachab899c12011-09-07 23:10:15 +0000926 bool isT2MemRegOffset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000927 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
928 Memory.Alignment != 0)
Jim Grosbachab899c12011-09-07 23:10:15 +0000929 return false;
930 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000931 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbachab899c12011-09-07 23:10:15 +0000932 return true;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000933 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbachab899c12011-09-07 23:10:15 +0000934 return false;
935 return true;
936 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000937 bool isMemThumbRR() const {
938 // Thumb reg+reg addressing is simple. Just two registers, a base and
939 // an offset. No shifts, negations or any other complicating factors.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000940 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000941 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000942 return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000943 return isARMLowRegister(Memory.BaseRegNum) &&
944 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +0000945 }
946 bool isMemThumbRIs4() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000947 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000948 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach60f91a32011-08-19 17:55:24 +0000949 return false;
950 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000951 if (!Memory.OffsetImm) return true;
952 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +0000953 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
954 }
Jim Grosbach38466302011-08-19 18:55:51 +0000955 bool isMemThumbRIs2() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000956 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000957 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach38466302011-08-19 18:55:51 +0000958 return false;
959 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000960 if (!Memory.OffsetImm) return true;
961 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach38466302011-08-19 18:55:51 +0000962 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
963 }
Jim Grosbach48ff5ff2011-08-19 18:49:59 +0000964 bool isMemThumbRIs1() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000965 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000966 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach48ff5ff2011-08-19 18:49:59 +0000967 return false;
968 // Immediate offset in range [0, 31].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000969 if (!Memory.OffsetImm) return true;
970 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach48ff5ff2011-08-19 18:49:59 +0000971 return Val >= 0 && Val <= 31;
972 }
Jim Grosbachecd85892011-08-19 18:13:48 +0000973 bool isMemThumbSPI() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000974 if (!isMemory() || Memory.OffsetRegNum != 0 ||
975 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbachecd85892011-08-19 18:13:48 +0000976 return false;
977 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000978 if (!Memory.OffsetImm) return true;
979 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +0000980 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000981 }
Jim Grosbacha77295d2011-09-08 22:07:06 +0000982 bool isMemImm8s4Offset() const {
Jim Grosbach2f196742011-12-19 23:06:24 +0000983 // If we have an immediate that's not a constant, treat it as a label
984 // reference needing a fixup. If it is a constant, it's something else
985 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000986 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +0000987 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000988 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha77295d2011-09-08 22:07:06 +0000989 return false;
990 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000991 if (!Memory.OffsetImm) return true;
992 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha77295d2011-09-08 22:07:06 +0000993 return Val >= -1020 && Val <= 1020 && (Val & 3) == 0;
994 }
Jim Grosbachb6aed502011-09-09 18:37:27 +0000995 bool isMemImm0_1020s4Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000996 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachb6aed502011-09-09 18:37:27 +0000997 return false;
998 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000999 if (!Memory.OffsetImm) return true;
1000 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachb6aed502011-09-09 18:37:27 +00001001 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1002 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001003 bool isMemImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001004 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001005 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001006 // Base reg of PC isn't allowed for these encodings.
1007 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001008 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001009 if (!Memory.OffsetImm) return true;
1010 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson4d2a0012011-09-23 22:25:02 +00001011 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001012 }
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001013 bool isMemPosImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001014 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001015 return false;
1016 // Immediate offset in range [0, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001017 if (!Memory.OffsetImm) return true;
1018 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001019 return Val >= 0 && Val < 256;
1020 }
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001021 bool isMemNegImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001022 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001023 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001024 // Base reg of PC isn't allowed for these encodings.
1025 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001026 // Immediate offset in range [-255, -1].
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001027 if (!Memory.OffsetImm) return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +00001028 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001029 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001030 }
1031 bool isMemUImm12Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001032 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001033 return false;
1034 // Immediate offset in range [0, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001035 if (!Memory.OffsetImm) return true;
1036 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001037 return (Val >= 0 && Val < 4096);
1038 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001039 bool isMemImm12Offset() const {
Jim Grosbach09176e12011-08-08 20:59:31 +00001040 // If we have an immediate that's not a constant, treat it as a label
1041 // reference needing a fixup. If it is a constant, it's something else
1042 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001043 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach09176e12011-08-08 20:59:31 +00001044 return true;
1045
Jim Grosbach57dcb852011-10-11 17:29:55 +00001046 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001047 return false;
1048 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001049 if (!Memory.OffsetImm) return true;
1050 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +00001051 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001052 }
1053 bool isPostIdxImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001054 if (!isImm()) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001055 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1056 if (!CE) return false;
1057 int64_t Val = CE->getValue();
Owen Anderson63553c72011-08-29 17:17:09 +00001058 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001059 }
Jim Grosbach2bd01182011-10-11 21:55:36 +00001060 bool isPostIdxImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001061 if (!isImm()) return false;
Jim Grosbach2bd01182011-10-11 21:55:36 +00001062 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1063 if (!CE) return false;
1064 int64_t Val = CE->getValue();
1065 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1066 (Val == INT32_MIN);
1067 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001068
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001069 bool isMSRMask() const { return Kind == k_MSRMask; }
1070 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001071
Jim Grosbach0e387b22011-10-17 22:26:03 +00001072 // NEON operands.
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001073 bool isSingleSpacedVectorList() const {
1074 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1075 }
1076 bool isDoubleSpacedVectorList() const {
1077 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1078 }
Jim Grosbach862019c2011-10-18 23:02:30 +00001079 bool isVecListOneD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001080 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach862019c2011-10-18 23:02:30 +00001081 return VectorList.Count == 1;
1082 }
1083
Jim Grosbach280dfad2011-10-21 18:54:25 +00001084 bool isVecListTwoD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001085 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach280dfad2011-10-21 18:54:25 +00001086 return VectorList.Count == 2;
1087 }
1088
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001089 bool isVecListThreeD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001090 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001091 return VectorList.Count == 3;
1092 }
1093
Jim Grosbachb6310312011-10-21 20:35:01 +00001094 bool isVecListFourD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001095 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachb6310312011-10-21 20:35:01 +00001096 return VectorList.Count == 4;
1097 }
1098
Jim Grosbach4661d4c2011-10-21 22:21:10 +00001099 bool isVecListTwoQ() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001100 if (!isDoubleSpacedVectorList()) return false;
1101 return VectorList.Count == 2;
Jim Grosbach4661d4c2011-10-21 22:21:10 +00001102 }
1103
Jim Grosbachc387fc62012-01-23 23:20:46 +00001104 bool isVecListThreeQ() const {
1105 if (!isDoubleSpacedVectorList()) return false;
1106 return VectorList.Count == 3;
1107 }
1108
Jim Grosbach7945ead2012-01-24 00:43:12 +00001109 bool isVecListFourQ() const {
1110 if (!isDoubleSpacedVectorList()) return false;
1111 return VectorList.Count == 4;
1112 }
1113
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001114 bool isSingleSpacedVectorAllLanes() const {
1115 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1116 }
1117 bool isDoubleSpacedVectorAllLanes() const {
1118 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1119 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00001120 bool isVecListOneDAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001121 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach98b05a52011-11-30 01:09:44 +00001122 return VectorList.Count == 1;
1123 }
1124
Jim Grosbach13af2222011-11-30 18:21:25 +00001125 bool isVecListTwoDAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001126 if (!isSingleSpacedVectorAllLanes()) return false;
1127 return VectorList.Count == 2;
1128 }
1129
1130 bool isVecListTwoQAllLanes() const {
1131 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach13af2222011-11-30 18:21:25 +00001132 return VectorList.Count == 2;
1133 }
1134
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001135 bool isVecListThreeDAllLanes() const {
1136 if (!isSingleSpacedVectorAllLanes()) return false;
1137 return VectorList.Count == 3;
1138 }
1139
1140 bool isVecListThreeQAllLanes() const {
1141 if (!isDoubleSpacedVectorAllLanes()) return false;
1142 return VectorList.Count == 3;
1143 }
1144
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001145 bool isVecListFourDAllLanes() const {
1146 if (!isSingleSpacedVectorAllLanes()) return false;
1147 return VectorList.Count == 4;
1148 }
1149
1150 bool isVecListFourQAllLanes() const {
1151 if (!isDoubleSpacedVectorAllLanes()) return false;
1152 return VectorList.Count == 4;
1153 }
1154
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001155 bool isSingleSpacedVectorIndexed() const {
1156 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1157 }
1158 bool isDoubleSpacedVectorIndexed() const {
1159 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1160 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00001161 bool isVecListOneDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001162 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach7636bf62011-12-02 00:35:16 +00001163 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1164 }
1165
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001166 bool isVecListOneDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001167 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001168 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1169 }
1170
1171 bool isVecListOneDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001172 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001173 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1174 }
1175
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001176 bool isVecListTwoDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001177 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001178 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1179 }
1180
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001181 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001182 if (!isSingleSpacedVectorIndexed()) return false;
1183 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1184 }
1185
1186 bool isVecListTwoQWordIndexed() const {
1187 if (!isDoubleSpacedVectorIndexed()) return false;
1188 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1189 }
1190
1191 bool isVecListTwoQHWordIndexed() const {
1192 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001193 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1194 }
1195
1196 bool isVecListTwoDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001197 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001198 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1199 }
1200
Jim Grosbach3a678af2012-01-23 21:53:26 +00001201 bool isVecListThreeDByteIndexed() const {
1202 if (!isSingleSpacedVectorIndexed()) return false;
1203 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1204 }
1205
1206 bool isVecListThreeDHWordIndexed() const {
1207 if (!isSingleSpacedVectorIndexed()) return false;
1208 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1209 }
1210
1211 bool isVecListThreeQWordIndexed() const {
1212 if (!isDoubleSpacedVectorIndexed()) return false;
1213 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1214 }
1215
1216 bool isVecListThreeQHWordIndexed() const {
1217 if (!isDoubleSpacedVectorIndexed()) return false;
1218 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1219 }
1220
1221 bool isVecListThreeDWordIndexed() const {
1222 if (!isSingleSpacedVectorIndexed()) return false;
1223 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1224 }
1225
Jim Grosbache983a132012-01-24 18:37:25 +00001226 bool isVecListFourDByteIndexed() const {
1227 if (!isSingleSpacedVectorIndexed()) return false;
1228 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1229 }
1230
1231 bool isVecListFourDHWordIndexed() const {
1232 if (!isSingleSpacedVectorIndexed()) return false;
1233 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1234 }
1235
1236 bool isVecListFourQWordIndexed() const {
1237 if (!isDoubleSpacedVectorIndexed()) return false;
1238 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1239 }
1240
1241 bool isVecListFourQHWordIndexed() const {
1242 if (!isDoubleSpacedVectorIndexed()) return false;
1243 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1244 }
1245
1246 bool isVecListFourDWordIndexed() const {
1247 if (!isSingleSpacedVectorIndexed()) return false;
1248 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1249 }
1250
Jim Grosbach460a9052011-10-07 23:56:00 +00001251 bool isVectorIndex8() const {
1252 if (Kind != k_VectorIndex) return false;
1253 return VectorIndex.Val < 8;
1254 }
1255 bool isVectorIndex16() const {
1256 if (Kind != k_VectorIndex) return false;
1257 return VectorIndex.Val < 4;
1258 }
1259 bool isVectorIndex32() const {
1260 if (Kind != k_VectorIndex) return false;
1261 return VectorIndex.Val < 2;
1262 }
1263
Jim Grosbach0e387b22011-10-17 22:26:03 +00001264 bool isNEONi8splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001265 if (!isImm()) return false;
Jim Grosbach0e387b22011-10-17 22:26:03 +00001266 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1267 // Must be a constant.
1268 if (!CE) return false;
1269 int64_t Value = CE->getValue();
1270 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1271 // value.
Jim Grosbach0e387b22011-10-17 22:26:03 +00001272 return Value >= 0 && Value < 256;
1273 }
Jim Grosbach460a9052011-10-07 23:56:00 +00001274
Jim Grosbachea461102011-10-17 23:09:09 +00001275 bool isNEONi16splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001276 if (!isImm()) return false;
Jim Grosbachea461102011-10-17 23:09:09 +00001277 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1278 // Must be a constant.
1279 if (!CE) return false;
1280 int64_t Value = CE->getValue();
1281 // i16 value in the range [0,255] or [0x0100, 0xff00]
1282 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1283 }
1284
Jim Grosbach6248a542011-10-18 00:22:00 +00001285 bool isNEONi32splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001286 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001287 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1288 // Must be a constant.
1289 if (!CE) return false;
1290 int64_t Value = CE->getValue();
1291 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1292 return (Value >= 0 && Value < 256) ||
1293 (Value >= 0x0100 && Value <= 0xff00) ||
1294 (Value >= 0x010000 && Value <= 0xff0000) ||
1295 (Value >= 0x01000000 && Value <= 0xff000000);
1296 }
1297
1298 bool isNEONi32vmov() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001299 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001300 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1301 // Must be a constant.
1302 if (!CE) return false;
1303 int64_t Value = CE->getValue();
1304 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1305 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1306 return (Value >= 0 && Value < 256) ||
1307 (Value >= 0x0100 && Value <= 0xff00) ||
1308 (Value >= 0x010000 && Value <= 0xff0000) ||
1309 (Value >= 0x01000000 && Value <= 0xff000000) ||
1310 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1311 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1312 }
Jim Grosbach9b087852011-12-19 23:51:07 +00001313 bool isNEONi32vmovNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001314 if (!isImm()) return false;
Jim Grosbach9b087852011-12-19 23:51:07 +00001315 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1316 // Must be a constant.
1317 if (!CE) return false;
1318 int64_t Value = ~CE->getValue();
1319 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1320 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1321 return (Value >= 0 && Value < 256) ||
1322 (Value >= 0x0100 && Value <= 0xff00) ||
1323 (Value >= 0x010000 && Value <= 0xff0000) ||
1324 (Value >= 0x01000000 && Value <= 0xff000000) ||
1325 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1326 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1327 }
Jim Grosbach6248a542011-10-18 00:22:00 +00001328
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001329 bool isNEONi64splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001330 if (!isImm()) return false;
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001331 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1332 // Must be a constant.
1333 if (!CE) return false;
1334 uint64_t Value = CE->getValue();
1335 // i64 value with each byte being either 0 or 0xff.
1336 for (unsigned i = 0; i < 8; ++i)
1337 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1338 return true;
1339 }
1340
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001341 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +00001342 // Add as immediates when possible. Null MCExpr = 0.
1343 if (Expr == 0)
1344 Inst.addOperand(MCOperand::CreateImm(0));
1345 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001346 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1347 else
1348 Inst.addOperand(MCOperand::CreateExpr(Expr));
1349 }
1350
Daniel Dunbar8462b302010-08-11 06:36:53 +00001351 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001352 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +00001353 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +00001354 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1355 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +00001356 }
1357
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001358 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1359 assert(N == 1 && "Invalid number of operands!");
1360 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1361 }
1362
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00001363 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1364 assert(N == 1 && "Invalid number of operands!");
1365 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1366 }
1367
1368 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1369 assert(N == 1 && "Invalid number of operands!");
1370 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1371 }
1372
Jim Grosbach89df9962011-08-26 21:43:41 +00001373 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1374 assert(N == 1 && "Invalid number of operands!");
1375 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1376 }
1377
1378 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1379 assert(N == 1 && "Invalid number of operands!");
1380 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1381 }
1382
Jim Grosbachd67641b2010-12-06 18:21:12 +00001383 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1384 assert(N == 1 && "Invalid number of operands!");
1385 Inst.addOperand(MCOperand::CreateReg(getReg()));
1386 }
1387
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001388 void addRegOperands(MCInst &Inst, unsigned N) const {
1389 assert(N == 1 && "Invalid number of operands!");
1390 Inst.addOperand(MCOperand::CreateReg(getReg()));
1391 }
1392
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001393 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbache8606dc2011-07-13 17:50:29 +00001394 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001395 assert(isRegShiftedReg() &&
1396 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001397 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1398 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001399 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001400 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001401 }
1402
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001403 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson152d4a42011-07-21 23:38:37 +00001404 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001405 assert(isRegShiftedImm() &&
1406 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001407 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Owen Anderson92a20222011-07-21 18:54:16 +00001408 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001409 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, RegShiftedImm.ShiftImm)));
Owen Anderson92a20222011-07-21 18:54:16 +00001410 }
1411
Jim Grosbach580f4a92011-07-25 22:20:28 +00001412 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson00828302011-03-18 22:50:18 +00001413 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach580f4a92011-07-25 22:20:28 +00001414 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1415 ShifterImm.Imm));
Owen Anderson00828302011-03-18 22:50:18 +00001416 }
1417
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001418 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +00001419 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +00001420 const SmallVectorImpl<unsigned> &RegList = getRegList();
1421 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00001422 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1423 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001424 }
1425
Bill Wendling0f630752010-11-17 04:32:08 +00001426 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1427 addRegListOperands(Inst, N);
1428 }
1429
1430 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1431 addRegListOperands(Inst, N);
1432 }
1433
Jim Grosbach7e1547e2011-07-27 20:15:40 +00001434 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1435 assert(N == 1 && "Invalid number of operands!");
1436 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1437 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1438 }
1439
Jim Grosbach293a2ee2011-07-28 21:34:26 +00001440 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1441 assert(N == 1 && "Invalid number of operands!");
1442 // Munge the lsb/width into a bitfield mask.
1443 unsigned lsb = Bitfield.LSB;
1444 unsigned width = Bitfield.Width;
1445 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1446 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1447 (32 - (lsb + width)));
1448 Inst.addOperand(MCOperand::CreateImm(Mask));
1449 }
1450
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001451 void addImmOperands(MCInst &Inst, unsigned N) const {
1452 assert(N == 1 && "Invalid number of operands!");
1453 addExpr(Inst, getImm());
1454 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001455
Jim Grosbach4050bc42011-12-22 22:19:05 +00001456 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1457 assert(N == 1 && "Invalid number of operands!");
1458 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1459 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1460 }
1461
1462 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1463 assert(N == 1 && "Invalid number of operands!");
1464 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1465 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1466 }
1467
Jim Grosbach9d390362011-10-03 23:38:36 +00001468 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1469 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach51222d12012-01-20 18:09:51 +00001470 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1471 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1472 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach9d390362011-10-03 23:38:36 +00001473 }
1474
Jim Grosbacha77295d2011-09-08 22:07:06 +00001475 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1476 assert(N == 1 && "Invalid number of operands!");
1477 // FIXME: We really want to scale the value here, but the LDRD/STRD
1478 // instruction don't encode operands that way yet.
1479 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1480 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1481 }
1482
Jim Grosbach72f39f82011-08-24 21:22:15 +00001483 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1484 assert(N == 1 && "Invalid number of operands!");
1485 // The immediate is scaled by four in the encoding and is stored
1486 // in the MCInst as such. Lop off the low two bits here.
1487 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1488 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1489 }
1490
1491 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1492 assert(N == 1 && "Invalid number of operands!");
1493 // The immediate is scaled by four in the encoding and is stored
1494 // in the MCInst as such. Lop off the low two bits here.
1495 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1496 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1497 }
1498
Jim Grosbachf4943352011-07-25 23:09:14 +00001499 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1500 assert(N == 1 && "Invalid number of operands!");
1501 // The constant encodes as the immediate-1, and we store in the instruction
1502 // the bits as encoded, so subtract off one here.
1503 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1504 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1505 }
1506
Jim Grosbach4a5ffb32011-07-22 23:16:18 +00001507 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1508 assert(N == 1 && "Invalid number of operands!");
1509 // The constant encodes as the immediate-1, and we store in the instruction
1510 // the bits as encoded, so subtract off one here.
1511 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1512 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1513 }
1514
Jim Grosbach70939ee2011-08-17 21:51:27 +00001515 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1516 assert(N == 1 && "Invalid number of operands!");
1517 // The constant encodes as the immediate, except for 32, which encodes as
1518 // zero.
1519 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1520 unsigned Imm = CE->getValue();
1521 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1522 }
1523
Jim Grosbachf6c05252011-07-21 17:23:04 +00001524 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1525 assert(N == 1 && "Invalid number of operands!");
1526 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1527 // the instruction as well.
1528 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1529 int Val = CE->getValue();
1530 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1531 }
1532
Jim Grosbach89a63372011-10-28 22:36:30 +00001533 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1534 assert(N == 1 && "Invalid number of operands!");
1535 // The operand is actually a t2_so_imm, but we have its bitwise
1536 // negation in the assembly source, so twiddle it here.
1537 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1538 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1539 }
1540
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001541 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1542 assert(N == 1 && "Invalid number of operands!");
1543 // The operand is actually a t2_so_imm, but we have its
1544 // negation in the assembly source, so twiddle it here.
1545 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1546 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1547 }
1548
Jim Grosbache70ec842011-10-28 22:50:54 +00001549 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1550 assert(N == 1 && "Invalid number of operands!");
1551 // The operand is actually a so_imm, but we have its bitwise
1552 // negation in the assembly source, so twiddle it here.
1553 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1554 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1555 }
1556
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001557 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1558 assert(N == 1 && "Invalid number of operands!");
1559 // The operand is actually a so_imm, but we have its
1560 // negation in the assembly source, so twiddle it here.
1561 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1562 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1563 }
1564
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001565 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1566 assert(N == 1 && "Invalid number of operands!");
1567 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1568 }
1569
Jim Grosbach7ce05792011-08-03 23:50:40 +00001570 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1571 assert(N == 1 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001572 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00001573 }
1574
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001575 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1576 assert(N == 1 && "Invalid number of operands!");
1577 int32_t Imm = Memory.OffsetImm->getValue();
1578 // FIXME: Handle #-0
1579 if (Imm == INT32_MIN) Imm = 0;
1580 Inst.addOperand(MCOperand::CreateImm(Imm));
1581 }
1582
Jim Grosbach57dcb852011-10-11 17:29:55 +00001583 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1584 assert(N == 2 && "Invalid number of operands!");
1585 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1586 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1587 }
1588
Jim Grosbach7ce05792011-08-03 23:50:40 +00001589 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1590 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001591 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1592 if (!Memory.OffsetRegNum) {
Jim Grosbach7ce05792011-08-03 23:50:40 +00001593 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1594 // Special case for #-0
1595 if (Val == INT32_MIN) Val = 0;
1596 if (Val < 0) Val = -Val;
1597 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1598 } else {
1599 // For register offset, we encode the shift type and negation flag
1600 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001601 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1602 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001603 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001604 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1605 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001606 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001607 }
1608
Jim Grosbach039c2e12011-08-04 23:01:30 +00001609 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1610 assert(N == 2 && "Invalid number of operands!");
1611 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1612 assert(CE && "non-constant AM2OffsetImm operand!");
1613 int32_t Val = CE->getValue();
1614 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1615 // Special case for #-0
1616 if (Val == INT32_MIN) Val = 0;
1617 if (Val < 0) Val = -Val;
1618 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1619 Inst.addOperand(MCOperand::CreateReg(0));
1620 Inst.addOperand(MCOperand::CreateImm(Val));
1621 }
1622
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001623 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1624 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001625 // If we have an immediate that's not a constant, treat it as a label
1626 // reference needing a fixup. If it is a constant, it's something else
1627 // and we reject it.
1628 if (isImm()) {
1629 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1630 Inst.addOperand(MCOperand::CreateReg(0));
1631 Inst.addOperand(MCOperand::CreateImm(0));
1632 return;
1633 }
1634
Jim Grosbache53c87b2011-10-11 15:59:20 +00001635 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1636 if (!Memory.OffsetRegNum) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001637 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1638 // Special case for #-0
1639 if (Val == INT32_MIN) Val = 0;
1640 if (Val < 0) Val = -Val;
1641 Val = ARM_AM::getAM3Opc(AddSub, Val);
1642 } else {
1643 // For register offset, we encode the shift type and negation flag
1644 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001645 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001646 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001647 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1648 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001649 Inst.addOperand(MCOperand::CreateImm(Val));
1650 }
1651
1652 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1653 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001654 if (Kind == k_PostIndexRegister) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001655 int32_t Val =
1656 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1657 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1658 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach251bf252011-08-10 21:56:18 +00001659 return;
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001660 }
1661
1662 // Constant offset.
1663 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1664 int32_t Val = CE->getValue();
1665 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1666 // Special case for #-0
1667 if (Val == INT32_MIN) Val = 0;
1668 if (Val < 0) Val = -Val;
Jim Grosbach251bf252011-08-10 21:56:18 +00001669 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001670 Inst.addOperand(MCOperand::CreateReg(0));
1671 Inst.addOperand(MCOperand::CreateImm(Val));
1672 }
1673
Jim Grosbach7ce05792011-08-03 23:50:40 +00001674 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1675 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach681460f2011-11-01 01:24:45 +00001676 // If we have an immediate that's not a constant, treat it as a label
1677 // reference needing a fixup. If it is a constant, it's something else
1678 // and we reject it.
1679 if (isImm()) {
1680 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1681 Inst.addOperand(MCOperand::CreateImm(0));
1682 return;
1683 }
1684
Jim Grosbach7ce05792011-08-03 23:50:40 +00001685 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001686 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001687 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1688 // Special case for #-0
1689 if (Val == INT32_MIN) Val = 0;
1690 if (Val < 0) Val = -Val;
1691 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001692 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001693 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001694 }
1695
Jim Grosbacha77295d2011-09-08 22:07:06 +00001696 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1697 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001698 // If we have an immediate that's not a constant, treat it as a label
1699 // reference needing a fixup. If it is a constant, it's something else
1700 // and we reject it.
1701 if (isImm()) {
1702 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1703 Inst.addOperand(MCOperand::CreateImm(0));
1704 return;
1705 }
1706
Jim Grosbache53c87b2011-10-11 15:59:20 +00001707 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1708 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha77295d2011-09-08 22:07:06 +00001709 Inst.addOperand(MCOperand::CreateImm(Val));
1710 }
1711
Jim Grosbachb6aed502011-09-09 18:37:27 +00001712 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1713 assert(N == 2 && "Invalid number of operands!");
1714 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001715 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1716 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachb6aed502011-09-09 18:37:27 +00001717 Inst.addOperand(MCOperand::CreateImm(Val));
1718 }
1719
Jim Grosbach7ce05792011-08-03 23:50:40 +00001720 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1721 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001722 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1723 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001724 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner14b93852010-10-29 00:27:31 +00001725 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001726
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001727 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1728 addMemImm8OffsetOperands(Inst, N);
1729 }
1730
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001731 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001732 addMemImm8OffsetOperands(Inst, N);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001733 }
1734
1735 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1736 assert(N == 2 && "Invalid number of operands!");
1737 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001738 if (isImm()) {
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001739 addExpr(Inst, getImm());
1740 Inst.addOperand(MCOperand::CreateImm(0));
1741 return;
1742 }
1743
1744 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001745 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1746 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001747 Inst.addOperand(MCOperand::CreateImm(Val));
1748 }
1749
Jim Grosbach7ce05792011-08-03 23:50:40 +00001750 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1751 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach09176e12011-08-08 20:59:31 +00001752 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001753 if (isImm()) {
Jim Grosbach09176e12011-08-08 20:59:31 +00001754 addExpr(Inst, getImm());
1755 Inst.addOperand(MCOperand::CreateImm(0));
1756 return;
1757 }
1758
1759 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001760 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1761 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001762 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendlingf4caf692010-12-14 03:36:38 +00001763 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001764
Jim Grosbach7f739be2011-09-19 22:21:13 +00001765 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1766 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001767 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1768 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001769 }
1770
1771 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1772 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001773 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1774 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001775 }
1776
Jim Grosbach7ce05792011-08-03 23:50:40 +00001777 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1778 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001779 unsigned Val =
1780 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1781 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001782 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1783 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001784 Inst.addOperand(MCOperand::CreateImm(Val));
1785 }
1786
Jim Grosbachab899c12011-09-07 23:10:15 +00001787 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1788 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001789 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1790 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1791 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbachab899c12011-09-07 23:10:15 +00001792 }
1793
Jim Grosbach7ce05792011-08-03 23:50:40 +00001794 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001796 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1797 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001798 }
1799
Jim Grosbach60f91a32011-08-19 17:55:24 +00001800 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1801 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001802 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1803 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +00001804 Inst.addOperand(MCOperand::CreateImm(Val));
1805 }
1806
Jim Grosbach38466302011-08-19 18:55:51 +00001807 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1808 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001809 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1810 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach38466302011-08-19 18:55:51 +00001811 Inst.addOperand(MCOperand::CreateImm(Val));
1812 }
1813
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001814 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1815 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001816 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1817 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001818 Inst.addOperand(MCOperand::CreateImm(Val));
1819 }
1820
Jim Grosbachecd85892011-08-19 18:13:48 +00001821 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1822 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001823 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1824 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachecd85892011-08-19 18:13:48 +00001825 Inst.addOperand(MCOperand::CreateImm(Val));
1826 }
1827
Jim Grosbach7ce05792011-08-03 23:50:40 +00001828 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1829 assert(N == 1 && "Invalid number of operands!");
1830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1831 assert(CE && "non-constant post-idx-imm8 operand!");
1832 int Imm = CE->getValue();
1833 bool isAdd = Imm >= 0;
Owen Anderson63553c72011-08-29 17:17:09 +00001834 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001835 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1836 Inst.addOperand(MCOperand::CreateImm(Imm));
1837 }
1838
Jim Grosbach2bd01182011-10-11 21:55:36 +00001839 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1840 assert(N == 1 && "Invalid number of operands!");
1841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1842 assert(CE && "non-constant post-idx-imm8s4 operand!");
1843 int Imm = CE->getValue();
1844 bool isAdd = Imm >= 0;
1845 if (Imm == INT32_MIN) Imm = 0;
1846 // Immediate is scaled by 4.
1847 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1848 Inst.addOperand(MCOperand::CreateImm(Imm));
1849 }
1850
Jim Grosbach7ce05792011-08-03 23:50:40 +00001851 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1852 assert(N == 2 && "Invalid number of operands!");
1853 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00001854 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1855 }
1856
1857 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1858 assert(N == 2 && "Invalid number of operands!");
1859 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1860 // The sign, shift type, and shift amount are encoded in a single operand
1861 // using the AM2 encoding helpers.
1862 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1863 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1864 PostIdxReg.ShiftTy);
1865 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001866 }
1867
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001868 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1869 assert(N == 1 && "Invalid number of operands!");
1870 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1871 }
1872
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001873 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1874 assert(N == 1 && "Invalid number of operands!");
1875 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1876 }
1877
Jim Grosbach6029b6d2011-11-29 23:51:09 +00001878 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach862019c2011-10-18 23:02:30 +00001879 assert(N == 1 && "Invalid number of operands!");
1880 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1881 }
1882
Jim Grosbach7636bf62011-12-02 00:35:16 +00001883 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1884 assert(N == 2 && "Invalid number of operands!");
1885 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1886 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1887 }
1888
Jim Grosbach460a9052011-10-07 23:56:00 +00001889 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1890 assert(N == 1 && "Invalid number of operands!");
1891 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1892 }
1893
1894 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1895 assert(N == 1 && "Invalid number of operands!");
1896 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1897 }
1898
1899 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1900 assert(N == 1 && "Invalid number of operands!");
1901 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1902 }
1903
Jim Grosbach0e387b22011-10-17 22:26:03 +00001904 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1905 assert(N == 1 && "Invalid number of operands!");
1906 // The immediate encodes the type of constant as well as the value.
1907 // Mask in that this is an i8 splat.
1908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1909 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1910 }
1911
Jim Grosbachea461102011-10-17 23:09:09 +00001912 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1913 assert(N == 1 && "Invalid number of operands!");
1914 // The immediate encodes the type of constant as well as the value.
1915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1916 unsigned Value = CE->getValue();
1917 if (Value >= 256)
1918 Value = (Value >> 8) | 0xa00;
1919 else
1920 Value |= 0x800;
1921 Inst.addOperand(MCOperand::CreateImm(Value));
1922 }
1923
Jim Grosbach6248a542011-10-18 00:22:00 +00001924 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
1925 assert(N == 1 && "Invalid number of operands!");
1926 // The immediate encodes the type of constant as well as the value.
1927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1928 unsigned Value = CE->getValue();
1929 if (Value >= 256 && Value <= 0xff00)
1930 Value = (Value >> 8) | 0x200;
1931 else if (Value > 0xffff && Value <= 0xff0000)
1932 Value = (Value >> 16) | 0x400;
1933 else if (Value > 0xffffff)
1934 Value = (Value >> 24) | 0x600;
1935 Inst.addOperand(MCOperand::CreateImm(Value));
1936 }
1937
1938 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
1939 assert(N == 1 && "Invalid number of operands!");
1940 // The immediate encodes the type of constant as well as the value.
1941 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1942 unsigned Value = CE->getValue();
1943 if (Value >= 256 && Value <= 0xffff)
1944 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1945 else if (Value > 0xffff && Value <= 0xffffff)
1946 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1947 else if (Value > 0xffffff)
1948 Value = (Value >> 24) | 0x600;
1949 Inst.addOperand(MCOperand::CreateImm(Value));
1950 }
1951
Jim Grosbach9b087852011-12-19 23:51:07 +00001952 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
1953 assert(N == 1 && "Invalid number of operands!");
1954 // The immediate encodes the type of constant as well as the value.
1955 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1956 unsigned Value = ~CE->getValue();
1957 if (Value >= 256 && Value <= 0xffff)
1958 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1959 else if (Value > 0xffff && Value <= 0xffffff)
1960 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1961 else if (Value > 0xffffff)
1962 Value = (Value >> 24) | 0x600;
1963 Inst.addOperand(MCOperand::CreateImm(Value));
1964 }
1965
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001966 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
1967 assert(N == 1 && "Invalid number of operands!");
1968 // The immediate encodes the type of constant as well as the value.
1969 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1970 uint64_t Value = CE->getValue();
1971 unsigned Imm = 0;
1972 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
1973 Imm |= (Value & 1) << i;
1974 }
1975 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
1976 }
1977
Jim Grosbachb7f689b2011-07-13 15:34:57 +00001978 virtual void print(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +00001979
Jim Grosbach89df9962011-08-26 21:43:41 +00001980 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001981 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach89df9962011-08-26 21:43:41 +00001982 Op->ITMask.Mask = Mask;
1983 Op->StartLoc = S;
1984 Op->EndLoc = S;
1985 return Op;
1986 }
1987
Chris Lattner3a697562010-10-28 17:20:03 +00001988 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001989 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001990 Op->CC.Val = CC;
1991 Op->StartLoc = S;
1992 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00001993 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001994 }
1995
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001996 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001997 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001998 Op->Cop.Val = CopVal;
1999 Op->StartLoc = S;
2000 Op->EndLoc = S;
2001 return Op;
2002 }
2003
2004 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002005 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002006 Op->Cop.Val = CopVal;
2007 Op->StartLoc = S;
2008 Op->EndLoc = S;
2009 return Op;
2010 }
2011
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002012 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2013 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2014 Op->Cop.Val = Val;
2015 Op->StartLoc = S;
2016 Op->EndLoc = E;
2017 return Op;
2018 }
2019
Jim Grosbachd67641b2010-12-06 18:21:12 +00002020 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002021 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbachd67641b2010-12-06 18:21:12 +00002022 Op->Reg.RegNum = RegNum;
2023 Op->StartLoc = S;
2024 Op->EndLoc = S;
2025 return Op;
2026 }
2027
Chris Lattner3a697562010-10-28 17:20:03 +00002028 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002029 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan76264762010-04-02 22:27:05 +00002030 Op->Tok.Data = Str.data();
2031 Op->Tok.Length = Str.size();
2032 Op->StartLoc = S;
2033 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002034 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002035 }
2036
Bill Wendling50d0f582010-11-18 23:43:05 +00002037 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002038 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan76264762010-04-02 22:27:05 +00002039 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +00002040 Op->StartLoc = S;
2041 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002042 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002043 }
2044
Jim Grosbache8606dc2011-07-13 17:50:29 +00002045 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2046 unsigned SrcReg,
2047 unsigned ShiftReg,
2048 unsigned ShiftImm,
2049 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002050 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002051 Op->RegShiftedReg.ShiftTy = ShTy;
2052 Op->RegShiftedReg.SrcReg = SrcReg;
2053 Op->RegShiftedReg.ShiftReg = ShiftReg;
2054 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002055 Op->StartLoc = S;
2056 Op->EndLoc = E;
2057 return Op;
2058 }
2059
Owen Anderson92a20222011-07-21 18:54:16 +00002060 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2061 unsigned SrcReg,
2062 unsigned ShiftImm,
2063 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002064 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002065 Op->RegShiftedImm.ShiftTy = ShTy;
2066 Op->RegShiftedImm.SrcReg = SrcReg;
2067 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Anderson92a20222011-07-21 18:54:16 +00002068 Op->StartLoc = S;
2069 Op->EndLoc = E;
2070 return Op;
2071 }
2072
Jim Grosbach580f4a92011-07-25 22:20:28 +00002073 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002074 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002075 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach580f4a92011-07-25 22:20:28 +00002076 Op->ShifterImm.isASR = isASR;
2077 Op->ShifterImm.Imm = Imm;
Owen Anderson00828302011-03-18 22:50:18 +00002078 Op->StartLoc = S;
2079 Op->EndLoc = E;
2080 return Op;
2081 }
2082
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002083 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002084 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002085 Op->RotImm.Imm = Imm;
2086 Op->StartLoc = S;
2087 Op->EndLoc = E;
2088 return Op;
2089 }
2090
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002091 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2092 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002093 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002094 Op->Bitfield.LSB = LSB;
2095 Op->Bitfield.Width = Width;
2096 Op->StartLoc = S;
2097 Op->EndLoc = E;
2098 return Op;
2099 }
2100
Bill Wendling7729e062010-11-09 22:44:22 +00002101 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +00002102 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002103 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002104 KindTy Kind = k_RegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002105
Jim Grosbachd300b942011-09-13 22:56:44 +00002106 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002107 Kind = k_DPRRegisterList;
Jim Grosbachd300b942011-09-13 22:56:44 +00002108 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng275944a2011-07-25 21:32:49 +00002109 contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002110 Kind = k_SPRRegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002111
2112 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +00002113 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002114 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +00002115 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +00002116 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002117 Op->StartLoc = StartLoc;
2118 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +00002119 return Op;
2120 }
2121
Jim Grosbach862019c2011-10-18 23:02:30 +00002122 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002123 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbach862019c2011-10-18 23:02:30 +00002124 ARMOperand *Op = new ARMOperand(k_VectorList);
2125 Op->VectorList.RegNum = RegNum;
2126 Op->VectorList.Count = Count;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002127 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +00002128 Op->StartLoc = S;
2129 Op->EndLoc = E;
2130 return Op;
2131 }
2132
Jim Grosbach98b05a52011-11-30 01:09:44 +00002133 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002134 bool isDoubleSpaced,
Jim Grosbach98b05a52011-11-30 01:09:44 +00002135 SMLoc S, SMLoc E) {
2136 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2137 Op->VectorList.RegNum = RegNum;
2138 Op->VectorList.Count = Count;
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002139 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002140 Op->StartLoc = S;
2141 Op->EndLoc = E;
2142 return Op;
2143 }
2144
Jim Grosbach7636bf62011-12-02 00:35:16 +00002145 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002146 unsigned Index,
2147 bool isDoubleSpaced,
2148 SMLoc S, SMLoc E) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00002149 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2150 Op->VectorList.RegNum = RegNum;
2151 Op->VectorList.Count = Count;
2152 Op->VectorList.LaneIndex = Index;
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002153 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002154 Op->StartLoc = S;
2155 Op->EndLoc = E;
2156 return Op;
2157 }
2158
Jim Grosbach460a9052011-10-07 23:56:00 +00002159 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2160 MCContext &Ctx) {
2161 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2162 Op->VectorIndex.Val = Idx;
2163 Op->StartLoc = S;
2164 Op->EndLoc = E;
2165 return Op;
2166 }
2167
Chris Lattner3a697562010-10-28 17:20:03 +00002168 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002169 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan76264762010-04-02 22:27:05 +00002170 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +00002171 Op->StartLoc = S;
2172 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002173 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +00002174 }
2175
Jim Grosbach7ce05792011-08-03 23:50:40 +00002176 static ARMOperand *CreateMem(unsigned BaseRegNum,
2177 const MCConstantExpr *OffsetImm,
2178 unsigned OffsetRegNum,
2179 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach0d6fac32011-08-05 22:03:36 +00002180 unsigned ShiftImm,
Jim Grosbach57dcb852011-10-11 17:29:55 +00002181 unsigned Alignment,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002182 bool isNegative,
Chris Lattner3a697562010-10-28 17:20:03 +00002183 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002184 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbache53c87b2011-10-11 15:59:20 +00002185 Op->Memory.BaseRegNum = BaseRegNum;
2186 Op->Memory.OffsetImm = OffsetImm;
2187 Op->Memory.OffsetRegNum = OffsetRegNum;
2188 Op->Memory.ShiftType = ShiftType;
2189 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbach57dcb852011-10-11 17:29:55 +00002190 Op->Memory.Alignment = Alignment;
Jim Grosbache53c87b2011-10-11 15:59:20 +00002191 Op->Memory.isNegative = isNegative;
Jim Grosbach7ce05792011-08-03 23:50:40 +00002192 Op->StartLoc = S;
2193 Op->EndLoc = E;
2194 return Op;
2195 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002196
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002197 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2198 ARM_AM::ShiftOpc ShiftTy,
2199 unsigned ShiftImm,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002200 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002201 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbach7ce05792011-08-03 23:50:40 +00002202 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002203 Op->PostIdxReg.isAdd = isAdd;
2204 Op->PostIdxReg.ShiftTy = ShiftTy;
2205 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan76264762010-04-02 22:27:05 +00002206 Op->StartLoc = S;
2207 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002208 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002209 }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002210
2211 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002212 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002213 Op->MBOpt.Val = Opt;
2214 Op->StartLoc = S;
2215 Op->EndLoc = S;
2216 return Op;
2217 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002218
2219 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002220 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002221 Op->IFlags.Val = IFlags;
2222 Op->StartLoc = S;
2223 Op->EndLoc = S;
2224 return Op;
2225 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002226
2227 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002228 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002229 Op->MMask.Val = MMask;
2230 Op->StartLoc = S;
2231 Op->EndLoc = S;
2232 return Op;
2233 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002234};
2235
2236} // end anonymous namespace.
2237
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002238void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002239 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002240 case k_CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +00002241 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002242 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002243 case k_CCOut:
Jim Grosbachd67641b2010-12-06 18:21:12 +00002244 OS << "<ccout " << getReg() << ">";
2245 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002246 case k_ITCondMask: {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002247 static const char *MaskStr[] = {
2248 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2249 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2250 };
Jim Grosbach89df9962011-08-26 21:43:41 +00002251 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2252 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2253 break;
2254 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002255 case k_CoprocNum:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002256 OS << "<coprocessor number: " << getCoproc() << ">";
2257 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002258 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002259 OS << "<coprocessor register: " << getCoproc() << ">";
2260 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002261 case k_CoprocOption:
2262 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2263 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002264 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002265 OS << "<mask: " << getMSRMask() << ">";
2266 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002267 case k_Immediate:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002268 getImm()->print(OS);
2269 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002270 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002271 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2272 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002273 case k_Memory:
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002274 OS << "<memory "
Jim Grosbache53c87b2011-10-11 15:59:20 +00002275 << " base:" << Memory.BaseRegNum;
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002276 OS << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002277 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002278 case k_PostIndexRegister:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002279 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2280 << PostIdxReg.RegNum;
2281 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2282 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2283 << PostIdxReg.ShiftImm;
2284 OS << ">";
Jim Grosbach7ce05792011-08-03 23:50:40 +00002285 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002286 case k_ProcIFlags: {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002287 OS << "<ARM_PROC::";
2288 unsigned IFlags = getProcIFlags();
2289 for (int i=2; i >= 0; --i)
2290 if (IFlags & (1 << i))
2291 OS << ARM_PROC::IFlagsToString(1 << i);
2292 OS << ">";
2293 break;
2294 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002295 case k_Register:
Bill Wendling50d0f582010-11-18 23:43:05 +00002296 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002297 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002298 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +00002299 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2300 << " #" << ShifterImm.Imm << ">";
Jim Grosbache8606dc2011-07-13 17:50:29 +00002301 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002302 case k_ShiftedRegister:
Owen Anderson92a20222011-07-21 18:54:16 +00002303 OS << "<so_reg_reg "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002304 << RegShiftedReg.SrcReg << " "
2305 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2306 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson00828302011-03-18 22:50:18 +00002307 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002308 case k_ShiftedImmediate:
Owen Anderson92a20222011-07-21 18:54:16 +00002309 OS << "<so_reg_imm "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002310 << RegShiftedImm.SrcReg << " "
2311 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2312 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Anderson92a20222011-07-21 18:54:16 +00002313 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002314 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002315 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2316 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002317 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002318 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2319 << ", width: " << Bitfield.Width << ">";
2320 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002321 case k_RegisterList:
2322 case k_DPRRegisterList:
2323 case k_SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +00002324 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002325
Bill Wendling5fa22a12010-11-09 23:28:44 +00002326 const SmallVectorImpl<unsigned> &RegList = getRegList();
2327 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002328 I = RegList.begin(), E = RegList.end(); I != E; ) {
2329 OS << *I;
2330 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002331 }
2332
2333 OS << ">";
2334 break;
2335 }
Jim Grosbach862019c2011-10-18 23:02:30 +00002336 case k_VectorList:
2337 OS << "<vector_list " << VectorList.Count << " * "
2338 << VectorList.RegNum << ">";
2339 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002340 case k_VectorListAllLanes:
2341 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2342 << VectorList.RegNum << ">";
2343 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002344 case k_VectorListIndexed:
2345 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2346 << VectorList.Count << " * " << VectorList.RegNum << ">";
2347 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002348 case k_Token:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002349 OS << "'" << getToken() << "'";
2350 break;
Jim Grosbach460a9052011-10-07 23:56:00 +00002351 case k_VectorIndex:
2352 OS << "<vectorindex " << getVectorIndex() << ">";
2353 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002354 }
2355}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002356
2357/// @name Auto-generated Match Functions
2358/// {
2359
2360static unsigned MatchRegisterName(StringRef Name);
2361
2362/// }
2363
Bob Wilson69df7232011-02-03 21:46:10 +00002364bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2365 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbacha39cda72011-12-14 02:16:11 +00002366 StartLoc = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002367 RegNo = tryParseRegister();
Jim Grosbacha39cda72011-12-14 02:16:11 +00002368 EndLoc = Parser.getTok().getLoc();
Roman Divackybf755322011-01-27 17:14:22 +00002369
2370 return (RegNo == (unsigned)-1);
2371}
2372
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002373/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +00002374/// and if it is a register name the token is eaten and the register number is
2375/// returned. Otherwise return -1.
2376///
Jim Grosbach1355cf12011-07-26 17:10:22 +00002377int ARMAsmParser::tryParseRegister() {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002378 const AsmToken &Tok = Parser.getTok();
Jim Grosbach7ce05792011-08-03 23:50:40 +00002379 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002380
Benjamin Kramer59085362011-11-06 20:37:06 +00002381 std::string lowerCase = Tok.getString().lower();
Owen Anderson0c9f2502011-01-13 22:50:36 +00002382 unsigned RegNum = MatchRegisterName(lowerCase);
2383 if (!RegNum) {
2384 RegNum = StringSwitch<unsigned>(lowerCase)
2385 .Case("r13", ARM::SP)
2386 .Case("r14", ARM::LR)
2387 .Case("r15", ARM::PC)
2388 .Case("ip", ARM::R12)
Jim Grosbach40e28552011-12-08 19:27:38 +00002389 // Additional register name aliases for 'gas' compatibility.
2390 .Case("a1", ARM::R0)
2391 .Case("a2", ARM::R1)
2392 .Case("a3", ARM::R2)
2393 .Case("a4", ARM::R3)
2394 .Case("v1", ARM::R4)
2395 .Case("v2", ARM::R5)
2396 .Case("v3", ARM::R6)
2397 .Case("v4", ARM::R7)
2398 .Case("v5", ARM::R8)
2399 .Case("v6", ARM::R9)
2400 .Case("v7", ARM::R10)
2401 .Case("v8", ARM::R11)
2402 .Case("sb", ARM::R9)
2403 .Case("sl", ARM::R10)
2404 .Case("fp", ARM::R11)
Owen Anderson0c9f2502011-01-13 22:50:36 +00002405 .Default(0);
2406 }
Jim Grosbacha39cda72011-12-14 02:16:11 +00002407 if (!RegNum) {
Jim Grosbachaee718b2011-12-20 23:11:00 +00002408 // Check for aliases registered via .req. Canonicalize to lower case.
2409 // That's more consistent since register names are case insensitive, and
2410 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2411 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbacha39cda72011-12-14 02:16:11 +00002412 // If no match, return failure.
2413 if (Entry == RegisterReqs.end())
2414 return -1;
2415 Parser.Lex(); // Eat identifier token.
2416 return Entry->getValue();
2417 }
Bob Wilson69df7232011-02-03 21:46:10 +00002418
Chris Lattnere5658fa2010-10-30 04:09:10 +00002419 Parser.Lex(); // Eat identifier token.
Jim Grosbach460a9052011-10-07 23:56:00 +00002420
Chris Lattnere5658fa2010-10-30 04:09:10 +00002421 return RegNum;
2422}
Jim Grosbachd4462a52010-11-01 16:44:21 +00002423
Jim Grosbach19906722011-07-13 18:49:30 +00002424// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2425// If a recoverable error occurs, return 1. If an irrecoverable error
2426// occurs, return -1. An irrecoverable error is one where tokens have been
2427// consumed in the process of trying to parse the shifter (i.e., when it is
2428// indeed a shifter operand, but malformed).
Jim Grosbach0d87ec22011-07-26 20:41:24 +00002429int ARMAsmParser::tryParseShiftRegister(
Owen Anderson00828302011-03-18 22:50:18 +00002430 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2431 SMLoc S = Parser.getTok().getLoc();
2432 const AsmToken &Tok = Parser.getTok();
2433 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2434
Benjamin Kramer59085362011-11-06 20:37:06 +00002435 std::string lowerCase = Tok.getString().lower();
Owen Anderson00828302011-03-18 22:50:18 +00002436 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbachaf4edea2011-12-07 23:40:58 +00002437 .Case("asl", ARM_AM::lsl)
Owen Anderson00828302011-03-18 22:50:18 +00002438 .Case("lsl", ARM_AM::lsl)
2439 .Case("lsr", ARM_AM::lsr)
2440 .Case("asr", ARM_AM::asr)
2441 .Case("ror", ARM_AM::ror)
2442 .Case("rrx", ARM_AM::rrx)
2443 .Default(ARM_AM::no_shift);
2444
2445 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbach19906722011-07-13 18:49:30 +00002446 return 1;
Owen Anderson00828302011-03-18 22:50:18 +00002447
Jim Grosbache8606dc2011-07-13 17:50:29 +00002448 Parser.Lex(); // Eat the operator.
Owen Anderson00828302011-03-18 22:50:18 +00002449
Jim Grosbache8606dc2011-07-13 17:50:29 +00002450 // The source register for the shift has already been added to the
2451 // operand list, so we need to pop it off and combine it into the shifted
2452 // register operand instead.
Benjamin Kramereac07962011-07-14 18:41:22 +00002453 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbache8606dc2011-07-13 17:50:29 +00002454 if (!PrevOp->isReg())
2455 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2456 int SrcReg = PrevOp->getReg();
2457 int64_t Imm = 0;
2458 int ShiftReg = 0;
2459 if (ShiftTy == ARM_AM::rrx) {
2460 // RRX Doesn't have an explicit shift amount. The encoder expects
2461 // the shift register to be the same as the source register. Seems odd,
2462 // but OK.
2463 ShiftReg = SrcReg;
2464 } else {
2465 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00002466 if (Parser.getTok().is(AsmToken::Hash) ||
2467 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbache8606dc2011-07-13 17:50:29 +00002468 Parser.Lex(); // Eat hash.
2469 SMLoc ImmLoc = Parser.getTok().getLoc();
2470 const MCExpr *ShiftExpr = 0;
Jim Grosbach19906722011-07-13 18:49:30 +00002471 if (getParser().ParseExpression(ShiftExpr)) {
2472 Error(ImmLoc, "invalid immediate shift value");
2473 return -1;
2474 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002475 // The expression must be evaluatable as an immediate.
2476 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbach19906722011-07-13 18:49:30 +00002477 if (!CE) {
2478 Error(ImmLoc, "invalid immediate shift value");
2479 return -1;
2480 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002481 // Range check the immediate.
2482 // lsl, ror: 0 <= imm <= 31
2483 // lsr, asr: 0 <= imm <= 32
2484 Imm = CE->getValue();
2485 if (Imm < 0 ||
2486 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2487 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbach19906722011-07-13 18:49:30 +00002488 Error(ImmLoc, "immediate shift value out of range");
2489 return -1;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002490 }
Jim Grosbachde626ad2011-12-22 17:37:00 +00002491 // shift by zero is a nop. Always send it through as lsl.
2492 // ('as' compatibility)
2493 if (Imm == 0)
2494 ShiftTy = ARM_AM::lsl;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002495 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach1355cf12011-07-26 17:10:22 +00002496 ShiftReg = tryParseRegister();
Jim Grosbache8606dc2011-07-13 17:50:29 +00002497 SMLoc L = Parser.getTok().getLoc();
Jim Grosbach19906722011-07-13 18:49:30 +00002498 if (ShiftReg == -1) {
2499 Error (L, "expected immediate or register in shift operand");
2500 return -1;
2501 }
2502 } else {
2503 Error (Parser.getTok().getLoc(),
Jim Grosbache8606dc2011-07-13 17:50:29 +00002504 "expected immediate or register in shift operand");
Jim Grosbach19906722011-07-13 18:49:30 +00002505 return -1;
2506 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002507 }
2508
Owen Anderson92a20222011-07-21 18:54:16 +00002509 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2510 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002511 ShiftReg, Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002512 S, Parser.getTok().getLoc()));
Owen Anderson92a20222011-07-21 18:54:16 +00002513 else
2514 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2515 S, Parser.getTok().getLoc()));
Owen Anderson00828302011-03-18 22:50:18 +00002516
Jim Grosbach19906722011-07-13 18:49:30 +00002517 return 0;
Owen Anderson00828302011-03-18 22:50:18 +00002518}
2519
2520
Bill Wendling50d0f582010-11-18 23:43:05 +00002521/// Try to parse a register name. The token must be an Identifier when called.
2522/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2523/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +00002524///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002525/// TODO this is likely to change to allow different register types and or to
2526/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +00002527bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002528tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002529 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002530 int RegNo = tryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +00002531 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +00002532 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002533
Bill Wendling50d0f582010-11-18 23:43:05 +00002534 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002535
Chris Lattnere5658fa2010-10-30 04:09:10 +00002536 const AsmToken &ExclaimTok = Parser.getTok();
2537 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +00002538 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2539 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +00002540 Parser.Lex(); // Eat exclaim token
Jim Grosbach460a9052011-10-07 23:56:00 +00002541 return false;
2542 }
2543
2544 // Also check for an index operand. This is only legal for vector registers,
2545 // but that'll get caught OK in operand matching, so we don't need to
2546 // explicitly filter everything else out here.
2547 if (Parser.getTok().is(AsmToken::LBrac)) {
2548 SMLoc SIdx = Parser.getTok().getLoc();
2549 Parser.Lex(); // Eat left bracket token.
2550
2551 const MCExpr *ImmVal;
Jim Grosbach460a9052011-10-07 23:56:00 +00002552 if (getParser().ParseExpression(ImmVal))
2553 return MatchOperand_ParseFail;
2554 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2555 if (!MCE) {
2556 TokError("immediate value expected for vector index");
2557 return MatchOperand_ParseFail;
2558 }
2559
2560 SMLoc E = Parser.getTok().getLoc();
2561 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2562 Error(E, "']' expected");
2563 return MatchOperand_ParseFail;
2564 }
2565
2566 Parser.Lex(); // Eat right bracket token.
2567
2568 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2569 SIdx, E,
2570 getContext()));
Kevin Enderby99e6d4e2009-10-07 18:01:35 +00002571 }
2572
Bill Wendling50d0f582010-11-18 23:43:05 +00002573 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002574}
2575
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002576/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2577/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2578/// "c5", ...
2579static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002580 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2581 // but efficient.
2582 switch (Name.size()) {
David Blaikie4d6ccb52012-01-20 21:51:11 +00002583 default: return -1;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002584 case 2:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002585 if (Name[0] != CoprocOp)
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002586 return -1;
2587 switch (Name[1]) {
2588 default: return -1;
2589 case '0': return 0;
2590 case '1': return 1;
2591 case '2': return 2;
2592 case '3': return 3;
2593 case '4': return 4;
2594 case '5': return 5;
2595 case '6': return 6;
2596 case '7': return 7;
2597 case '8': return 8;
2598 case '9': return 9;
2599 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002600 case 3:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002601 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002602 return -1;
2603 switch (Name[2]) {
2604 default: return -1;
2605 case '0': return 10;
2606 case '1': return 11;
2607 case '2': return 12;
2608 case '3': return 13;
2609 case '4': return 14;
2610 case '5': return 15;
2611 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002612 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002613}
2614
Jim Grosbach89df9962011-08-26 21:43:41 +00002615/// parseITCondCode - Try to parse a condition code for an IT instruction.
2616ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2617parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2618 SMLoc S = Parser.getTok().getLoc();
2619 const AsmToken &Tok = Parser.getTok();
2620 if (!Tok.is(AsmToken::Identifier))
2621 return MatchOperand_NoMatch;
2622 unsigned CC = StringSwitch<unsigned>(Tok.getString())
2623 .Case("eq", ARMCC::EQ)
2624 .Case("ne", ARMCC::NE)
2625 .Case("hs", ARMCC::HS)
2626 .Case("cs", ARMCC::HS)
2627 .Case("lo", ARMCC::LO)
2628 .Case("cc", ARMCC::LO)
2629 .Case("mi", ARMCC::MI)
2630 .Case("pl", ARMCC::PL)
2631 .Case("vs", ARMCC::VS)
2632 .Case("vc", ARMCC::VC)
2633 .Case("hi", ARMCC::HI)
2634 .Case("ls", ARMCC::LS)
2635 .Case("ge", ARMCC::GE)
2636 .Case("lt", ARMCC::LT)
2637 .Case("gt", ARMCC::GT)
2638 .Case("le", ARMCC::LE)
2639 .Case("al", ARMCC::AL)
2640 .Default(~0U);
2641 if (CC == ~0U)
2642 return MatchOperand_NoMatch;
2643 Parser.Lex(); // Eat the token.
2644
2645 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2646
2647 return MatchOperand_Success;
2648}
2649
Jim Grosbach43904292011-07-25 20:14:50 +00002650/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002651/// token must be an Identifier when called, and if it is a coprocessor
2652/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002653ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002654parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002655 SMLoc S = Parser.getTok().getLoc();
2656 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002657 if (Tok.isNot(AsmToken::Identifier))
2658 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002659
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002660 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002661 if (Num == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002662 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002663
2664 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002665 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002666 return MatchOperand_Success;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002667}
2668
Jim Grosbach43904292011-07-25 20:14:50 +00002669/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002670/// token must be an Identifier when called, and if it is a coprocessor
2671/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002672ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002673parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002674 SMLoc S = Parser.getTok().getLoc();
2675 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002676 if (Tok.isNot(AsmToken::Identifier))
2677 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002678
2679 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2680 if (Reg == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002681 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002682
2683 Parser.Lex(); // Eat identifier token.
2684 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002685 return MatchOperand_Success;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002686}
2687
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002688/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2689/// coproc_option : '{' imm0_255 '}'
2690ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2691parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2692 SMLoc S = Parser.getTok().getLoc();
2693
2694 // If this isn't a '{', this isn't a coprocessor immediate operand.
2695 if (Parser.getTok().isNot(AsmToken::LCurly))
2696 return MatchOperand_NoMatch;
2697 Parser.Lex(); // Eat the '{'
2698
2699 const MCExpr *Expr;
2700 SMLoc Loc = Parser.getTok().getLoc();
2701 if (getParser().ParseExpression(Expr)) {
2702 Error(Loc, "illegal expression");
2703 return MatchOperand_ParseFail;
2704 }
2705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2706 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2707 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2708 return MatchOperand_ParseFail;
2709 }
2710 int Val = CE->getValue();
2711
2712 // Check for and consume the closing '}'
2713 if (Parser.getTok().isNot(AsmToken::RCurly))
2714 return MatchOperand_ParseFail;
2715 SMLoc E = Parser.getTok().getLoc();
2716 Parser.Lex(); // Eat the '}'
2717
2718 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2719 return MatchOperand_Success;
2720}
2721
Jim Grosbachd0588e22011-09-14 18:08:35 +00002722// For register list parsing, we need to map from raw GPR register numbering
2723// to the enumeration values. The enumeration values aren't sorted by
2724// register number due to our using "sp", "lr" and "pc" as canonical names.
2725static unsigned getNextRegister(unsigned Reg) {
2726 // If this is a GPR, we need to do it manually, otherwise we can rely
2727 // on the sort ordering of the enumeration since the other reg-classes
2728 // are sane.
2729 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2730 return Reg + 1;
2731 switch(Reg) {
2732 default: assert(0 && "Invalid GPR number!");
2733 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2734 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2735 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2736 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2737 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2738 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2739 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2740 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2741 }
2742}
2743
Jim Grosbachce485e72011-11-11 21:27:40 +00002744// Return the low-subreg of a given Q register.
2745static unsigned getDRegFromQReg(unsigned QReg) {
2746 switch (QReg) {
2747 default: llvm_unreachable("expected a Q register!");
2748 case ARM::Q0: return ARM::D0;
2749 case ARM::Q1: return ARM::D2;
2750 case ARM::Q2: return ARM::D4;
2751 case ARM::Q3: return ARM::D6;
2752 case ARM::Q4: return ARM::D8;
2753 case ARM::Q5: return ARM::D10;
2754 case ARM::Q6: return ARM::D12;
2755 case ARM::Q7: return ARM::D14;
2756 case ARM::Q8: return ARM::D16;
Jim Grosbach25e0a872011-11-15 21:01:30 +00002757 case ARM::Q9: return ARM::D18;
Jim Grosbachce485e72011-11-11 21:27:40 +00002758 case ARM::Q10: return ARM::D20;
2759 case ARM::Q11: return ARM::D22;
2760 case ARM::Q12: return ARM::D24;
2761 case ARM::Q13: return ARM::D26;
2762 case ARM::Q14: return ARM::D28;
2763 case ARM::Q15: return ARM::D30;
2764 }
2765}
2766
Jim Grosbachd0588e22011-09-14 18:08:35 +00002767/// Parse a register list.
Bill Wendling50d0f582010-11-18 23:43:05 +00002768bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002769parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +00002770 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00002771 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +00002772 SMLoc S = Parser.getTok().getLoc();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002773 Parser.Lex(); // Eat '{' token.
2774 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002775
Jim Grosbachd0588e22011-09-14 18:08:35 +00002776 // Check the first register in the list to see what register class
2777 // this is a list of.
2778 int Reg = tryParseRegister();
2779 if (Reg == -1)
2780 return Error(RegLoc, "register expected");
2781
Jim Grosbachce485e72011-11-11 21:27:40 +00002782 // The reglist instructions have at most 16 registers, so reserve
2783 // space for that many.
2784 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2785
2786 // Allow Q regs and just interpret them as the two D sub-registers.
2787 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2788 Reg = getDRegFromQReg(Reg);
2789 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2790 ++Reg;
2791 }
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002792 const MCRegisterClass *RC;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002793 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2794 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2795 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2796 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2797 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2798 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2799 else
2800 return Error(RegLoc, "invalid register in register list");
2801
Jim Grosbachce485e72011-11-11 21:27:40 +00002802 // Store the register.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002803 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002804
Jim Grosbachd0588e22011-09-14 18:08:35 +00002805 // This starts immediately after the first register token in the list,
2806 // so we can see either a comma or a minus (range separator) as a legal
2807 // next token.
2808 while (Parser.getTok().is(AsmToken::Comma) ||
2809 Parser.getTok().is(AsmToken::Minus)) {
2810 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache43862b2011-11-15 23:19:15 +00002811 Parser.Lex(); // Eat the minus.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002812 SMLoc EndLoc = Parser.getTok().getLoc();
2813 int EndReg = tryParseRegister();
2814 if (EndReg == -1)
2815 return Error(EndLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002816 // Allow Q regs and just interpret them as the two D sub-registers.
2817 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2818 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002819 // If the register is the same as the start reg, there's nothing
2820 // more to do.
2821 if (Reg == EndReg)
2822 continue;
2823 // The register must be in the same register class as the first.
2824 if (!RC->contains(EndReg))
2825 return Error(EndLoc, "invalid register in register list");
2826 // Ranges must go from low to high.
2827 if (getARMRegisterNumbering(Reg) > getARMRegisterNumbering(EndReg))
2828 return Error(EndLoc, "bad range in register list");
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002829
Jim Grosbachd0588e22011-09-14 18:08:35 +00002830 // Add all the registers in the range to the register list.
2831 while (Reg != EndReg) {
2832 Reg = getNextRegister(Reg);
2833 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2834 }
2835 continue;
2836 }
2837 Parser.Lex(); // Eat the comma.
2838 RegLoc = Parser.getTok().getLoc();
2839 int OldReg = Reg;
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002840 const AsmToken RegTok = Parser.getTok();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002841 Reg = tryParseRegister();
2842 if (Reg == -1)
Jim Grosbach2d539692011-09-12 23:36:42 +00002843 return Error(RegLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002844 // Allow Q regs and just interpret them as the two D sub-registers.
2845 bool isQReg = false;
2846 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2847 Reg = getDRegFromQReg(Reg);
2848 isQReg = true;
2849 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002850 // The register must be in the same register class as the first.
2851 if (!RC->contains(Reg))
2852 return Error(RegLoc, "invalid register in register list");
2853 // List must be monotonically increasing.
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002854 if (getARMRegisterNumbering(Reg) < getARMRegisterNumbering(OldReg))
Jim Grosbachd0588e22011-09-14 18:08:35 +00002855 return Error(RegLoc, "register list not in ascending order");
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002856 if (getARMRegisterNumbering(Reg) == getARMRegisterNumbering(OldReg)) {
2857 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2858 ") in register list");
2859 continue;
2860 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002861 // VFP register lists must also be contiguous.
2862 // It's OK to use the enumeration values directly here rather, as the
2863 // VFP register classes have the enum sorted properly.
2864 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2865 Reg != OldReg + 1)
2866 return Error(RegLoc, "non-contiguous register range");
2867 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbachce485e72011-11-11 21:27:40 +00002868 if (isQReg)
2869 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge7176102010-11-06 22:36:58 +00002870 }
2871
Jim Grosbachd0588e22011-09-14 18:08:35 +00002872 SMLoc E = Parser.getTok().getLoc();
2873 if (Parser.getTok().isNot(AsmToken::RCurly))
2874 return Error(E, "'}' expected");
2875 Parser.Lex(); // Eat '}' token.
2876
Jim Grosbach27debd62011-12-13 21:48:29 +00002877 // Push the register list operand.
Bill Wendling50d0f582010-11-18 23:43:05 +00002878 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach27debd62011-12-13 21:48:29 +00002879
2880 // The ARM system instruction variants for LDM/STM have a '^' token here.
2881 if (Parser.getTok().is(AsmToken::Caret)) {
2882 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2883 Parser.Lex(); // Eat '^' token.
2884 }
2885
Bill Wendling50d0f582010-11-18 23:43:05 +00002886 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002887}
2888
Jim Grosbach98b05a52011-11-30 01:09:44 +00002889// Helper function to parse the lane index for vector lists.
2890ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach7636bf62011-12-02 00:35:16 +00002891parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2892 Index = 0; // Always return a defined index value.
Jim Grosbach98b05a52011-11-30 01:09:44 +00002893 if (Parser.getTok().is(AsmToken::LBrac)) {
2894 Parser.Lex(); // Eat the '['.
2895 if (Parser.getTok().is(AsmToken::RBrac)) {
2896 // "Dn[]" is the 'all lanes' syntax.
2897 LaneKind = AllLanes;
2898 Parser.Lex(); // Eat the ']'.
2899 return MatchOperand_Success;
2900 }
Jim Grosbachc9313252011-12-21 01:19:23 +00002901 const MCExpr *LaneIndex;
2902 SMLoc Loc = Parser.getTok().getLoc();
2903 if (getParser().ParseExpression(LaneIndex)) {
2904 Error(Loc, "illegal expression");
2905 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002906 }
Jim Grosbachc9313252011-12-21 01:19:23 +00002907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2908 if (!CE) {
2909 Error(Loc, "lane index must be empty or an integer");
2910 return MatchOperand_ParseFail;
2911 }
2912 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2913 Error(Parser.getTok().getLoc(), "']' expected");
2914 return MatchOperand_ParseFail;
2915 }
2916 Parser.Lex(); // Eat the ']'.
2917 int64_t Val = CE->getValue();
2918
2919 // FIXME: Make this range check context sensitive for .8, .16, .32.
2920 if (Val < 0 || Val > 7) {
2921 Error(Parser.getTok().getLoc(), "lane index out of range");
2922 return MatchOperand_ParseFail;
2923 }
2924 Index = Val;
2925 LaneKind = IndexedLane;
2926 return MatchOperand_Success;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002927 }
2928 LaneKind = NoLanes;
2929 return MatchOperand_Success;
2930}
2931
Jim Grosbach862019c2011-10-18 23:02:30 +00002932// parse a vector register list
2933ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2934parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00002935 VectorLaneTy LaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002936 unsigned LaneIndex;
Jim Grosbach5c984e42011-11-15 21:45:55 +00002937 SMLoc S = Parser.getTok().getLoc();
2938 // As an extension (to match gas), support a plain D register or Q register
2939 // (without encosing curly braces) as a single or double entry list,
2940 // respectively.
2941 if (Parser.getTok().is(AsmToken::Identifier)) {
2942 int Reg = tryParseRegister();
2943 if (Reg == -1)
2944 return MatchOperand_NoMatch;
2945 SMLoc E = Parser.getTok().getLoc();
2946 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00002947 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00002948 if (Res != MatchOperand_Success)
2949 return Res;
2950 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00002951 case NoLanes:
2952 E = Parser.getTok().getLoc();
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002953 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00002954 break;
2955 case AllLanes:
2956 E = Parser.getTok().getLoc();
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002957 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
2958 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00002959 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002960 case IndexedLane:
2961 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002962 LaneIndex,
2963 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00002964 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002965 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00002966 return MatchOperand_Success;
2967 }
2968 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2969 Reg = getDRegFromQReg(Reg);
Jim Grosbach7636bf62011-12-02 00:35:16 +00002970 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00002971 if (Res != MatchOperand_Success)
2972 return Res;
2973 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00002974 case NoLanes:
2975 E = Parser.getTok().getLoc();
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002976 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00002977 break;
2978 case AllLanes:
2979 E = Parser.getTok().getLoc();
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002980 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
2981 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00002982 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002983 case IndexedLane:
2984 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002985 LaneIndex,
2986 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00002987 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002988 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00002989 return MatchOperand_Success;
2990 }
2991 Error(S, "vector register expected");
2992 return MatchOperand_ParseFail;
2993 }
2994
2995 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbach862019c2011-10-18 23:02:30 +00002996 return MatchOperand_NoMatch;
2997
Jim Grosbach862019c2011-10-18 23:02:30 +00002998 Parser.Lex(); // Eat '{' token.
2999 SMLoc RegLoc = Parser.getTok().getLoc();
3000
3001 int Reg = tryParseRegister();
3002 if (Reg == -1) {
3003 Error(RegLoc, "register expected");
3004 return MatchOperand_ParseFail;
3005 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003006 unsigned Count = 1;
Jim Grosbach276ed032011-12-15 21:54:55 +00003007 int Spacing = 0;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003008 unsigned FirstReg = Reg;
3009 // The list is of D registers, but we also allow Q regs and just interpret
3010 // them as the two D sub-registers.
3011 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3012 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003013 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3014 // it's ambiguous with four-register single spaced.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003015 ++Reg;
3016 ++Count;
3017 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00003018 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003019 return MatchOperand_ParseFail;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003020
Jim Grosbache43862b2011-11-15 23:19:15 +00003021 while (Parser.getTok().is(AsmToken::Comma) ||
3022 Parser.getTok().is(AsmToken::Minus)) {
3023 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003024 if (!Spacing)
3025 Spacing = 1; // Register range implies a single spaced list.
3026 else if (Spacing == 2) {
3027 Error(Parser.getTok().getLoc(),
3028 "sequential registers in double spaced list");
3029 return MatchOperand_ParseFail;
3030 }
Jim Grosbache43862b2011-11-15 23:19:15 +00003031 Parser.Lex(); // Eat the minus.
3032 SMLoc EndLoc = Parser.getTok().getLoc();
3033 int EndReg = tryParseRegister();
3034 if (EndReg == -1) {
3035 Error(EndLoc, "register expected");
3036 return MatchOperand_ParseFail;
3037 }
3038 // Allow Q regs and just interpret them as the two D sub-registers.
3039 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3040 EndReg = getDRegFromQReg(EndReg) + 1;
3041 // If the register is the same as the start reg, there's nothing
3042 // more to do.
3043 if (Reg == EndReg)
3044 continue;
3045 // The register must be in the same register class as the first.
3046 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3047 Error(EndLoc, "invalid register in register list");
3048 return MatchOperand_ParseFail;
3049 }
3050 // Ranges must go from low to high.
3051 if (Reg > EndReg) {
3052 Error(EndLoc, "bad range in register list");
3053 return MatchOperand_ParseFail;
3054 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003055 // Parse the lane specifier if present.
3056 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003057 unsigned NextLaneIndex;
3058 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003059 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003060 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003061 Error(EndLoc, "mismatched lane index in register list");
3062 return MatchOperand_ParseFail;
3063 }
3064 EndLoc = Parser.getTok().getLoc();
Jim Grosbache43862b2011-11-15 23:19:15 +00003065
3066 // Add all the registers in the range to the register list.
3067 Count += EndReg - Reg;
3068 Reg = EndReg;
3069 continue;
3070 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003071 Parser.Lex(); // Eat the comma.
3072 RegLoc = Parser.getTok().getLoc();
3073 int OldReg = Reg;
3074 Reg = tryParseRegister();
3075 if (Reg == -1) {
3076 Error(RegLoc, "register expected");
3077 return MatchOperand_ParseFail;
3078 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003079 // vector register lists must be contiguous.
Jim Grosbach862019c2011-10-18 23:02:30 +00003080 // It's OK to use the enumeration values directly here rather, as the
3081 // VFP register classes have the enum sorted properly.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003082 //
3083 // The list is of D registers, but we also allow Q regs and just interpret
3084 // them as the two D sub-registers.
3085 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003086 if (!Spacing)
3087 Spacing = 1; // Register range implies a single spaced list.
3088 else if (Spacing == 2) {
3089 Error(RegLoc,
3090 "invalid register in double-spaced list (must be 'D' register')");
3091 return MatchOperand_ParseFail;
3092 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003093 Reg = getDRegFromQReg(Reg);
3094 if (Reg != OldReg + 1) {
3095 Error(RegLoc, "non-contiguous register range");
3096 return MatchOperand_ParseFail;
3097 }
3098 ++Reg;
3099 Count += 2;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003100 // Parse the lane specifier if present.
3101 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003102 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003103 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003104 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003105 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003106 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003107 Error(EndLoc, "mismatched lane index in register list");
3108 return MatchOperand_ParseFail;
3109 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003110 continue;
3111 }
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003112 // Normal D register.
3113 // Figure out the register spacing (single or double) of the list if
3114 // we don't know it already.
3115 if (!Spacing)
3116 Spacing = 1 + (Reg == OldReg + 2);
3117
3118 // Just check that it's contiguous and keep going.
3119 if (Reg != OldReg + Spacing) {
Jim Grosbach862019c2011-10-18 23:02:30 +00003120 Error(RegLoc, "non-contiguous register range");
3121 return MatchOperand_ParseFail;
3122 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003123 ++Count;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003124 // Parse the lane specifier if present.
3125 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003126 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003127 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003128 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003129 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003130 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003131 Error(EndLoc, "mismatched lane index in register list");
3132 return MatchOperand_ParseFail;
3133 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003134 }
3135
3136 SMLoc E = Parser.getTok().getLoc();
3137 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3138 Error(E, "'}' expected");
3139 return MatchOperand_ParseFail;
3140 }
3141 Parser.Lex(); // Eat '}' token.
3142
Jim Grosbach98b05a52011-11-30 01:09:44 +00003143 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003144 case NoLanes:
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003145 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3146 (Spacing == 2), S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003147 break;
3148 case AllLanes:
3149 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003150 (Spacing == 2),
Jim Grosbach98b05a52011-11-30 01:09:44 +00003151 S, E));
3152 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003153 case IndexedLane:
3154 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003155 LaneIndex,
3156 (Spacing == 2),
3157 S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003158 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003159 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003160 return MatchOperand_Success;
3161}
3162
Jim Grosbach43904292011-07-25 20:14:50 +00003163/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbachf922c472011-02-12 01:34:40 +00003164ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003165parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003166 SMLoc S = Parser.getTok().getLoc();
3167 const AsmToken &Tok = Parser.getTok();
3168 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3169 StringRef OptStr = Tok.getString();
3170
3171 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()))
3172 .Case("sy", ARM_MB::SY)
3173 .Case("st", ARM_MB::ST)
Jim Grosbach032434d2011-07-13 23:40:38 +00003174 .Case("sh", ARM_MB::ISH)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003175 .Case("ish", ARM_MB::ISH)
Jim Grosbach032434d2011-07-13 23:40:38 +00003176 .Case("shst", ARM_MB::ISHST)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003177 .Case("ishst", ARM_MB::ISHST)
3178 .Case("nsh", ARM_MB::NSH)
Jim Grosbach032434d2011-07-13 23:40:38 +00003179 .Case("un", ARM_MB::NSH)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003180 .Case("nshst", ARM_MB::NSHST)
Jim Grosbach032434d2011-07-13 23:40:38 +00003181 .Case("unst", ARM_MB::NSHST)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003182 .Case("osh", ARM_MB::OSH)
3183 .Case("oshst", ARM_MB::OSHST)
3184 .Default(~0U);
3185
3186 if (Opt == ~0U)
Jim Grosbachf922c472011-02-12 01:34:40 +00003187 return MatchOperand_NoMatch;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003188
3189 Parser.Lex(); // Eat identifier token.
3190 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00003191 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003192}
3193
Jim Grosbach43904292011-07-25 20:14:50 +00003194/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003195ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003196parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003197 SMLoc S = Parser.getTok().getLoc();
3198 const AsmToken &Tok = Parser.getTok();
3199 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3200 StringRef IFlagsStr = Tok.getString();
3201
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003202 // An iflags string of "none" is interpreted to mean that none of the AIF
3203 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003204 unsigned IFlags = 0;
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003205 if (IFlagsStr != "none") {
3206 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3207 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3208 .Case("a", ARM_PROC::A)
3209 .Case("i", ARM_PROC::I)
3210 .Case("f", ARM_PROC::F)
3211 .Default(~0U);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003212
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003213 // If some specific iflag is already set, it means that some letter is
3214 // present more than once, this is not acceptable.
3215 if (Flag == ~0U || (IFlags & Flag))
3216 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003217
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003218 IFlags |= Flag;
3219 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003220 }
3221
3222 Parser.Lex(); // Eat identifier token.
3223 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3224 return MatchOperand_Success;
3225}
3226
Jim Grosbach43904292011-07-25 20:14:50 +00003227/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003228ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003229parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003230 SMLoc S = Parser.getTok().getLoc();
3231 const AsmToken &Tok = Parser.getTok();
3232 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3233 StringRef Mask = Tok.getString();
3234
James Molloyacad68d2011-09-28 14:21:38 +00003235 if (isMClass()) {
3236 // See ARMv6-M 10.1.1
3237 unsigned FlagsVal = StringSwitch<unsigned>(Mask)
3238 .Case("apsr", 0)
3239 .Case("iapsr", 1)
3240 .Case("eapsr", 2)
3241 .Case("xpsr", 3)
3242 .Case("ipsr", 5)
3243 .Case("epsr", 6)
3244 .Case("iepsr", 7)
3245 .Case("msp", 8)
3246 .Case("psp", 9)
3247 .Case("primask", 16)
3248 .Case("basepri", 17)
3249 .Case("basepri_max", 18)
3250 .Case("faultmask", 19)
3251 .Case("control", 20)
3252 .Default(~0U);
Jim Grosbach18c8d122011-12-22 17:17:10 +00003253
James Molloyacad68d2011-09-28 14:21:38 +00003254 if (FlagsVal == ~0U)
3255 return MatchOperand_NoMatch;
3256
3257 if (!hasV7Ops() && FlagsVal >= 17 && FlagsVal <= 19)
3258 // basepri, basepri_max and faultmask only valid for V7m.
3259 return MatchOperand_NoMatch;
Jim Grosbach18c8d122011-12-22 17:17:10 +00003260
James Molloyacad68d2011-09-28 14:21:38 +00003261 Parser.Lex(); // Eat identifier token.
3262 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3263 return MatchOperand_Success;
3264 }
3265
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003266 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3267 size_t Start = 0, Next = Mask.find('_');
3268 StringRef Flags = "";
Benjamin Kramer59085362011-11-06 20:37:06 +00003269 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003270 if (Next != StringRef::npos)
3271 Flags = Mask.slice(Next+1, Mask.size());
3272
3273 // FlagsVal contains the complete mask:
3274 // 3-0: Mask
3275 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3276 unsigned FlagsVal = 0;
3277
3278 if (SpecReg == "apsr") {
3279 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +00003280 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003281 .Case("g", 0x4) // same as CPSR_s
3282 .Case("nzcvqg", 0xc) // same as CPSR_fs
3283 .Default(~0U);
3284
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003285 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003286 if (!Flags.empty())
3287 return MatchOperand_NoMatch;
3288 else
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003289 FlagsVal = 8; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003290 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003291 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00003292 if (Flags == "all") // cpsr_all is an alias for cpsr_fc
3293 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003294 for (int i = 0, e = Flags.size(); i != e; ++i) {
3295 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3296 .Case("c", 1)
3297 .Case("x", 2)
3298 .Case("s", 4)
3299 .Case("f", 8)
3300 .Default(~0U);
3301
3302 // If some specific flag is already set, it means that some letter is
3303 // present more than once, this is not acceptable.
3304 if (FlagsVal == ~0U || (FlagsVal & Flag))
3305 return MatchOperand_NoMatch;
3306 FlagsVal |= Flag;
3307 }
3308 } else // No match for special register.
3309 return MatchOperand_NoMatch;
3310
Owen Anderson7784f1d2011-10-21 18:43:28 +00003311 // Special register without flags is NOT equivalent to "fc" flags.
3312 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3313 // two lines would enable gas compatibility at the expense of breaking
3314 // round-tripping.
3315 //
3316 // if (!FlagsVal)
3317 // FlagsVal = 0x9;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003318
3319 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3320 if (SpecReg == "spsr")
3321 FlagsVal |= 16;
3322
3323 Parser.Lex(); // Eat identifier token.
3324 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3325 return MatchOperand_Success;
3326}
3327
Jim Grosbachf6c05252011-07-21 17:23:04 +00003328ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3329parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3330 int Low, int High) {
3331 const AsmToken &Tok = Parser.getTok();
3332 if (Tok.isNot(AsmToken::Identifier)) {
3333 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3334 return MatchOperand_ParseFail;
3335 }
3336 StringRef ShiftName = Tok.getString();
Benjamin Kramer59085362011-11-06 20:37:06 +00003337 std::string LowerOp = Op.lower();
3338 std::string UpperOp = Op.upper();
Jim Grosbachf6c05252011-07-21 17:23:04 +00003339 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3340 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3341 return MatchOperand_ParseFail;
3342 }
3343 Parser.Lex(); // Eat shift type token.
3344
3345 // There must be a '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003346 if (Parser.getTok().isNot(AsmToken::Hash) &&
3347 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbachf6c05252011-07-21 17:23:04 +00003348 Error(Parser.getTok().getLoc(), "'#' expected");
3349 return MatchOperand_ParseFail;
3350 }
3351 Parser.Lex(); // Eat hash token.
3352
3353 const MCExpr *ShiftAmount;
3354 SMLoc Loc = Parser.getTok().getLoc();
3355 if (getParser().ParseExpression(ShiftAmount)) {
3356 Error(Loc, "illegal expression");
3357 return MatchOperand_ParseFail;
3358 }
3359 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3360 if (!CE) {
3361 Error(Loc, "constant expression expected");
3362 return MatchOperand_ParseFail;
3363 }
3364 int Val = CE->getValue();
3365 if (Val < Low || Val > High) {
3366 Error(Loc, "immediate value out of range");
3367 return MatchOperand_ParseFail;
3368 }
3369
3370 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3371
3372 return MatchOperand_Success;
3373}
3374
Jim Grosbachc27d4f92011-07-22 17:44:50 +00003375ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3376parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3377 const AsmToken &Tok = Parser.getTok();
3378 SMLoc S = Tok.getLoc();
3379 if (Tok.isNot(AsmToken::Identifier)) {
3380 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3381 return MatchOperand_ParseFail;
3382 }
3383 int Val = StringSwitch<int>(Tok.getString())
3384 .Case("be", 1)
3385 .Case("le", 0)
3386 .Default(-1);
3387 Parser.Lex(); // Eat the token.
3388
3389 if (Val == -1) {
3390 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3391 return MatchOperand_ParseFail;
3392 }
3393 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3394 getContext()),
3395 S, Parser.getTok().getLoc()));
3396 return MatchOperand_Success;
3397}
3398
Jim Grosbach580f4a92011-07-25 22:20:28 +00003399/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3400/// instructions. Legal values are:
3401/// lsl #n 'n' in [0,31]
3402/// asr #n 'n' in [1,32]
3403/// n == 32 encoded as n == 0.
3404ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3405parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3406 const AsmToken &Tok = Parser.getTok();
3407 SMLoc S = Tok.getLoc();
3408 if (Tok.isNot(AsmToken::Identifier)) {
3409 Error(S, "shift operator 'asr' or 'lsl' expected");
3410 return MatchOperand_ParseFail;
3411 }
3412 StringRef ShiftName = Tok.getString();
3413 bool isASR;
3414 if (ShiftName == "lsl" || ShiftName == "LSL")
3415 isASR = false;
3416 else if (ShiftName == "asr" || ShiftName == "ASR")
3417 isASR = true;
3418 else {
3419 Error(S, "shift operator 'asr' or 'lsl' expected");
3420 return MatchOperand_ParseFail;
3421 }
3422 Parser.Lex(); // Eat the operator.
3423
3424 // A '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003425 if (Parser.getTok().isNot(AsmToken::Hash) &&
3426 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach580f4a92011-07-25 22:20:28 +00003427 Error(Parser.getTok().getLoc(), "'#' expected");
3428 return MatchOperand_ParseFail;
3429 }
3430 Parser.Lex(); // Eat hash token.
3431
3432 const MCExpr *ShiftAmount;
3433 SMLoc E = Parser.getTok().getLoc();
3434 if (getParser().ParseExpression(ShiftAmount)) {
3435 Error(E, "malformed shift expression");
3436 return MatchOperand_ParseFail;
3437 }
3438 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3439 if (!CE) {
3440 Error(E, "shift amount must be an immediate");
3441 return MatchOperand_ParseFail;
3442 }
3443
3444 int64_t Val = CE->getValue();
3445 if (isASR) {
3446 // Shift amount must be in [1,32]
3447 if (Val < 1 || Val > 32) {
3448 Error(E, "'asr' shift amount must be in range [1,32]");
3449 return MatchOperand_ParseFail;
3450 }
Owen Anderson0afa0092011-09-26 21:06:22 +00003451 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3452 if (isThumb() && Val == 32) {
3453 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3454 return MatchOperand_ParseFail;
3455 }
Jim Grosbach580f4a92011-07-25 22:20:28 +00003456 if (Val == 32) Val = 0;
3457 } else {
3458 // Shift amount must be in [1,32]
3459 if (Val < 0 || Val > 31) {
3460 Error(E, "'lsr' shift amount must be in range [0,31]");
3461 return MatchOperand_ParseFail;
3462 }
3463 }
3464
3465 E = Parser.getTok().getLoc();
3466 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3467
3468 return MatchOperand_Success;
3469}
3470
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003471/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3472/// of instructions. Legal values are:
3473/// ror #n 'n' in {0, 8, 16, 24}
3474ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3475parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3476 const AsmToken &Tok = Parser.getTok();
3477 SMLoc S = Tok.getLoc();
Jim Grosbach326efe52011-09-19 20:29:33 +00003478 if (Tok.isNot(AsmToken::Identifier))
3479 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003480 StringRef ShiftName = Tok.getString();
Jim Grosbach326efe52011-09-19 20:29:33 +00003481 if (ShiftName != "ror" && ShiftName != "ROR")
3482 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003483 Parser.Lex(); // Eat the operator.
3484
3485 // A '#' and a rotate amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003486 if (Parser.getTok().isNot(AsmToken::Hash) &&
3487 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003488 Error(Parser.getTok().getLoc(), "'#' expected");
3489 return MatchOperand_ParseFail;
3490 }
3491 Parser.Lex(); // Eat hash token.
3492
3493 const MCExpr *ShiftAmount;
3494 SMLoc E = Parser.getTok().getLoc();
3495 if (getParser().ParseExpression(ShiftAmount)) {
3496 Error(E, "malformed rotate expression");
3497 return MatchOperand_ParseFail;
3498 }
3499 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3500 if (!CE) {
3501 Error(E, "rotate amount must be an immediate");
3502 return MatchOperand_ParseFail;
3503 }
3504
3505 int64_t Val = CE->getValue();
3506 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3507 // normally, zero is represented in asm by omitting the rotate operand
3508 // entirely.
3509 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3510 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3511 return MatchOperand_ParseFail;
3512 }
3513
3514 E = Parser.getTok().getLoc();
3515 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3516
3517 return MatchOperand_Success;
3518}
3519
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003520ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3521parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3522 SMLoc S = Parser.getTok().getLoc();
3523 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003524 if (Parser.getTok().isNot(AsmToken::Hash) &&
3525 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003526 Error(Parser.getTok().getLoc(), "'#' expected");
3527 return MatchOperand_ParseFail;
3528 }
3529 Parser.Lex(); // Eat hash token.
3530
3531 const MCExpr *LSBExpr;
3532 SMLoc E = Parser.getTok().getLoc();
3533 if (getParser().ParseExpression(LSBExpr)) {
3534 Error(E, "malformed immediate expression");
3535 return MatchOperand_ParseFail;
3536 }
3537 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3538 if (!CE) {
3539 Error(E, "'lsb' operand must be an immediate");
3540 return MatchOperand_ParseFail;
3541 }
3542
3543 int64_t LSB = CE->getValue();
3544 // The LSB must be in the range [0,31]
3545 if (LSB < 0 || LSB > 31) {
3546 Error(E, "'lsb' operand must be in the range [0,31]");
3547 return MatchOperand_ParseFail;
3548 }
3549 E = Parser.getTok().getLoc();
3550
3551 // Expect another immediate operand.
3552 if (Parser.getTok().isNot(AsmToken::Comma)) {
3553 Error(Parser.getTok().getLoc(), "too few operands");
3554 return MatchOperand_ParseFail;
3555 }
3556 Parser.Lex(); // Eat hash token.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003557 if (Parser.getTok().isNot(AsmToken::Hash) &&
3558 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003559 Error(Parser.getTok().getLoc(), "'#' expected");
3560 return MatchOperand_ParseFail;
3561 }
3562 Parser.Lex(); // Eat hash token.
3563
3564 const MCExpr *WidthExpr;
3565 if (getParser().ParseExpression(WidthExpr)) {
3566 Error(E, "malformed immediate expression");
3567 return MatchOperand_ParseFail;
3568 }
3569 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3570 if (!CE) {
3571 Error(E, "'width' operand must be an immediate");
3572 return MatchOperand_ParseFail;
3573 }
3574
3575 int64_t Width = CE->getValue();
3576 // The LSB must be in the range [1,32-lsb]
3577 if (Width < 1 || Width > 32 - LSB) {
3578 Error(E, "'width' operand must be in the range [1,32-lsb]");
3579 return MatchOperand_ParseFail;
3580 }
3581 E = Parser.getTok().getLoc();
3582
3583 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3584
3585 return MatchOperand_Success;
3586}
3587
Jim Grosbach7ce05792011-08-03 23:50:40 +00003588ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3589parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3590 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003591 // postidx_reg := '+' register {, shift}
3592 // | '-' register {, shift}
3593 // | register {, shift}
Jim Grosbach7ce05792011-08-03 23:50:40 +00003594
3595 // This method must return MatchOperand_NoMatch without consuming any tokens
3596 // in the case where there is no match, as other alternatives take other
3597 // parse methods.
3598 AsmToken Tok = Parser.getTok();
3599 SMLoc S = Tok.getLoc();
3600 bool haveEaten = false;
Jim Grosbach16578b52011-08-05 16:11:38 +00003601 bool isAdd = true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003602 int Reg = -1;
3603 if (Tok.is(AsmToken::Plus)) {
3604 Parser.Lex(); // Eat the '+' token.
3605 haveEaten = true;
3606 } else if (Tok.is(AsmToken::Minus)) {
3607 Parser.Lex(); // Eat the '-' token.
Jim Grosbach16578b52011-08-05 16:11:38 +00003608 isAdd = false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003609 haveEaten = true;
3610 }
3611 if (Parser.getTok().is(AsmToken::Identifier))
3612 Reg = tryParseRegister();
3613 if (Reg == -1) {
3614 if (!haveEaten)
3615 return MatchOperand_NoMatch;
3616 Error(Parser.getTok().getLoc(), "register expected");
3617 return MatchOperand_ParseFail;
3618 }
3619 SMLoc E = Parser.getTok().getLoc();
3620
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003621 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3622 unsigned ShiftImm = 0;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00003623 if (Parser.getTok().is(AsmToken::Comma)) {
3624 Parser.Lex(); // Eat the ','.
3625 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3626 return MatchOperand_ParseFail;
3627 }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003628
3629 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3630 ShiftImm, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003631
3632 return MatchOperand_Success;
3633}
3634
Jim Grosbach251bf252011-08-10 21:56:18 +00003635ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3636parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3637 // Check for a post-index addressing register operand. Specifically:
3638 // am3offset := '+' register
3639 // | '-' register
3640 // | register
3641 // | # imm
3642 // | # + imm
3643 // | # - imm
3644
3645 // This method must return MatchOperand_NoMatch without consuming any tokens
3646 // in the case where there is no match, as other alternatives take other
3647 // parse methods.
3648 AsmToken Tok = Parser.getTok();
3649 SMLoc S = Tok.getLoc();
3650
3651 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003652 if (Parser.getTok().is(AsmToken::Hash) ||
3653 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach251bf252011-08-10 21:56:18 +00003654 Parser.Lex(); // Eat the '#'.
3655 // Explicitly look for a '-', as we need to encode negative zero
3656 // differently.
3657 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3658 const MCExpr *Offset;
3659 if (getParser().ParseExpression(Offset))
3660 return MatchOperand_ParseFail;
3661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3662 if (!CE) {
3663 Error(S, "constant expression expected");
3664 return MatchOperand_ParseFail;
3665 }
3666 SMLoc E = Tok.getLoc();
3667 // Negative zero is encoded as the flag value INT32_MIN.
3668 int32_t Val = CE->getValue();
3669 if (isNegative && Val == 0)
3670 Val = INT32_MIN;
3671
3672 Operands.push_back(
3673 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3674
3675 return MatchOperand_Success;
3676 }
3677
3678
3679 bool haveEaten = false;
3680 bool isAdd = true;
3681 int Reg = -1;
3682 if (Tok.is(AsmToken::Plus)) {
3683 Parser.Lex(); // Eat the '+' token.
3684 haveEaten = true;
3685 } else if (Tok.is(AsmToken::Minus)) {
3686 Parser.Lex(); // Eat the '-' token.
3687 isAdd = false;
3688 haveEaten = true;
3689 }
3690 if (Parser.getTok().is(AsmToken::Identifier))
3691 Reg = tryParseRegister();
3692 if (Reg == -1) {
3693 if (!haveEaten)
3694 return MatchOperand_NoMatch;
3695 Error(Parser.getTok().getLoc(), "register expected");
3696 return MatchOperand_ParseFail;
3697 }
3698 SMLoc E = Parser.getTok().getLoc();
3699
3700 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3701 0, S, E));
3702
3703 return MatchOperand_Success;
3704}
3705
Jim Grosbacha77295d2011-09-08 22:07:06 +00003706/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3707/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3708/// when they refer multiple MIOperands inside a single one.
3709bool ARMAsmParser::
3710cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
3711 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3712 // Rt, Rt2
3713 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3714 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3715 // Create a writeback register dummy placeholder.
3716 Inst.addOperand(MCOperand::CreateReg(0));
3717 // addr
3718 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3719 // pred
3720 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3721 return true;
3722}
3723
3724/// cvtT2StrdPre - Convert parsed operands to MCInst.
3725/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3726/// when they refer multiple MIOperands inside a single one.
3727bool ARMAsmParser::
3728cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
3729 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3730 // Create a writeback register dummy placeholder.
3731 Inst.addOperand(MCOperand::CreateReg(0));
3732 // Rt, Rt2
3733 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3734 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3735 // addr
3736 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3737 // pred
3738 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3739 return true;
3740}
3741
Jim Grosbacheeec0252011-09-08 00:39:19 +00003742/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3743/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3744/// when they refer multiple MIOperands inside a single one.
3745bool ARMAsmParser::
3746cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3747 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3748 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3749
3750 // Create a writeback register dummy placeholder.
3751 Inst.addOperand(MCOperand::CreateImm(0));
3752
3753 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3754 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3755 return true;
3756}
3757
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003758/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3759/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3760/// when they refer multiple MIOperands inside a single one.
3761bool ARMAsmParser::
3762cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3763 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3764 // Create a writeback register dummy placeholder.
3765 Inst.addOperand(MCOperand::CreateImm(0));
3766 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3767 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3768 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3769 return true;
3770}
3771
Jim Grosbach1355cf12011-07-26 17:10:22 +00003772/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003773/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3774/// when they refer multiple MIOperands inside a single one.
3775bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003776cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003777 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3778 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3779
3780 // Create a writeback register dummy placeholder.
3781 Inst.addOperand(MCOperand::CreateImm(0));
3782
Jim Grosbach7ce05792011-08-03 23:50:40 +00003783 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003784 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3785 return true;
3786}
3787
Owen Anderson9ab0f252011-08-26 20:43:14 +00003788/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3789/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3790/// when they refer multiple MIOperands inside a single one.
3791bool ARMAsmParser::
3792cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3793 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3794 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3795
3796 // Create a writeback register dummy placeholder.
3797 Inst.addOperand(MCOperand::CreateImm(0));
3798
3799 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3800 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3801 return true;
3802}
3803
3804
Jim Grosbach548340c2011-08-11 19:22:40 +00003805/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3806/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3807/// when they refer multiple MIOperands inside a single one.
3808bool ARMAsmParser::
3809cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3810 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3811 // Create a writeback register dummy placeholder.
3812 Inst.addOperand(MCOperand::CreateImm(0));
3813 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3814 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3815 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3816 return true;
3817}
3818
Jim Grosbach1355cf12011-07-26 17:10:22 +00003819/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003820/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3821/// when they refer multiple MIOperands inside a single one.
3822bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003823cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003824 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3825 // Create a writeback register dummy placeholder.
3826 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach548340c2011-08-11 19:22:40 +00003827 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3828 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3829 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003830 return true;
3831}
3832
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00003833/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3834/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3835/// when they refer multiple MIOperands inside a single one.
3836bool ARMAsmParser::
3837cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3838 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3839 // Create a writeback register dummy placeholder.
3840 Inst.addOperand(MCOperand::CreateImm(0));
3841 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3842 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3843 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3844 return true;
3845}
3846
Jim Grosbach7ce05792011-08-03 23:50:40 +00003847/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
3848/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3849/// when they refer multiple MIOperands inside a single one.
3850bool ARMAsmParser::
3851cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3852 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3853 // Rt
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003854 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003855 // Create a writeback register dummy placeholder.
3856 Inst.addOperand(MCOperand::CreateImm(0));
3857 // addr
3858 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3859 // offset
3860 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3861 // pred
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003862 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3863 return true;
3864}
3865
Jim Grosbach7ce05792011-08-03 23:50:40 +00003866/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003867/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3868/// when they refer multiple MIOperands inside a single one.
3869bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00003870cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3871 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3872 // Rt
Owen Andersonaa3402e2011-07-28 17:18:57 +00003873 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003874 // Create a writeback register dummy placeholder.
3875 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003876 // addr
3877 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3878 // offset
3879 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3880 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003881 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3882 return true;
3883}
3884
Jim Grosbach7ce05792011-08-03 23:50:40 +00003885/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003886/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3887/// when they refer multiple MIOperands inside a single one.
3888bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00003889cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3890 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003891 // Create a writeback register dummy placeholder.
3892 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003893 // Rt
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003894 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003895 // addr
3896 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3897 // offset
3898 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3899 // pred
3900 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3901 return true;
3902}
3903
3904/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
3905/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3906/// when they refer multiple MIOperands inside a single one.
3907bool ARMAsmParser::
3908cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3909 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3910 // Create a writeback register dummy placeholder.
3911 Inst.addOperand(MCOperand::CreateImm(0));
3912 // Rt
3913 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3914 // addr
3915 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3916 // offset
3917 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3918 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003919 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3920 return true;
3921}
3922
Jim Grosbach2fd2b872011-08-10 20:29:19 +00003923/// cvtLdrdPre - Convert parsed operands to MCInst.
3924/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3925/// when they refer multiple MIOperands inside a single one.
3926bool ARMAsmParser::
3927cvtLdrdPre(MCInst &Inst, unsigned Opcode,
3928 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3929 // Rt, Rt2
3930 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3931 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3932 // Create a writeback register dummy placeholder.
3933 Inst.addOperand(MCOperand::CreateImm(0));
3934 // addr
3935 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3936 // pred
3937 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3938 return true;
3939}
3940
Jim Grosbach14605d12011-08-11 20:28:23 +00003941/// cvtStrdPre - Convert parsed operands to MCInst.
3942/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3943/// when they refer multiple MIOperands inside a single one.
3944bool ARMAsmParser::
3945cvtStrdPre(MCInst &Inst, unsigned Opcode,
3946 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3947 // Create a writeback register dummy placeholder.
3948 Inst.addOperand(MCOperand::CreateImm(0));
3949 // Rt, Rt2
3950 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3951 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3952 // addr
3953 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3954 // pred
3955 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3956 return true;
3957}
3958
Jim Grosbach623a4542011-08-10 22:42:16 +00003959/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3960/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3961/// when they refer multiple MIOperands inside a single one.
3962bool ARMAsmParser::
3963cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3964 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3965 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3966 // Create a writeback register dummy placeholder.
3967 Inst.addOperand(MCOperand::CreateImm(0));
3968 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3969 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3970 return true;
3971}
3972
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00003973/// cvtThumbMultiple- Convert parsed operands to MCInst.
3974/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3975/// when they refer multiple MIOperands inside a single one.
3976bool ARMAsmParser::
3977cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
3978 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3979 // The second source operand must be the same register as the destination
3980 // operand.
3981 if (Operands.size() == 6 &&
Jim Grosbach7a010692011-08-19 22:30:46 +00003982 (((ARMOperand*)Operands[3])->getReg() !=
3983 ((ARMOperand*)Operands[5])->getReg()) &&
3984 (((ARMOperand*)Operands[3])->getReg() !=
3985 ((ARMOperand*)Operands[4])->getReg())) {
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00003986 Error(Operands[3]->getStartLoc(),
Jim Grosbach7a010692011-08-19 22:30:46 +00003987 "destination register must match source register");
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00003988 return false;
3989 }
3990 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3991 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach1b332862011-11-10 22:10:12 +00003992 // If we have a three-operand form, make sure to set Rn to be the operand
3993 // that isn't the same as Rd.
3994 unsigned RegOp = 4;
3995 if (Operands.size() == 6 &&
3996 ((ARMOperand*)Operands[4])->getReg() ==
3997 ((ARMOperand*)Operands[3])->getReg())
3998 RegOp = 5;
3999 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4000 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004001 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4002
4003 return true;
4004}
Jim Grosbach623a4542011-08-10 22:42:16 +00004005
Jim Grosbach12431322011-10-24 22:16:58 +00004006bool ARMAsmParser::
4007cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
4008 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4009 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004010 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004011 // Create a writeback register dummy placeholder.
4012 Inst.addOperand(MCOperand::CreateImm(0));
4013 // Vn
4014 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4015 // pred
4016 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4017 return true;
4018}
4019
4020bool ARMAsmParser::
4021cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
4022 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4023 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004024 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004025 // Create a writeback register dummy placeholder.
4026 Inst.addOperand(MCOperand::CreateImm(0));
4027 // Vn
4028 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4029 // Vm
4030 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4031 // pred
4032 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4033 return true;
4034}
4035
Jim Grosbach4334e032011-10-31 21:50:31 +00004036bool ARMAsmParser::
4037cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
4038 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4039 // Create a writeback register dummy placeholder.
4040 Inst.addOperand(MCOperand::CreateImm(0));
4041 // Vn
4042 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4043 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004044 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004045 // pred
4046 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4047 return true;
4048}
4049
4050bool ARMAsmParser::
4051cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
4052 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4053 // Create a writeback register dummy placeholder.
4054 Inst.addOperand(MCOperand::CreateImm(0));
4055 // Vn
4056 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4057 // Vm
4058 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4059 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004060 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004061 // pred
4062 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4063 return true;
4064}
4065
Bill Wendlinge7176102010-11-06 22:36:58 +00004066/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004067/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00004068bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004069parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +00004070 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00004071 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00004072 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00004073 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004074 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004075
Sean Callanan18b83232010-01-19 21:44:56 +00004076 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbach1355cf12011-07-26 17:10:22 +00004077 int BaseRegNum = tryParseRegister();
Jim Grosbach7ce05792011-08-03 23:50:40 +00004078 if (BaseRegNum == -1)
4079 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004080
Daniel Dunbar05710932011-01-18 05:34:17 +00004081 // The next token must either be a comma or a closing bracket.
4082 const AsmToken &Tok = Parser.getTok();
4083 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004084 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar05710932011-01-18 05:34:17 +00004085
Jim Grosbach7ce05792011-08-03 23:50:40 +00004086 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan76264762010-04-02 22:27:05 +00004087 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004088 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004089
Jim Grosbach7ce05792011-08-03 23:50:40 +00004090 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004091 0, 0, false, S, E));
Jim Grosbach03f44a02010-11-29 23:18:01 +00004092
Jim Grosbachfb12f352011-09-19 18:42:21 +00004093 // If there's a pre-indexing writeback marker, '!', just add it as a token
4094 // operand. It's rather odd, but syntactically valid.
4095 if (Parser.getTok().is(AsmToken::Exclaim)) {
4096 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4097 Parser.Lex(); // Eat the '!'.
4098 }
4099
Jim Grosbach7ce05792011-08-03 23:50:40 +00004100 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004101 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004102
Jim Grosbach7ce05792011-08-03 23:50:40 +00004103 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4104 Parser.Lex(); // Eat the comma.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004105
Jim Grosbach57dcb852011-10-11 17:29:55 +00004106 // If we have a ':', it's an alignment specifier.
4107 if (Parser.getTok().is(AsmToken::Colon)) {
4108 Parser.Lex(); // Eat the ':'.
4109 E = Parser.getTok().getLoc();
4110
4111 const MCExpr *Expr;
4112 if (getParser().ParseExpression(Expr))
4113 return true;
4114
4115 // The expression has to be a constant. Memory references with relocations
4116 // don't come through here, as they use the <label> forms of the relevant
4117 // instructions.
4118 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4119 if (!CE)
4120 return Error (E, "constant expression expected");
4121
4122 unsigned Align = 0;
4123 switch (CE->getValue()) {
4124 default:
Jim Grosbacheeaf1c12011-12-19 18:31:43 +00004125 return Error(E,
4126 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4127 case 16: Align = 2; break;
4128 case 32: Align = 4; break;
Jim Grosbach57dcb852011-10-11 17:29:55 +00004129 case 64: Align = 8; break;
4130 case 128: Align = 16; break;
4131 case 256: Align = 32; break;
4132 }
4133
4134 // Now we should have the closing ']'
4135 E = Parser.getTok().getLoc();
4136 if (Parser.getTok().isNot(AsmToken::RBrac))
4137 return Error(E, "']' expected");
4138 Parser.Lex(); // Eat right bracket token.
4139
4140 // Don't worry about range checking the value here. That's handled by
4141 // the is*() predicates.
4142 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4143 ARM_AM::no_shift, 0, Align,
4144 false, S, E));
4145
4146 // If there's a pre-indexing writeback marker, '!', just add it as a token
4147 // operand.
4148 if (Parser.getTok().is(AsmToken::Exclaim)) {
4149 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4150 Parser.Lex(); // Eat the '!'.
4151 }
4152
4153 return false;
4154 }
4155
4156 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004157 // offset. Be friendly and also accept a plain integer (without a leading
4158 // hash) for gas compatibility.
4159 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004160 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004161 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004162 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004163 Parser.Lex(); // Eat the '#'.
Jim Grosbach7ce05792011-08-03 23:50:40 +00004164 E = Parser.getTok().getLoc();
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004165
Owen Anderson0da10cf2011-08-29 19:36:44 +00004166 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004167 const MCExpr *Offset;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004168 if (getParser().ParseExpression(Offset))
4169 return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004170
4171 // The expression has to be a constant. Memory references with relocations
4172 // don't come through here, as they use the <label> forms of the relevant
4173 // instructions.
4174 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4175 if (!CE)
4176 return Error (E, "constant expression expected");
4177
Owen Anderson0da10cf2011-08-29 19:36:44 +00004178 // If the constant was #-0, represent it as INT32_MIN.
4179 int32_t Val = CE->getValue();
4180 if (isNegative && Val == 0)
4181 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4182
Jim Grosbach7ce05792011-08-03 23:50:40 +00004183 // Now we should have the closing ']'
4184 E = Parser.getTok().getLoc();
4185 if (Parser.getTok().isNot(AsmToken::RBrac))
4186 return Error(E, "']' expected");
4187 Parser.Lex(); // Eat right bracket token.
4188
4189 // Don't worry about range checking the value here. That's handled by
4190 // the is*() predicates.
4191 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004192 ARM_AM::no_shift, 0, 0,
4193 false, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004194
4195 // If there's a pre-indexing writeback marker, '!', just add it as a token
4196 // operand.
4197 if (Parser.getTok().is(AsmToken::Exclaim)) {
4198 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4199 Parser.Lex(); // Eat the '!'.
4200 }
4201
4202 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004203 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004204
4205 // The register offset is optionally preceded by a '+' or '-'
4206 bool isNegative = false;
4207 if (Parser.getTok().is(AsmToken::Minus)) {
4208 isNegative = true;
4209 Parser.Lex(); // Eat the '-'.
4210 } else if (Parser.getTok().is(AsmToken::Plus)) {
4211 // Nothing to do.
4212 Parser.Lex(); // Eat the '+'.
4213 }
4214
4215 E = Parser.getTok().getLoc();
4216 int OffsetRegNum = tryParseRegister();
4217 if (OffsetRegNum == -1)
4218 return Error(E, "register expected");
4219
4220 // If there's a shift operator, handle it.
4221 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004222 unsigned ShiftImm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004223 if (Parser.getTok().is(AsmToken::Comma)) {
4224 Parser.Lex(); // Eat the ','.
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004225 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004226 return true;
4227 }
4228
4229 // Now we should have the closing ']'
4230 E = Parser.getTok().getLoc();
4231 if (Parser.getTok().isNot(AsmToken::RBrac))
4232 return Error(E, "']' expected");
4233 Parser.Lex(); // Eat right bracket token.
4234
4235 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004236 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004237 S, E));
4238
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00004239 // If there's a pre-indexing writeback marker, '!', just add it as a token
4240 // operand.
4241 if (Parser.getTok().is(AsmToken::Exclaim)) {
4242 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4243 Parser.Lex(); // Eat the '!'.
4244 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004245
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004246 return false;
4247}
4248
Jim Grosbach7ce05792011-08-03 23:50:40 +00004249/// parseMemRegOffsetShift - one of these two:
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004250/// ( lsl | lsr | asr | ror ) , # shift_amount
4251/// rrx
Jim Grosbach7ce05792011-08-03 23:50:40 +00004252/// return true if it parses a shift otherwise it returns false.
4253bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4254 unsigned &Amount) {
4255 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan18b83232010-01-19 21:44:56 +00004256 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004257 if (Tok.isNot(AsmToken::Identifier))
4258 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00004259 StringRef ShiftName = Tok.getString();
Jim Grosbachaf4edea2011-12-07 23:40:58 +00004260 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4261 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson00828302011-03-18 22:50:18 +00004262 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004263 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00004264 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004265 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00004266 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004267 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00004268 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004269 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00004270 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004271 else
Jim Grosbach7ce05792011-08-03 23:50:40 +00004272 return Error(Loc, "illegal shift operator");
Sean Callananb9a25b72010-01-19 20:27:46 +00004273 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004274
Jim Grosbach7ce05792011-08-03 23:50:40 +00004275 // rrx stands alone.
4276 Amount = 0;
4277 if (St != ARM_AM::rrx) {
4278 Loc = Parser.getTok().getLoc();
4279 // A '#' and a shift amount.
4280 const AsmToken &HashTok = Parser.getTok();
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004281 if (HashTok.isNot(AsmToken::Hash) &&
4282 HashTok.isNot(AsmToken::Dollar))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004283 return Error(HashTok.getLoc(), "'#' expected");
4284 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004285
Jim Grosbach7ce05792011-08-03 23:50:40 +00004286 const MCExpr *Expr;
4287 if (getParser().ParseExpression(Expr))
4288 return true;
4289 // Range check the immediate.
4290 // lsl, ror: 0 <= imm <= 31
4291 // lsr, asr: 0 <= imm <= 32
4292 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4293 if (!CE)
4294 return Error(Loc, "shift amount must be an immediate");
4295 int64_t Imm = CE->getValue();
4296 if (Imm < 0 ||
4297 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4298 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4299 return Error(Loc, "immediate shift value out of range");
4300 Amount = Imm;
4301 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004302
4303 return false;
4304}
4305
Jim Grosbach9d390362011-10-03 23:38:36 +00004306/// parseFPImm - A floating point immediate expression operand.
4307ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4308parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004309 // Anything that can accept a floating point constant as an operand
4310 // needs to go through here, as the regular ParseExpression is
4311 // integer only.
4312 //
4313 // This routine still creates a generic Immediate operand, containing
4314 // a bitcast of the 64-bit floating point value. The various operands
4315 // that accept floats can check whether the value is valid for them
4316 // via the standard is*() predicates.
4317
Jim Grosbach9d390362011-10-03 23:38:36 +00004318 SMLoc S = Parser.getTok().getLoc();
4319
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004320 if (Parser.getTok().isNot(AsmToken::Hash) &&
4321 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbach9d390362011-10-03 23:38:36 +00004322 return MatchOperand_NoMatch;
Jim Grosbach0e387b22011-10-17 22:26:03 +00004323
4324 // Disambiguate the VMOV forms that can accept an FP immediate.
4325 // vmov.f32 <sreg>, #imm
4326 // vmov.f64 <dreg>, #imm
4327 // vmov.f32 <dreg>, #imm @ vector f32x2
4328 // vmov.f32 <qreg>, #imm @ vector f32x4
4329 //
4330 // There are also the NEON VMOV instructions which expect an
4331 // integer constant. Make sure we don't try to parse an FPImm
4332 // for these:
4333 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4334 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4335 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4336 TyOp->getToken() != ".f64"))
4337 return MatchOperand_NoMatch;
4338
Jim Grosbach9d390362011-10-03 23:38:36 +00004339 Parser.Lex(); // Eat the '#'.
4340
4341 // Handle negation, as that still comes through as a separate token.
4342 bool isNegative = false;
4343 if (Parser.getTok().is(AsmToken::Minus)) {
4344 isNegative = true;
4345 Parser.Lex();
4346 }
4347 const AsmToken &Tok = Parser.getTok();
Jim Grosbachae69f702012-01-19 02:47:30 +00004348 SMLoc Loc = Tok.getLoc();
Jim Grosbach9d390362011-10-03 23:38:36 +00004349 if (Tok.is(AsmToken::Real)) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004350 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbach9d390362011-10-03 23:38:36 +00004351 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4352 // If we had a '-' in front, toggle the sign bit.
Jim Grosbach51222d12012-01-20 18:09:51 +00004353 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbach9d390362011-10-03 23:38:36 +00004354 Parser.Lex(); // Eat the token.
Jim Grosbach51222d12012-01-20 18:09:51 +00004355 Operands.push_back(ARMOperand::CreateImm(
4356 MCConstantExpr::Create(IntVal, getContext()),
4357 S, Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004358 return MatchOperand_Success;
4359 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004360 // Also handle plain integers. Instructions which allow floating point
4361 // immediates also allow a raw encoded 8-bit value.
Jim Grosbach9d390362011-10-03 23:38:36 +00004362 if (Tok.is(AsmToken::Integer)) {
4363 int64_t Val = Tok.getIntVal();
4364 Parser.Lex(); // Eat the token.
4365 if (Val > 255 || Val < 0) {
Jim Grosbachae69f702012-01-19 02:47:30 +00004366 Error(Loc, "encoded floating point value out of range");
Jim Grosbach9d390362011-10-03 23:38:36 +00004367 return MatchOperand_ParseFail;
4368 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004369 double RealVal = ARM_AM::getFPImmFloat(Val);
4370 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4371 Operands.push_back(ARMOperand::CreateImm(
4372 MCConstantExpr::Create(Val, getContext()), S,
4373 Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004374 return MatchOperand_Success;
4375 }
4376
Jim Grosbachae69f702012-01-19 02:47:30 +00004377 Error(Loc, "invalid floating point immediate");
Jim Grosbach9d390362011-10-03 23:38:36 +00004378 return MatchOperand_ParseFail;
4379}
Jim Grosbach51222d12012-01-20 18:09:51 +00004380
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004381/// Parse a arm instruction operand. For now this parses the operand regardless
4382/// of the mnemonic.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004383bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004384 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00004385 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004386
4387 // Check if the current operand has a custom associated parser, if so, try to
4388 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00004389 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4390 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004391 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00004392 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4393 // there was a match, but an error occurred, in which case, just return that
4394 // the operand parsing failed.
4395 if (ResTy == MatchOperand_ParseFail)
4396 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004397
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004398 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00004399 default:
4400 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00004401 return true;
Jim Grosbach19906722011-07-13 18:49:30 +00004402 case AsmToken::Identifier: {
Jim Grosbach1355cf12011-07-26 17:10:22 +00004403 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling50d0f582010-11-18 23:43:05 +00004404 return false;
Jim Grosbach0d87ec22011-07-26 20:41:24 +00004405 int Res = tryParseShiftRegister(Operands);
Jim Grosbach19906722011-07-13 18:49:30 +00004406 if (Res == 0) // success
Owen Anderson00828302011-03-18 22:50:18 +00004407 return false;
Jim Grosbach19906722011-07-13 18:49:30 +00004408 else if (Res == -1) // irrecoverable error
4409 return true;
Jim Grosbach3cbe43f2011-12-20 22:26:38 +00004410 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004411 if (Mnemonic == "vmrs" && Parser.getTok().getString() == "apsr_nzcv") {
4412 S = Parser.getTok().getLoc();
4413 Parser.Lex();
4414 Operands.push_back(ARMOperand::CreateToken("apsr_nzcv", S));
4415 return false;
4416 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00004417
4418 // Fall though for the Identifier case that is not a register or a
4419 // special name.
Jim Grosbach19906722011-07-13 18:49:30 +00004420 }
Jim Grosbach758a5192011-10-26 21:14:08 +00004421 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderby67b212e2011-01-13 20:32:36 +00004422 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach6284afc2011-11-01 22:38:31 +00004423 case AsmToken::String: // quoted label names.
Kevin Enderby67b212e2011-01-13 20:32:36 +00004424 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00004425 // This was not a register so parse other operands that start with an
4426 // identifier (like labels) as expressions and create them as immediates.
4427 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00004428 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00004429 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004430 return true;
Sean Callanan76264762010-04-02 22:27:05 +00004431 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004432 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4433 return false;
4434 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004435 case AsmToken::LBrac:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004436 return parseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00004437 case AsmToken::LCurly:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004438 return parseRegisterList(Operands);
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004439 case AsmToken::Dollar:
Owen Anderson63553c72011-08-29 17:17:09 +00004440 case AsmToken::Hash: {
Kevin Enderby079469f2009-10-13 23:33:38 +00004441 // #42 -> immediate.
4442 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
Sean Callanan76264762010-04-02 22:27:05 +00004443 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004444 Parser.Lex();
Owen Anderson63553c72011-08-29 17:17:09 +00004445 bool isNegative = Parser.getTok().is(AsmToken::Minus);
Kevin Enderby515d5092009-10-15 20:48:48 +00004446 const MCExpr *ImmVal;
4447 if (getParser().ParseExpression(ImmVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004448 return true;
Owen Anderson63553c72011-08-29 17:17:09 +00004449 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbached6a0c52011-11-01 22:37:37 +00004450 if (CE) {
4451 int32_t Val = CE->getValue();
4452 if (isNegative && Val == 0)
4453 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
Owen Anderson63553c72011-08-29 17:17:09 +00004454 }
Sean Callanan76264762010-04-02 22:27:05 +00004455 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004456 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4457 return false;
Owen Anderson63553c72011-08-29 17:17:09 +00004458 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004459 case AsmToken::Colon: {
4460 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00004461 // FIXME: Check it's an expression prefix,
4462 // e.g. (FOO - :lower16:BAR) isn't legal.
4463 ARMMCExpr::VariantKind RefKind;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004464 if (parsePrefix(RefKind))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004465 return true;
4466
Evan Cheng75972122011-01-13 07:58:56 +00004467 const MCExpr *SubExprVal;
4468 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004469 return true;
4470
Evan Cheng75972122011-01-13 07:58:56 +00004471 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4472 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00004473 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00004474 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00004475 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004476 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004477 }
4478}
4479
Jim Grosbach1355cf12011-07-26 17:10:22 +00004480// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng75972122011-01-13 07:58:56 +00004481// :lower16: and :upper16:.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004482bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng75972122011-01-13 07:58:56 +00004483 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004484
4485 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00004486 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00004487 Parser.Lex(); // Eat ':'
4488
4489 if (getLexer().isNot(AsmToken::Identifier)) {
4490 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4491 return true;
4492 }
4493
4494 StringRef IDVal = Parser.getTok().getIdentifier();
4495 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00004496 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004497 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00004498 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004499 } else {
4500 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4501 return true;
4502 }
4503 Parser.Lex();
4504
4505 if (getLexer().isNot(AsmToken::Colon)) {
4506 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4507 return true;
4508 }
4509 Parser.Lex(); // Eat the last ':'
4510 return false;
4511}
4512
Daniel Dunbar352e1482011-01-11 15:59:50 +00004513/// \brief Given a mnemonic, split out possible predication code and carry
4514/// setting letters to form a canonical mnemonic and flags.
4515//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004516// FIXME: Would be nice to autogen this.
Jim Grosbach89df9962011-08-26 21:43:41 +00004517// FIXME: This is a bit of a maze of special cases.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004518StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5f160572011-07-19 20:10:31 +00004519 unsigned &PredicationCode,
4520 bool &CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004521 unsigned &ProcessorIMod,
4522 StringRef &ITMask) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004523 PredicationCode = ARMCC::AL;
4524 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004525 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004526
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004527 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00004528 //
4529 // FIXME: Would be nice to autogen this.
Jim Grosbach5f160572011-07-19 20:10:31 +00004530 if ((Mnemonic == "movs" && isThumb()) ||
4531 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4532 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4533 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4534 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4535 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4536 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbach68490192011-12-19 19:43:50 +00004537 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4538 Mnemonic == "fmuls")
Daniel Dunbar352e1482011-01-11 15:59:50 +00004539 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00004540
Jim Grosbach3f00e312011-07-11 17:09:57 +00004541 // First, split out any predication code. Ignore mnemonics we know aren't
4542 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbachab40f4b2011-07-20 18:20:31 +00004543 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach71725a02011-07-27 21:58:11 +00004544 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach04d55f12011-08-22 23:55:58 +00004545 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbach2f25d9b2011-09-01 18:22:13 +00004546 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbach3f00e312011-07-11 17:09:57 +00004547 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4548 .Case("eq", ARMCC::EQ)
4549 .Case("ne", ARMCC::NE)
4550 .Case("hs", ARMCC::HS)
4551 .Case("cs", ARMCC::HS)
4552 .Case("lo", ARMCC::LO)
4553 .Case("cc", ARMCC::LO)
4554 .Case("mi", ARMCC::MI)
4555 .Case("pl", ARMCC::PL)
4556 .Case("vs", ARMCC::VS)
4557 .Case("vc", ARMCC::VC)
4558 .Case("hi", ARMCC::HI)
4559 .Case("ls", ARMCC::LS)
4560 .Case("ge", ARMCC::GE)
4561 .Case("lt", ARMCC::LT)
4562 .Case("gt", ARMCC::GT)
4563 .Case("le", ARMCC::LE)
4564 .Case("al", ARMCC::AL)
4565 .Default(~0U);
4566 if (CC != ~0U) {
4567 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4568 PredicationCode = CC;
4569 }
Bill Wendling52925b62010-10-29 23:50:21 +00004570 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004571
Daniel Dunbar352e1482011-01-11 15:59:50 +00004572 // Next, determine if we have a carry setting bit. We explicitly ignore all
4573 // the instructions we know end in 's'.
4574 if (Mnemonic.endswith("s") &&
Jim Grosbach00f5d982011-08-17 22:49:09 +00004575 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5f160572011-07-19 20:10:31 +00004576 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4577 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4578 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach67ca1ad2011-12-08 00:49:29 +00004579 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach48171e72011-12-10 00:01:02 +00004580 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach9c397892011-12-19 19:02:41 +00004581 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbach1aa149f2011-12-22 19:20:45 +00004582 Mnemonic == "fmuls" || Mnemonic == "fcmps" ||
Jim Grosbache1cf5902011-07-29 20:26:09 +00004583 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004584 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4585 CarrySetting = true;
4586 }
4587
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004588 // The "cps" instruction can have a interrupt mode operand which is glued into
4589 // the mnemonic. Check if this is the case, split it and parse the imod op
4590 if (Mnemonic.startswith("cps")) {
4591 // Split out any imod code.
4592 unsigned IMod =
4593 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4594 .Case("ie", ARM_PROC::IE)
4595 .Case("id", ARM_PROC::ID)
4596 .Default(~0U);
4597 if (IMod != ~0U) {
4598 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4599 ProcessorIMod = IMod;
4600 }
4601 }
4602
Jim Grosbach89df9962011-08-26 21:43:41 +00004603 // The "it" instruction has the condition mask on the end of the mnemonic.
4604 if (Mnemonic.startswith("it")) {
4605 ITMask = Mnemonic.slice(2, Mnemonic.size());
4606 Mnemonic = Mnemonic.slice(0, 2);
4607 }
4608
Daniel Dunbar352e1482011-01-11 15:59:50 +00004609 return Mnemonic;
4610}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004611
4612/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4613/// inclusion of carry set or predication code operands.
4614//
4615// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004616void ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00004617getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004618 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004619 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4620 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004621 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004622 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004623 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004624 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004625 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004626 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004627 Mnemonic == "mla" || Mnemonic == "smlal" ||
4628 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004629 CanAcceptCarrySet = true;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004630 } else
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004631 CanAcceptCarrySet = false;
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004632
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004633 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4634 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4635 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4636 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbachad2dad92011-09-06 20:27:04 +00004637 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4638 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach0780b632011-08-19 23:24:36 +00004639 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach2bd01182011-10-11 21:55:36 +00004640 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4641 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4642 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbach4af54a42011-08-26 22:21:51 +00004643 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4644 !isThumb()) ||
Jim Grosbach1ad60c22011-09-10 00:15:36 +00004645 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004646 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004647 } else
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004648 CanAcceptPredicationCode = true;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004649
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004650 if (isThumb()) {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004651 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00004652 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004653 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004654 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004655}
4656
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004657bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4658 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004659 // FIXME: This is all horribly hacky. We really need a better way to deal
4660 // with optional operands like this in the matcher table.
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004661
4662 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4663 // another does not. Specifically, the MOVW instruction does not. So we
4664 // special case it here and remove the defaulted (non-setting) cc_out
4665 // operand if that's the instruction we're trying to match.
4666 //
4667 // We do this as post-processing of the explicit operands rather than just
4668 // conditionally adding the cc_out in the first place because we need
4669 // to check the type of the parsed immediate operand.
Owen Anderson8adf6202011-09-14 22:46:14 +00004670 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004671 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4672 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4673 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4674 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004675
4676 // Register-register 'add' for thumb does not have a cc_out operand
4677 // when there are only two register operands.
4678 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4679 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4680 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4681 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4682 return true;
Jim Grosbach72f39f82011-08-24 21:22:15 +00004683 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004684 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4685 // have to check the immediate range here since Thumb2 has a variant
4686 // that can handle a different range and has a cc_out operand.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004687 if (((isThumb() && Mnemonic == "add") ||
4688 (isThumbTwo() && Mnemonic == "sub")) &&
4689 Operands.size() == 6 &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004690 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4691 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4692 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004693 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4694 (static_cast<ARMOperand*>(Operands[5])->isReg() ||
4695 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004696 return true;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004697 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4698 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004699 // selecting via the generic "add" mnemonic, so to know that we
4700 // should remove the cc_out operand, we have to explicitly check that
4701 // it's not one of the other variants. Ugh.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004702 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4703 Operands.size() == 6 &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004704 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4705 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4706 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4707 // Nest conditions rather than one big 'if' statement for readability.
4708 //
4709 // If either register is a high reg, it's either one of the SP
4710 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach12a88632012-01-21 00:07:56 +00004711 // check against T3. If the second register is the PC, this is an
4712 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004713 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4714 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach12a88632012-01-21 00:07:56 +00004715 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004716 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4717 return false;
4718 // If both registers are low, we're in an IT block, and the immediate is
4719 // in range, we should use encoding T1 instead, which has a cc_out.
4720 if (inITBlock() &&
Jim Grosbach64944f42011-09-14 21:00:40 +00004721 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004722 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4723 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4724 return false;
4725
4726 // Otherwise, we use encoding T4, which does not have a cc_out
4727 // operand.
4728 return true;
4729 }
4730
Jim Grosbach64944f42011-09-14 21:00:40 +00004731 // The thumb2 multiply instruction doesn't have a CCOut register, so
4732 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4733 // use the 16-bit encoding or not.
4734 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4735 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4736 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4737 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4738 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4739 // If the registers aren't low regs, the destination reg isn't the
4740 // same as one of the source regs, or the cc_out operand is zero
4741 // outside of an IT block, we have to use the 32-bit encoding, so
4742 // remove the cc_out operand.
4743 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4744 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach1de0bd12011-11-15 19:29:45 +00004745 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach64944f42011-09-14 21:00:40 +00004746 !inITBlock() ||
4747 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4748 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4749 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4750 static_cast<ARMOperand*>(Operands[4])->getReg())))
4751 return true;
4752
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004753 // Also check the 'mul' syntax variant that doesn't specify an explicit
4754 // destination register.
4755 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4756 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4757 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4758 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4759 // If the registers aren't low regs or the cc_out operand is zero
4760 // outside of an IT block, we have to use the 32-bit encoding, so
4761 // remove the cc_out operand.
4762 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4763 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4764 !inITBlock()))
4765 return true;
4766
Jim Grosbach64944f42011-09-14 21:00:40 +00004767
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004768
Jim Grosbachf69c8042011-08-24 21:42:27 +00004769 // Register-register 'add/sub' for thumb does not have a cc_out operand
4770 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4771 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4772 // right, this will result in better diagnostics (which operand is off)
4773 // anyway.
4774 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4775 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004776 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4777 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4778 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4779 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004780
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004781 return false;
4782}
4783
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004784static bool isDataTypeToken(StringRef Tok) {
4785 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4786 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4787 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4788 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4789 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4790 Tok == ".f" || Tok == ".d";
4791}
4792
4793// FIXME: This bit should probably be handled via an explicit match class
4794// in the .td files that matches the suffix instead of having it be
4795// a literal string token the way it is now.
4796static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4797 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4798}
4799
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004800static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004801/// Parse an arm instruction mnemonic followed by its operands.
4802bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4803 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004804 // Apply mnemonic aliases before doing anything else, as the destination
4805 // mnemnonic may include suffices and we want to handle them normally.
4806 // The generic tblgen'erated code does this later, at the start of
4807 // MatchInstructionImpl(), but that's too late for aliases that include
4808 // any sort of suffix.
4809 unsigned AvailableFeatures = getAvailableFeatures();
4810 applyMnemonicAliases(Name, AvailableFeatures);
4811
Jim Grosbacha39cda72011-12-14 02:16:11 +00004812 // First check for the ARM-specific .req directive.
4813 if (Parser.getTok().is(AsmToken::Identifier) &&
4814 Parser.getTok().getIdentifier() == ".req") {
4815 parseDirectiveReq(Name, NameLoc);
4816 // We always return 'error' for this, as we're done with this
4817 // statement and don't need to match the 'instruction."
4818 return true;
4819 }
4820
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004821 // Create the leading tokens for the mnemonic, split by '.' characters.
4822 size_t Start = 0, Next = Name.find('.');
Jim Grosbachffa32252011-07-19 19:13:28 +00004823 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004824
Daniel Dunbar352e1482011-01-11 15:59:50 +00004825 // Split out the predication code and carry setting flag from the mnemonic.
4826 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004827 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004828 bool CarrySetting;
Jim Grosbach89df9962011-08-26 21:43:41 +00004829 StringRef ITMask;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004830 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004831 ProcessorIMod, ITMask);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004832
Jim Grosbach0c49ac02011-08-25 17:23:55 +00004833 // In Thumb1, only the branch (B) instruction can be predicated.
4834 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4835 Parser.EatToEndOfStatement();
4836 return Error(NameLoc, "conditional execution not supported in Thumb1");
4837 }
4838
Jim Grosbachffa32252011-07-19 19:13:28 +00004839 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4840
Jim Grosbach89df9962011-08-26 21:43:41 +00004841 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4842 // is the mask as it will be for the IT encoding if the conditional
4843 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4844 // where the conditional bit0 is zero, the instruction post-processing
4845 // will adjust the mask accordingly.
4846 if (Mnemonic == "it") {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004847 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4848 if (ITMask.size() > 3) {
4849 Parser.EatToEndOfStatement();
4850 return Error(Loc, "too many conditions on IT instruction");
4851 }
Jim Grosbach89df9962011-08-26 21:43:41 +00004852 unsigned Mask = 8;
4853 for (unsigned i = ITMask.size(); i != 0; --i) {
4854 char pos = ITMask[i - 1];
4855 if (pos != 't' && pos != 'e') {
4856 Parser.EatToEndOfStatement();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004857 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach89df9962011-08-26 21:43:41 +00004858 }
4859 Mask >>= 1;
4860 if (ITMask[i - 1] == 't')
4861 Mask |= 8;
4862 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004863 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach89df9962011-08-26 21:43:41 +00004864 }
4865
Jim Grosbachffa32252011-07-19 19:13:28 +00004866 // FIXME: This is all a pretty gross hack. We should automatically handle
4867 // optional operands like this via tblgen.
Bill Wendling9717fa92010-11-21 10:56:05 +00004868
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004869 // Next, add the CCOut and ConditionCode operands, if needed.
4870 //
4871 // For mnemonics which can ever incorporate a carry setting bit or predication
4872 // code, our matching model involves us always generating CCOut and
4873 // ConditionCode operands to match the mnemonic "as written" and then we let
4874 // the matcher deal with finding the right instruction or generating an
4875 // appropriate error.
4876 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004877 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004878
Jim Grosbach33c16a22011-07-14 22:04:21 +00004879 // If we had a carry-set on an instruction that can't do that, issue an
4880 // error.
4881 if (!CanAcceptCarrySet && CarrySetting) {
4882 Parser.EatToEndOfStatement();
Jim Grosbachffa32252011-07-19 19:13:28 +00004883 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach33c16a22011-07-14 22:04:21 +00004884 "' can not set flags, but 's' suffix specified");
4885 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +00004886 // If we had a predication code on an instruction that can't do that, issue an
4887 // error.
4888 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
4889 Parser.EatToEndOfStatement();
4890 return Error(NameLoc, "instruction '" + Mnemonic +
4891 "' is not predicable, but condition code specified");
4892 }
Jim Grosbach33c16a22011-07-14 22:04:21 +00004893
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004894 // Add the carry setting operand, if necessary.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004895 if (CanAcceptCarrySet) {
4896 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004897 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004898 Loc));
4899 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004900
4901 // Add the predication code operand, if necessary.
4902 if (CanAcceptPredicationCode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004903 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
4904 CarrySetting);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004905 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004906 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004907 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004908
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004909 // Add the processor imod operand, if necessary.
4910 if (ProcessorIMod) {
4911 Operands.push_back(ARMOperand::CreateImm(
4912 MCConstantExpr::Create(ProcessorIMod, getContext()),
4913 NameLoc, NameLoc));
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004914 }
4915
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004916 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00004917 while (Next != StringRef::npos) {
4918 Start = Next;
4919 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004920 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004921
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004922 // Some NEON instructions have an optional datatype suffix that is
4923 // completely ignored. Check for that.
4924 if (isDataTypeToken(ExtraToken) &&
4925 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
4926 continue;
4927
Jim Grosbach81d2e392011-09-07 16:06:04 +00004928 if (ExtraToken != ".n") {
4929 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
4930 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
4931 }
Daniel Dunbar5747b132010-08-11 06:37:16 +00004932 }
4933
4934 // Read the remaining operands.
4935 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004936 // Read the first operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004937 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00004938 Parser.EatToEndOfStatement();
4939 return true;
4940 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004941
4942 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00004943 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004944
4945 // Parse and remember the operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004946 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00004947 Parser.EatToEndOfStatement();
4948 return true;
4949 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004950 }
4951 }
Jim Grosbach16c74252010-10-29 14:46:02 +00004952
Chris Lattnercbf8a982010-09-11 16:18:25 +00004953 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbach186ffac2011-10-07 18:27:04 +00004954 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00004955 Parser.EatToEndOfStatement();
Jim Grosbach186ffac2011-10-07 18:27:04 +00004956 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00004957 }
Bill Wendling146018f2010-11-06 21:42:12 +00004958
Chris Lattner34e53142010-09-08 05:10:46 +00004959 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbachffa32252011-07-19 19:13:28 +00004960
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004961 // Some instructions, mostly Thumb, have forms for the same mnemonic that
4962 // do and don't have a cc_out optional-def operand. With some spot-checks
4963 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004964 // parse and adjust accordingly before actually matching. We shouldn't ever
4965 // try to remove a cc_out operand that was explicitly set on the the
4966 // mnemonic, of course (CarrySetting == true). Reason number #317 the
4967 // table driven matcher doesn't fit well with the ARM instruction set.
4968 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbachffa32252011-07-19 19:13:28 +00004969 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
4970 Operands.erase(Operands.begin() + 1);
4971 delete Op;
4972 }
4973
Jim Grosbachcf121c32011-07-28 21:57:55 +00004974 // ARM mode 'blx' need special handling, as the register operand version
4975 // is predicable, but the label operand version is not. So, we can't rely
4976 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach21ff17c2011-10-07 23:24:09 +00004977 // a k_CondCode operand in the list. If we're trying to match the label
4978 // version, remove the k_CondCode operand here.
Jim Grosbachcf121c32011-07-28 21:57:55 +00004979 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
4980 static_cast<ARMOperand*>(Operands[2])->isImm()) {
4981 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
4982 Operands.erase(Operands.begin() + 1);
4983 delete Op;
4984 }
Jim Grosbach857e1a72011-08-11 23:51:13 +00004985
4986 // The vector-compare-to-zero instructions have a literal token "#0" at
4987 // the end that comes to here as an immediate operand. Convert it to a
4988 // token to play nicely with the matcher.
4989 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
4990 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
4991 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4992 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
4993 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
4994 if (CE && CE->getValue() == 0) {
4995 Operands.erase(Operands.begin() + 5);
4996 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
4997 delete Op;
4998 }
4999 }
Jim Grosbach68259142011-10-03 22:30:24 +00005000 // VCMP{E} does the same thing, but with a different operand count.
5001 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5002 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5003 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5004 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5005 if (CE && CE->getValue() == 0) {
5006 Operands.erase(Operands.begin() + 4);
5007 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5008 delete Op;
5009 }
5010 }
Jim Grosbach934755a2011-08-22 23:47:13 +00005011 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach55b02f22011-12-13 20:50:38 +00005012 // end. Convert it to a token here. Take care not to convert those
5013 // that should hit the Thumb2 encoding.
Jim Grosbach934755a2011-08-22 23:47:13 +00005014 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach55b02f22011-12-13 20:50:38 +00005015 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5016 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbach934755a2011-08-22 23:47:13 +00005017 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5018 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5019 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach55b02f22011-12-13 20:50:38 +00005020 if (CE && CE->getValue() == 0 &&
5021 (isThumbOne() ||
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005022 // The cc_out operand matches the IT block.
5023 ((inITBlock() != CarrySetting) &&
5024 // Neither register operand is a high register.
Jim Grosbach55b02f22011-12-13 20:50:38 +00005025 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005026 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbach934755a2011-08-22 23:47:13 +00005027 Operands.erase(Operands.begin() + 5);
5028 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5029 delete Op;
5030 }
5031 }
5032
Chris Lattner98986712010-01-14 22:21:20 +00005033 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00005034}
5035
Jim Grosbach189610f2011-07-26 18:25:39 +00005036// Validate context-sensitive operand constraints.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005037
5038// return 'true' if register list contains non-low GPR registers,
5039// 'false' otherwise. If Reg is in the register list or is HiReg, set
5040// 'containsReg' to true.
5041static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5042 unsigned HiReg, bool &containsReg) {
5043 containsReg = false;
5044 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5045 unsigned OpReg = Inst.getOperand(i).getReg();
5046 if (OpReg == Reg)
5047 containsReg = true;
5048 // Anything other than a low register isn't legal here.
5049 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5050 return true;
5051 }
5052 return false;
5053}
5054
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005055// Check if the specified regisgter is in the register list of the inst,
5056// starting at the indicated operand number.
5057static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5058 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5059 unsigned OpReg = Inst.getOperand(i).getReg();
5060 if (OpReg == Reg)
5061 return true;
5062 }
5063 return false;
5064}
5065
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005066// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5067// the ARMInsts array) instead. Getting that here requires awkward
5068// API changes, though. Better way?
5069namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005070extern const MCInstrDesc ARMInsts[];
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005071}
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005072static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005073 return ARMInsts[Opcode];
5074}
5075
Jim Grosbach189610f2011-07-26 18:25:39 +00005076// FIXME: We would really like to be able to tablegen'erate this.
5077bool ARMAsmParser::
5078validateInstruction(MCInst &Inst,
5079 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005080 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005081 SMLoc Loc = Operands[0]->getStartLoc();
5082 // Check the IT block state first.
Owen Andersonb6b7f512011-09-13 17:59:19 +00005083 // NOTE: In Thumb mode, the BKPT instruction has the interesting property of
5084 // being allowed in IT blocks, but not being predicable. It just always
5085 // executes.
5086 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005087 unsigned bit = 1;
5088 if (ITState.FirstCond)
5089 ITState.FirstCond = false;
5090 else
Jim Grosbacha1109882011-09-02 23:22:08 +00005091 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005092 // The instruction must be predicable.
5093 if (!MCID.isPredicable())
5094 return Error(Loc, "instructions in IT block must be predicable");
5095 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5096 unsigned ITCond = bit ? ITState.Cond :
5097 ARMCC::getOppositeCondition(ITState.Cond);
5098 if (Cond != ITCond) {
5099 // Find the condition code Operand to get its SMLoc information.
5100 SMLoc CondLoc;
5101 for (unsigned i = 1; i < Operands.size(); ++i)
5102 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5103 CondLoc = Operands[i]->getStartLoc();
5104 return Error(CondLoc, "incorrect condition in IT block; got '" +
5105 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5106 "', but expected '" +
5107 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5108 }
Jim Grosbachc9a9b442011-08-31 18:29:05 +00005109 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005110 } else if (isThumbTwo() && MCID.isPredicable() &&
5111 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson51f6a7a2011-09-09 21:48:23 +00005112 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5113 Inst.getOpcode() != ARM::t2B)
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005114 return Error(Loc, "predicated instructions must be in IT block");
5115
Jim Grosbach189610f2011-07-26 18:25:39 +00005116 switch (Inst.getOpcode()) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00005117 case ARM::LDRD:
5118 case ARM::LDRD_PRE:
5119 case ARM::LDRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005120 case ARM::LDREXD: {
5121 // Rt2 must be Rt + 1.
5122 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5123 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5124 if (Rt2 != Rt + 1)
5125 return Error(Operands[3]->getStartLoc(),
5126 "destination operands must be sequential");
5127 return false;
5128 }
Jim Grosbach14605d12011-08-11 20:28:23 +00005129 case ARM::STRD: {
5130 // Rt2 must be Rt + 1.
5131 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5132 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5133 if (Rt2 != Rt + 1)
5134 return Error(Operands[3]->getStartLoc(),
5135 "source operands must be sequential");
5136 return false;
5137 }
Jim Grosbach53642c52011-08-10 20:49:18 +00005138 case ARM::STRD_PRE:
5139 case ARM::STRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005140 case ARM::STREXD: {
5141 // Rt2 must be Rt + 1.
5142 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5143 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(2).getReg());
5144 if (Rt2 != Rt + 1)
Jim Grosbach14605d12011-08-11 20:28:23 +00005145 return Error(Operands[3]->getStartLoc(),
Jim Grosbach189610f2011-07-26 18:25:39 +00005146 "source operands must be sequential");
5147 return false;
5148 }
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005149 case ARM::SBFX:
5150 case ARM::UBFX: {
5151 // width must be in range [1, 32-lsb]
5152 unsigned lsb = Inst.getOperand(2).getImm();
5153 unsigned widthm1 = Inst.getOperand(3).getImm();
5154 if (widthm1 >= 32 - lsb)
5155 return Error(Operands[5]->getStartLoc(),
5156 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach00c9a512011-08-16 21:42:31 +00005157 return false;
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005158 }
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005159 case ARM::tLDMIA: {
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005160 // If we're parsing Thumb2, the .w variant is available and handles
5161 // most cases that are normally illegal for a Thumb1 LDM
5162 // instruction. We'll make the transformation in processInstruction()
5163 // if necessary.
5164 //
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005165 // Thumb LDM instructions are writeback iff the base register is not
5166 // in the register list.
5167 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005168 bool hasWritebackToken =
5169 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5170 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbachaa875f82011-08-23 18:13:04 +00005171 bool listContainsBase;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005172 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005173 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5174 "registers must be in range r0-r7");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005175 // If we should have writeback, then there should be a '!' token.
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005176 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005177 return Error(Operands[2]->getStartLoc(),
5178 "writeback operator '!' expected");
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005179 // If we should not have writeback, there must not be a '!'. This is
5180 // true even for the 32-bit wide encodings.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005181 if (listContainsBase && hasWritebackToken)
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005182 return Error(Operands[3]->getStartLoc(),
5183 "writeback operator '!' not allowed when base register "
5184 "in register list");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005185
5186 break;
5187 }
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005188 case ARM::t2LDMIA_UPD: {
5189 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5190 return Error(Operands[4]->getStartLoc(),
5191 "writeback operator '!' not allowed when base register "
5192 "in register list");
5193 break;
5194 }
Jim Grosbach54026372011-11-10 23:17:11 +00005195 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5196 // so only issue a diagnostic for thumb1. The instructions will be
5197 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005198 case ARM::tPOP: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005199 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005200 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5201 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005202 return Error(Operands[2]->getStartLoc(),
5203 "registers must be in range r0-r7 or pc");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005204 break;
5205 }
5206 case ARM::tPUSH: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005207 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005208 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5209 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005210 return Error(Operands[2]->getStartLoc(),
5211 "registers must be in range r0-r7 or lr");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005212 break;
5213 }
Jim Grosbach1e84f192011-08-23 18:15:37 +00005214 case ARM::tSTMIA_UPD: {
5215 bool listContainsBase;
Jim Grosbach8213c962011-09-16 20:50:13 +00005216 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach1e84f192011-08-23 18:15:37 +00005217 return Error(Operands[4]->getStartLoc(),
5218 "registers must be in range r0-r7");
5219 break;
5220 }
Jim Grosbach189610f2011-07-26 18:25:39 +00005221 }
5222
5223 return false;
5224}
5225
Jim Grosbachd7433e22012-01-23 23:45:44 +00005226static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach84defb52011-12-02 22:34:51 +00005227 switch(Opc) {
5228 default: assert(0 && "unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005229 // VST1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005230 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5231 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5232 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5233 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5234 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5235 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5236 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5237 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5238 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005239
5240 // VST2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005241 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5242 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5243 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5244 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5245 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005246
Jim Grosbach7945ead2012-01-24 00:43:12 +00005247 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5248 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5249 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5250 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5251 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005252
Jim Grosbach7945ead2012-01-24 00:43:12 +00005253 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5254 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5255 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5256 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5257 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005258
Jim Grosbach4adb1822012-01-24 00:07:41 +00005259 // VST3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005260 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5261 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5262 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5263 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5264 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5265 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5266 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5267 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5268 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5269 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5270 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5271 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5272 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5273 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5274 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbach4adb1822012-01-24 00:07:41 +00005275
Jim Grosbachd7433e22012-01-23 23:45:44 +00005276 // VST3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005277 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5278 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5279 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5280 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5281 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5282 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5283 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5284 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5285 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5286 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5287 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5288 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5289 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5290 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5291 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5292 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5293 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5294 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbach539aab72012-01-24 00:58:13 +00005295
Jim Grosbach88a54de2012-01-24 18:53:13 +00005296 // VST4LN
5297 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5298 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5299 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5300 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5301 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5302 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5303 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5304 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5305 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5306 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5307 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5308 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5309 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5310 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5311 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5312
Jim Grosbach539aab72012-01-24 00:58:13 +00005313 // VST4
5314 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5315 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5316 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5317 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5318 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5319 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5320 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5321 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5322 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5323 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5324 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5325 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5326 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5327 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5328 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5329 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5330 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5331 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbach84defb52011-12-02 22:34:51 +00005332 }
5333}
5334
Jim Grosbachd7433e22012-01-23 23:45:44 +00005335static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00005336 switch(Opc) {
5337 default: assert(0 && "unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005338 // VLD1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005339 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5340 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5341 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5342 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5343 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5344 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5345 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5346 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5347 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005348
5349 // VLD2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005350 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5351 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5352 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5353 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5354 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5355 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5356 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5357 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5358 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5359 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5360 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5361 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5362 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5363 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5364 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbach3a678af2012-01-23 21:53:26 +00005365
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00005366 // VLD3DUP
5367 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5368 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5369 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5370 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5371 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5372 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5373 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5374 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5375 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5376 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5377 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5378 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5379 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5380 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5381 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5382 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5383 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5384 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5385
Jim Grosbach3a678af2012-01-23 21:53:26 +00005386 // VLD3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005387 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5388 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5389 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5390 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5391 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5392 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5393 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5394 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5395 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5396 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5397 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5398 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5399 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5400 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5401 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachc387fc62012-01-23 23:20:46 +00005402
5403 // VLD3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005404 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5405 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5406 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5407 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5408 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5409 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5410 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5411 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5412 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5413 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5414 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5415 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5416 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5417 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5418 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5419 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5420 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5421 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005422
Jim Grosbache983a132012-01-24 18:37:25 +00005423 // VLD4LN
5424 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5425 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5426 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5427 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5428 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5429 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5430 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5431 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5432 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5433 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5434 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5435 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5436 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5437 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5438 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5439
Jim Grosbacha57a36a2012-01-25 00:01:08 +00005440 // VLD4DUP
5441 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5442 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5443 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5444 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5445 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5446 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5447 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5448 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5449 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5450 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5451 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5452 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5453 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5454 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5455 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5456 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5457 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5458 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5459
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005460 // VLD4
5461 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5462 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5463 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5464 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5465 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5466 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5467 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5468 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5469 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5470 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5471 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5472 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5473 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5474 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5475 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5476 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5477 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5478 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach7636bf62011-12-02 00:35:16 +00005479 }
5480}
5481
Jim Grosbach83ec8772011-11-10 23:42:14 +00005482bool ARMAsmParser::
Jim Grosbachf8fce712011-08-11 17:35:48 +00005483processInstruction(MCInst &Inst,
5484 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5485 switch (Inst.getOpcode()) {
Jim Grosbach0b4c6732012-01-18 22:46:46 +00005486 // Aliases for alternate PC+imm syntax of LDR instructions.
5487 case ARM::t2LDRpcrel:
5488 Inst.setOpcode(ARM::t2LDRpci);
5489 return true;
5490 case ARM::t2LDRBpcrel:
5491 Inst.setOpcode(ARM::t2LDRBpci);
5492 return true;
5493 case ARM::t2LDRHpcrel:
5494 Inst.setOpcode(ARM::t2LDRHpci);
5495 return true;
5496 case ARM::t2LDRSBpcrel:
5497 Inst.setOpcode(ARM::t2LDRSBpci);
5498 return true;
5499 case ARM::t2LDRSHpcrel:
5500 Inst.setOpcode(ARM::t2LDRSHpci);
5501 return true;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005502 // Handle NEON VST complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005503 case ARM::VST1LNdWB_register_Asm_8:
5504 case ARM::VST1LNdWB_register_Asm_16:
5505 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005506 MCInst TmpInst;
5507 // Shuffle the operands around so the lane index operand is in the
5508 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005509 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005510 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005511 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5512 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5513 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5514 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5515 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5516 TmpInst.addOperand(Inst.getOperand(1)); // lane
5517 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5518 TmpInst.addOperand(Inst.getOperand(6));
5519 Inst = TmpInst;
5520 return true;
5521 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005522
Jim Grosbach8b31f952012-01-23 19:39:08 +00005523 case ARM::VST2LNdWB_register_Asm_8:
5524 case ARM::VST2LNdWB_register_Asm_16:
5525 case ARM::VST2LNdWB_register_Asm_32:
5526 case ARM::VST2LNqWB_register_Asm_16:
5527 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005528 MCInst TmpInst;
5529 // Shuffle the operands around so the lane index operand is in the
5530 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005531 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005532 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005533 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5534 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5535 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5536 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5537 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005538 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5539 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005540 TmpInst.addOperand(Inst.getOperand(1)); // lane
5541 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5542 TmpInst.addOperand(Inst.getOperand(6));
5543 Inst = TmpInst;
5544 return true;
5545 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005546
5547 case ARM::VST3LNdWB_register_Asm_8:
5548 case ARM::VST3LNdWB_register_Asm_16:
5549 case ARM::VST3LNdWB_register_Asm_32:
5550 case ARM::VST3LNqWB_register_Asm_16:
5551 case ARM::VST3LNqWB_register_Asm_32: {
5552 MCInst TmpInst;
5553 // Shuffle the operands around so the lane index operand is in the
5554 // right place.
5555 unsigned Spacing;
5556 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5557 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5558 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5559 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5560 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5561 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5562 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5563 Spacing));
5564 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5565 Spacing * 2));
5566 TmpInst.addOperand(Inst.getOperand(1)); // lane
5567 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5568 TmpInst.addOperand(Inst.getOperand(6));
5569 Inst = TmpInst;
5570 return true;
5571 }
5572
Jim Grosbach88a54de2012-01-24 18:53:13 +00005573 case ARM::VST4LNdWB_register_Asm_8:
5574 case ARM::VST4LNdWB_register_Asm_16:
5575 case ARM::VST4LNdWB_register_Asm_32:
5576 case ARM::VST4LNqWB_register_Asm_16:
5577 case ARM::VST4LNqWB_register_Asm_32: {
5578 MCInst TmpInst;
5579 // Shuffle the operands around so the lane index operand is in the
5580 // right place.
5581 unsigned Spacing;
5582 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5583 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5584 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5585 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5586 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5587 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5588 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5589 Spacing));
5590 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5591 Spacing * 2));
5592 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5593 Spacing * 3));
5594 TmpInst.addOperand(Inst.getOperand(1)); // lane
5595 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5596 TmpInst.addOperand(Inst.getOperand(6));
5597 Inst = TmpInst;
5598 return true;
5599 }
5600
Jim Grosbach8b31f952012-01-23 19:39:08 +00005601 case ARM::VST1LNdWB_fixed_Asm_8:
5602 case ARM::VST1LNdWB_fixed_Asm_16:
5603 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005604 MCInst TmpInst;
5605 // Shuffle the operands around so the lane index operand is in the
5606 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005607 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005608 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005609 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5610 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5611 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5612 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5613 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5614 TmpInst.addOperand(Inst.getOperand(1)); // lane
5615 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5616 TmpInst.addOperand(Inst.getOperand(5));
5617 Inst = TmpInst;
5618 return true;
5619 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005620
Jim Grosbach8b31f952012-01-23 19:39:08 +00005621 case ARM::VST2LNdWB_fixed_Asm_8:
5622 case ARM::VST2LNdWB_fixed_Asm_16:
5623 case ARM::VST2LNdWB_fixed_Asm_32:
5624 case ARM::VST2LNqWB_fixed_Asm_16:
5625 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005626 MCInst TmpInst;
5627 // Shuffle the operands around so the lane index operand is in the
5628 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005629 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005630 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005631 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5632 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5633 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5634 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5635 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005636 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5637 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005638 TmpInst.addOperand(Inst.getOperand(1)); // lane
5639 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5640 TmpInst.addOperand(Inst.getOperand(5));
5641 Inst = TmpInst;
5642 return true;
5643 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005644
5645 case ARM::VST3LNdWB_fixed_Asm_8:
5646 case ARM::VST3LNdWB_fixed_Asm_16:
5647 case ARM::VST3LNdWB_fixed_Asm_32:
5648 case ARM::VST3LNqWB_fixed_Asm_16:
5649 case ARM::VST3LNqWB_fixed_Asm_32: {
5650 MCInst TmpInst;
5651 // Shuffle the operands around so the lane index operand is in the
5652 // right place.
5653 unsigned Spacing;
5654 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5655 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5656 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5657 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5658 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5659 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5660 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5661 Spacing));
5662 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5663 Spacing * 2));
5664 TmpInst.addOperand(Inst.getOperand(1)); // lane
5665 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5666 TmpInst.addOperand(Inst.getOperand(5));
5667 Inst = TmpInst;
5668 return true;
5669 }
5670
Jim Grosbach88a54de2012-01-24 18:53:13 +00005671 case ARM::VST4LNdWB_fixed_Asm_8:
5672 case ARM::VST4LNdWB_fixed_Asm_16:
5673 case ARM::VST4LNdWB_fixed_Asm_32:
5674 case ARM::VST4LNqWB_fixed_Asm_16:
5675 case ARM::VST4LNqWB_fixed_Asm_32: {
5676 MCInst TmpInst;
5677 // Shuffle the operands around so the lane index operand is in the
5678 // right place.
5679 unsigned Spacing;
5680 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5681 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5682 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5683 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5684 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5685 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5686 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5687 Spacing));
5688 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5689 Spacing * 2));
5690 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5691 Spacing * 3));
5692 TmpInst.addOperand(Inst.getOperand(1)); // lane
5693 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5694 TmpInst.addOperand(Inst.getOperand(5));
5695 Inst = TmpInst;
5696 return true;
5697 }
5698
Jim Grosbach8b31f952012-01-23 19:39:08 +00005699 case ARM::VST1LNdAsm_8:
5700 case ARM::VST1LNdAsm_16:
5701 case ARM::VST1LNdAsm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005702 MCInst TmpInst;
5703 // Shuffle the operands around so the lane index operand is in the
5704 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005705 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005706 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005707 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5708 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5709 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5710 TmpInst.addOperand(Inst.getOperand(1)); // lane
5711 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5712 TmpInst.addOperand(Inst.getOperand(5));
5713 Inst = TmpInst;
5714 return true;
5715 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005716
Jim Grosbach8b31f952012-01-23 19:39:08 +00005717 case ARM::VST2LNdAsm_8:
5718 case ARM::VST2LNdAsm_16:
5719 case ARM::VST2LNdAsm_32:
5720 case ARM::VST2LNqAsm_16:
5721 case ARM::VST2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005722 MCInst TmpInst;
5723 // Shuffle the operands around so the lane index operand is in the
5724 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005725 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005726 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005727 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5728 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5729 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005730 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5731 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005732 TmpInst.addOperand(Inst.getOperand(1)); // lane
5733 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5734 TmpInst.addOperand(Inst.getOperand(5));
5735 Inst = TmpInst;
5736 return true;
5737 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005738
5739 case ARM::VST3LNdAsm_8:
5740 case ARM::VST3LNdAsm_16:
5741 case ARM::VST3LNdAsm_32:
5742 case ARM::VST3LNqAsm_16:
5743 case ARM::VST3LNqAsm_32: {
5744 MCInst TmpInst;
5745 // Shuffle the operands around so the lane index operand is in the
5746 // right place.
5747 unsigned Spacing;
5748 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5749 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5750 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5751 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5752 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5753 Spacing));
5754 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5755 Spacing * 2));
5756 TmpInst.addOperand(Inst.getOperand(1)); // lane
5757 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5758 TmpInst.addOperand(Inst.getOperand(5));
5759 Inst = TmpInst;
5760 return true;
5761 }
5762
Jim Grosbach88a54de2012-01-24 18:53:13 +00005763 case ARM::VST4LNdAsm_8:
5764 case ARM::VST4LNdAsm_16:
5765 case ARM::VST4LNdAsm_32:
5766 case ARM::VST4LNqAsm_16:
5767 case ARM::VST4LNqAsm_32: {
5768 MCInst TmpInst;
5769 // Shuffle the operands around so the lane index operand is in the
5770 // right place.
5771 unsigned Spacing;
5772 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5773 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5774 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5775 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5776 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5777 Spacing));
5778 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5779 Spacing * 2));
5780 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5781 Spacing * 3));
5782 TmpInst.addOperand(Inst.getOperand(1)); // lane
5783 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5784 TmpInst.addOperand(Inst.getOperand(5));
5785 Inst = TmpInst;
5786 return true;
5787 }
5788
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005789 // Handle NEON VLD complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005790 case ARM::VLD1LNdWB_register_Asm_8:
5791 case ARM::VLD1LNdWB_register_Asm_16:
5792 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005793 MCInst TmpInst;
5794 // Shuffle the operands around so the lane index operand is in the
5795 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005796 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005797 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005798 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5799 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5800 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5801 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5802 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5803 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5804 TmpInst.addOperand(Inst.getOperand(1)); // lane
5805 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5806 TmpInst.addOperand(Inst.getOperand(6));
5807 Inst = TmpInst;
5808 return true;
5809 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005810
Jim Grosbach8b31f952012-01-23 19:39:08 +00005811 case ARM::VLD2LNdWB_register_Asm_8:
5812 case ARM::VLD2LNdWB_register_Asm_16:
5813 case ARM::VLD2LNdWB_register_Asm_32:
5814 case ARM::VLD2LNqWB_register_Asm_16:
5815 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005816 MCInst TmpInst;
5817 // Shuffle the operands around so the lane index operand is in the
5818 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005819 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005820 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005821 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005822 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5823 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005824 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5825 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5826 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5827 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5828 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005829 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5830 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005831 TmpInst.addOperand(Inst.getOperand(1)); // lane
5832 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5833 TmpInst.addOperand(Inst.getOperand(6));
5834 Inst = TmpInst;
5835 return true;
5836 }
5837
Jim Grosbach3a678af2012-01-23 21:53:26 +00005838 case ARM::VLD3LNdWB_register_Asm_8:
5839 case ARM::VLD3LNdWB_register_Asm_16:
5840 case ARM::VLD3LNdWB_register_Asm_32:
5841 case ARM::VLD3LNqWB_register_Asm_16:
5842 case ARM::VLD3LNqWB_register_Asm_32: {
5843 MCInst TmpInst;
5844 // Shuffle the operands around so the lane index operand is in the
5845 // right place.
5846 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005847 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005848 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5850 Spacing));
5851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005852 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005853 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5854 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5855 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5856 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5857 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5859 Spacing));
5860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005861 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005862 TmpInst.addOperand(Inst.getOperand(1)); // lane
5863 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5864 TmpInst.addOperand(Inst.getOperand(6));
5865 Inst = TmpInst;
5866 return true;
5867 }
5868
Jim Grosbache983a132012-01-24 18:37:25 +00005869 case ARM::VLD4LNdWB_register_Asm_8:
5870 case ARM::VLD4LNdWB_register_Asm_16:
5871 case ARM::VLD4LNdWB_register_Asm_32:
5872 case ARM::VLD4LNqWB_register_Asm_16:
5873 case ARM::VLD4LNqWB_register_Asm_32: {
5874 MCInst TmpInst;
5875 // Shuffle the operands around so the lane index operand is in the
5876 // right place.
5877 unsigned Spacing;
5878 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5879 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5880 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5881 Spacing));
5882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5883 Spacing * 2));
5884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5885 Spacing * 3));
5886 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5887 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5888 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5889 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5890 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5891 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5892 Spacing));
5893 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5894 Spacing * 2));
5895 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5896 Spacing * 3));
5897 TmpInst.addOperand(Inst.getOperand(1)); // lane
5898 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5899 TmpInst.addOperand(Inst.getOperand(6));
5900 Inst = TmpInst;
5901 return true;
5902 }
5903
Jim Grosbach8b31f952012-01-23 19:39:08 +00005904 case ARM::VLD1LNdWB_fixed_Asm_8:
5905 case ARM::VLD1LNdWB_fixed_Asm_16:
5906 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005907 MCInst TmpInst;
5908 // Shuffle the operands around so the lane index operand is in the
5909 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005910 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005911 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005912 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5913 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5914 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5915 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5916 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5917 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
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 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005924
Jim Grosbach8b31f952012-01-23 19:39:08 +00005925 case ARM::VLD2LNdWB_fixed_Asm_8:
5926 case ARM::VLD2LNdWB_fixed_Asm_16:
5927 case ARM::VLD2LNdWB_fixed_Asm_32:
5928 case ARM::VLD2LNqWB_fixed_Asm_16:
5929 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005930 MCInst TmpInst;
5931 // Shuffle the operands around so the lane index operand is in the
5932 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005933 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005934 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005935 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005936 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5937 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005938 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5939 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5940 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5941 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5942 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005943 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5944 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005945 TmpInst.addOperand(Inst.getOperand(1)); // lane
5946 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5947 TmpInst.addOperand(Inst.getOperand(5));
5948 Inst = TmpInst;
5949 return true;
5950 }
5951
Jim Grosbach3a678af2012-01-23 21:53:26 +00005952 case ARM::VLD3LNdWB_fixed_Asm_8:
5953 case ARM::VLD3LNdWB_fixed_Asm_16:
5954 case ARM::VLD3LNdWB_fixed_Asm_32:
5955 case ARM::VLD3LNqWB_fixed_Asm_16:
5956 case ARM::VLD3LNqWB_fixed_Asm_32: {
5957 MCInst TmpInst;
5958 // Shuffle the operands around so the lane index operand is in the
5959 // right place.
5960 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005961 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005962 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5963 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5964 Spacing));
5965 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005966 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005967 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5968 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5969 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5970 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5971 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5972 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5973 Spacing));
5974 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005975 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005976 TmpInst.addOperand(Inst.getOperand(1)); // lane
5977 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5978 TmpInst.addOperand(Inst.getOperand(5));
5979 Inst = TmpInst;
5980 return true;
5981 }
5982
Jim Grosbache983a132012-01-24 18:37:25 +00005983 case ARM::VLD4LNdWB_fixed_Asm_8:
5984 case ARM::VLD4LNdWB_fixed_Asm_16:
5985 case ARM::VLD4LNdWB_fixed_Asm_32:
5986 case ARM::VLD4LNqWB_fixed_Asm_16:
5987 case ARM::VLD4LNqWB_fixed_Asm_32: {
5988 MCInst TmpInst;
5989 // Shuffle the operands around so the lane index operand is in the
5990 // right place.
5991 unsigned Spacing;
5992 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5993 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5994 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5995 Spacing));
5996 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5997 Spacing * 2));
5998 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5999 Spacing * 3));
6000 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6001 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6002 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6003 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6004 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6006 Spacing));
6007 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6008 Spacing * 2));
6009 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6010 Spacing * 3));
6011 TmpInst.addOperand(Inst.getOperand(1)); // lane
6012 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6013 TmpInst.addOperand(Inst.getOperand(5));
6014 Inst = TmpInst;
6015 return true;
6016 }
6017
Jim Grosbach8b31f952012-01-23 19:39:08 +00006018 case ARM::VLD1LNdAsm_8:
6019 case ARM::VLD1LNdAsm_16:
6020 case ARM::VLD1LNdAsm_32: {
Jim Grosbach7636bf62011-12-02 00:35:16 +00006021 MCInst TmpInst;
6022 // Shuffle the operands around so the lane index operand is in the
6023 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006024 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006025 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach7636bf62011-12-02 00:35:16 +00006026 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6027 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6028 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6029 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6030 TmpInst.addOperand(Inst.getOperand(1)); // lane
6031 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6032 TmpInst.addOperand(Inst.getOperand(5));
6033 Inst = TmpInst;
6034 return true;
6035 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006036
Jim Grosbach8b31f952012-01-23 19:39:08 +00006037 case ARM::VLD2LNdAsm_8:
6038 case ARM::VLD2LNdAsm_16:
6039 case ARM::VLD2LNdAsm_32:
6040 case ARM::VLD2LNqAsm_16:
6041 case ARM::VLD2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006042 MCInst TmpInst;
6043 // Shuffle the operands around so the lane index operand is in the
6044 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006045 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006046 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006047 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006048 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6049 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006050 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6051 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6052 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006053 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6054 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006055 TmpInst.addOperand(Inst.getOperand(1)); // lane
6056 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6057 TmpInst.addOperand(Inst.getOperand(5));
6058 Inst = TmpInst;
6059 return true;
6060 }
Jim Grosbach3a678af2012-01-23 21:53:26 +00006061
6062 case ARM::VLD3LNdAsm_8:
6063 case ARM::VLD3LNdAsm_16:
6064 case ARM::VLD3LNdAsm_32:
6065 case ARM::VLD3LNqAsm_16:
6066 case ARM::VLD3LNqAsm_32: {
6067 MCInst TmpInst;
6068 // Shuffle the operands around so the lane index operand is in the
6069 // right place.
6070 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006071 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006072 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6074 Spacing));
6075 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006076 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006077 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6078 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6079 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6081 Spacing));
6082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006083 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006084 TmpInst.addOperand(Inst.getOperand(1)); // lane
6085 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6086 TmpInst.addOperand(Inst.getOperand(5));
6087 Inst = TmpInst;
6088 return true;
6089 }
6090
Jim Grosbache983a132012-01-24 18:37:25 +00006091 case ARM::VLD4LNdAsm_8:
6092 case ARM::VLD4LNdAsm_16:
6093 case ARM::VLD4LNdAsm_32:
6094 case ARM::VLD4LNqAsm_16:
6095 case ARM::VLD4LNqAsm_32: {
6096 MCInst TmpInst;
6097 // Shuffle the operands around so the lane index operand is in the
6098 // right place.
6099 unsigned Spacing;
6100 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6101 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6102 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6103 Spacing));
6104 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6105 Spacing * 2));
6106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6107 Spacing * 3));
6108 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6109 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6110 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6111 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6112 Spacing));
6113 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6114 Spacing * 2));
6115 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6116 Spacing * 3));
6117 TmpInst.addOperand(Inst.getOperand(1)); // lane
6118 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6119 TmpInst.addOperand(Inst.getOperand(5));
6120 Inst = TmpInst;
6121 return true;
6122 }
6123
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00006124 // VLD3DUP single 3-element structure to all lanes instructions.
6125 case ARM::VLD3DUPdAsm_8:
6126 case ARM::VLD3DUPdAsm_16:
6127 case ARM::VLD3DUPdAsm_32:
6128 case ARM::VLD3DUPqAsm_8:
6129 case ARM::VLD3DUPqAsm_16:
6130 case ARM::VLD3DUPqAsm_32: {
6131 MCInst TmpInst;
6132 unsigned Spacing;
6133 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6134 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6135 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6136 Spacing));
6137 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6138 Spacing * 2));
6139 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6140 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6141 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6142 TmpInst.addOperand(Inst.getOperand(4));
6143 Inst = TmpInst;
6144 return true;
6145 }
6146
6147 case ARM::VLD3DUPdWB_fixed_Asm_8:
6148 case ARM::VLD3DUPdWB_fixed_Asm_16:
6149 case ARM::VLD3DUPdWB_fixed_Asm_32:
6150 case ARM::VLD3DUPqWB_fixed_Asm_8:
6151 case ARM::VLD3DUPqWB_fixed_Asm_16:
6152 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6153 MCInst TmpInst;
6154 unsigned Spacing;
6155 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6156 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6157 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6158 Spacing));
6159 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6160 Spacing * 2));
6161 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6162 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6163 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6164 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6165 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6166 TmpInst.addOperand(Inst.getOperand(4));
6167 Inst = TmpInst;
6168 return true;
6169 }
6170
6171 case ARM::VLD3DUPdWB_register_Asm_8:
6172 case ARM::VLD3DUPdWB_register_Asm_16:
6173 case ARM::VLD3DUPdWB_register_Asm_32:
6174 case ARM::VLD3DUPqWB_register_Asm_8:
6175 case ARM::VLD3DUPqWB_register_Asm_16:
6176 case ARM::VLD3DUPqWB_register_Asm_32: {
6177 MCInst TmpInst;
6178 unsigned Spacing;
6179 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6180 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6181 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6182 Spacing));
6183 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6184 Spacing * 2));
6185 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6186 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6187 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6188 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6189 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6190 TmpInst.addOperand(Inst.getOperand(5));
6191 Inst = TmpInst;
6192 return true;
6193 }
6194
Jim Grosbachc387fc62012-01-23 23:20:46 +00006195 // VLD3 multiple 3-element structure instructions.
6196 case ARM::VLD3dAsm_8:
6197 case ARM::VLD3dAsm_16:
6198 case ARM::VLD3dAsm_32:
6199 case ARM::VLD3qAsm_8:
6200 case ARM::VLD3qAsm_16:
6201 case ARM::VLD3qAsm_32: {
6202 MCInst TmpInst;
6203 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006204 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006205 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6206 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6207 Spacing));
6208 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6209 Spacing * 2));
6210 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6211 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6212 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6213 TmpInst.addOperand(Inst.getOperand(4));
6214 Inst = TmpInst;
6215 return true;
6216 }
6217
6218 case ARM::VLD3dWB_fixed_Asm_8:
6219 case ARM::VLD3dWB_fixed_Asm_16:
6220 case ARM::VLD3dWB_fixed_Asm_32:
6221 case ARM::VLD3qWB_fixed_Asm_8:
6222 case ARM::VLD3qWB_fixed_Asm_16:
6223 case ARM::VLD3qWB_fixed_Asm_32: {
6224 MCInst TmpInst;
6225 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006226 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006227 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6228 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6229 Spacing));
6230 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6231 Spacing * 2));
6232 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6233 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6234 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6235 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6236 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6237 TmpInst.addOperand(Inst.getOperand(4));
6238 Inst = TmpInst;
6239 return true;
6240 }
6241
6242 case ARM::VLD3dWB_register_Asm_8:
6243 case ARM::VLD3dWB_register_Asm_16:
6244 case ARM::VLD3dWB_register_Asm_32:
6245 case ARM::VLD3qWB_register_Asm_8:
6246 case ARM::VLD3qWB_register_Asm_16:
6247 case ARM::VLD3qWB_register_Asm_32: {
6248 MCInst TmpInst;
6249 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006250 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006251 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6252 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 Spacing));
6254 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6255 Spacing * 2));
6256 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6257 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6258 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6259 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6260 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6261 TmpInst.addOperand(Inst.getOperand(5));
6262 Inst = TmpInst;
6263 return true;
6264 }
6265
Jim Grosbacha57a36a2012-01-25 00:01:08 +00006266 // VLD4DUP single 3-element structure to all lanes instructions.
6267 case ARM::VLD4DUPdAsm_8:
6268 case ARM::VLD4DUPdAsm_16:
6269 case ARM::VLD4DUPdAsm_32:
6270 case ARM::VLD4DUPqAsm_8:
6271 case ARM::VLD4DUPqAsm_16:
6272 case ARM::VLD4DUPqAsm_32: {
6273 MCInst TmpInst;
6274 unsigned Spacing;
6275 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6276 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6277 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6278 Spacing));
6279 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6280 Spacing * 2));
6281 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6282 Spacing * 3));
6283 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6284 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6285 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6286 TmpInst.addOperand(Inst.getOperand(4));
6287 Inst = TmpInst;
6288 return true;
6289 }
6290
6291 case ARM::VLD4DUPdWB_fixed_Asm_8:
6292 case ARM::VLD4DUPdWB_fixed_Asm_16:
6293 case ARM::VLD4DUPdWB_fixed_Asm_32:
6294 case ARM::VLD4DUPqWB_fixed_Asm_8:
6295 case ARM::VLD4DUPqWB_fixed_Asm_16:
6296 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6297 MCInst TmpInst;
6298 unsigned Spacing;
6299 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6300 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6301 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 Spacing));
6303 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6304 Spacing * 2));
6305 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6306 Spacing * 3));
6307 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6308 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6309 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6310 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6311 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6312 TmpInst.addOperand(Inst.getOperand(4));
6313 Inst = TmpInst;
6314 return true;
6315 }
6316
6317 case ARM::VLD4DUPdWB_register_Asm_8:
6318 case ARM::VLD4DUPdWB_register_Asm_16:
6319 case ARM::VLD4DUPdWB_register_Asm_32:
6320 case ARM::VLD4DUPqWB_register_Asm_8:
6321 case ARM::VLD4DUPqWB_register_Asm_16:
6322 case ARM::VLD4DUPqWB_register_Asm_32: {
6323 MCInst TmpInst;
6324 unsigned Spacing;
6325 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6326 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6327 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6328 Spacing));
6329 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6330 Spacing * 2));
6331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6332 Spacing * 3));
6333 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6334 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6335 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6336 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6337 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6338 TmpInst.addOperand(Inst.getOperand(5));
6339 Inst = TmpInst;
6340 return true;
6341 }
6342
6343 // VLD4 multiple 4-element structure instructions.
Jim Grosbach8abe7e32012-01-24 00:43:17 +00006344 case ARM::VLD4dAsm_8:
6345 case ARM::VLD4dAsm_16:
6346 case ARM::VLD4dAsm_32:
6347 case ARM::VLD4qAsm_8:
6348 case ARM::VLD4qAsm_16:
6349 case ARM::VLD4qAsm_32: {
6350 MCInst TmpInst;
6351 unsigned Spacing;
6352 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6353 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6354 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6355 Spacing));
6356 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6357 Spacing * 2));
6358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6359 Spacing * 3));
6360 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6361 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6362 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6363 TmpInst.addOperand(Inst.getOperand(4));
6364 Inst = TmpInst;
6365 return true;
6366 }
6367
6368 case ARM::VLD4dWB_fixed_Asm_8:
6369 case ARM::VLD4dWB_fixed_Asm_16:
6370 case ARM::VLD4dWB_fixed_Asm_32:
6371 case ARM::VLD4qWB_fixed_Asm_8:
6372 case ARM::VLD4qWB_fixed_Asm_16:
6373 case ARM::VLD4qWB_fixed_Asm_32: {
6374 MCInst TmpInst;
6375 unsigned Spacing;
6376 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6377 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6378 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6379 Spacing));
6380 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6381 Spacing * 2));
6382 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6383 Spacing * 3));
6384 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6385 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6386 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6387 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6388 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6389 TmpInst.addOperand(Inst.getOperand(4));
6390 Inst = TmpInst;
6391 return true;
6392 }
6393
6394 case ARM::VLD4dWB_register_Asm_8:
6395 case ARM::VLD4dWB_register_Asm_16:
6396 case ARM::VLD4dWB_register_Asm_32:
6397 case ARM::VLD4qWB_register_Asm_8:
6398 case ARM::VLD4qWB_register_Asm_16:
6399 case ARM::VLD4qWB_register_Asm_32: {
6400 MCInst TmpInst;
6401 unsigned Spacing;
6402 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6403 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6405 Spacing));
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6407 Spacing * 2));
6408 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6409 Spacing * 3));
6410 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6411 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6412 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6413 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6414 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6415 TmpInst.addOperand(Inst.getOperand(5));
6416 Inst = TmpInst;
6417 return true;
6418 }
6419
Jim Grosbachd7433e22012-01-23 23:45:44 +00006420 // VST3 multiple 3-element structure instructions.
6421 case ARM::VST3dAsm_8:
6422 case ARM::VST3dAsm_16:
6423 case ARM::VST3dAsm_32:
6424 case ARM::VST3qAsm_8:
6425 case ARM::VST3qAsm_16:
6426 case ARM::VST3qAsm_32: {
6427 MCInst TmpInst;
6428 unsigned Spacing;
6429 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6430 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6431 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6432 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6433 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6434 Spacing));
6435 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6436 Spacing * 2));
6437 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6438 TmpInst.addOperand(Inst.getOperand(4));
6439 Inst = TmpInst;
6440 return true;
6441 }
6442
6443 case ARM::VST3dWB_fixed_Asm_8:
6444 case ARM::VST3dWB_fixed_Asm_16:
6445 case ARM::VST3dWB_fixed_Asm_32:
6446 case ARM::VST3qWB_fixed_Asm_8:
6447 case ARM::VST3qWB_fixed_Asm_16:
6448 case ARM::VST3qWB_fixed_Asm_32: {
6449 MCInst TmpInst;
6450 unsigned Spacing;
6451 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6452 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6453 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6454 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6455 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6456 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6457 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6458 Spacing));
6459 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6460 Spacing * 2));
6461 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6462 TmpInst.addOperand(Inst.getOperand(4));
6463 Inst = TmpInst;
6464 return true;
6465 }
6466
6467 case ARM::VST3dWB_register_Asm_8:
6468 case ARM::VST3dWB_register_Asm_16:
6469 case ARM::VST3dWB_register_Asm_32:
6470 case ARM::VST3qWB_register_Asm_8:
6471 case ARM::VST3qWB_register_Asm_16:
6472 case ARM::VST3qWB_register_Asm_32: {
6473 MCInst TmpInst;
6474 unsigned Spacing;
6475 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6476 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6477 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6478 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6479 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6480 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6481 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6482 Spacing));
6483 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6484 Spacing * 2));
6485 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6486 TmpInst.addOperand(Inst.getOperand(5));
6487 Inst = TmpInst;
6488 return true;
6489 }
6490
Jim Grosbach539aab72012-01-24 00:58:13 +00006491 // VST4 multiple 3-element structure instructions.
6492 case ARM::VST4dAsm_8:
6493 case ARM::VST4dAsm_16:
6494 case ARM::VST4dAsm_32:
6495 case ARM::VST4qAsm_8:
6496 case ARM::VST4qAsm_16:
6497 case ARM::VST4qAsm_32: {
6498 MCInst TmpInst;
6499 unsigned Spacing;
6500 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6501 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6502 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6503 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6505 Spacing));
6506 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6507 Spacing * 2));
6508 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6509 Spacing * 3));
6510 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6511 TmpInst.addOperand(Inst.getOperand(4));
6512 Inst = TmpInst;
6513 return true;
6514 }
6515
6516 case ARM::VST4dWB_fixed_Asm_8:
6517 case ARM::VST4dWB_fixed_Asm_16:
6518 case ARM::VST4dWB_fixed_Asm_32:
6519 case ARM::VST4qWB_fixed_Asm_8:
6520 case ARM::VST4qWB_fixed_Asm_16:
6521 case ARM::VST4qWB_fixed_Asm_32: {
6522 MCInst TmpInst;
6523 unsigned Spacing;
6524 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6525 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6526 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6527 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6528 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6529 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6531 Spacing));
6532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6533 Spacing * 2));
6534 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6535 Spacing * 3));
6536 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6537 TmpInst.addOperand(Inst.getOperand(4));
6538 Inst = TmpInst;
6539 return true;
6540 }
6541
6542 case ARM::VST4dWB_register_Asm_8:
6543 case ARM::VST4dWB_register_Asm_16:
6544 case ARM::VST4dWB_register_Asm_32:
6545 case ARM::VST4qWB_register_Asm_8:
6546 case ARM::VST4qWB_register_Asm_16:
6547 case ARM::VST4qWB_register_Asm_32: {
6548 MCInst TmpInst;
6549 unsigned Spacing;
6550 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6551 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6552 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6553 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6554 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6555 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6557 Spacing));
6558 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6559 Spacing * 2));
6560 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6561 Spacing * 3));
6562 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6563 TmpInst.addOperand(Inst.getOperand(5));
6564 Inst = TmpInst;
6565 return true;
6566 }
6567
Jim Grosbach863d2af2011-12-13 22:45:11 +00006568 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00006569 case ARM::t2MOVsr:
6570 case ARM::t2MOVSsr: {
6571 // Which instruction to expand to depends on the CCOut operand and
6572 // whether we're in an IT block if the register operands are low
6573 // registers.
6574 bool isNarrow = false;
6575 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6576 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6577 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6578 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6579 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6580 isNarrow = true;
6581 MCInst TmpInst;
6582 unsigned newOpc;
6583 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6584 default: llvm_unreachable("unexpected opcode!");
6585 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6586 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6587 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6588 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6589 }
6590 TmpInst.setOpcode(newOpc);
6591 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6592 if (isNarrow)
6593 TmpInst.addOperand(MCOperand::CreateReg(
6594 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6595 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6596 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6597 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6598 TmpInst.addOperand(Inst.getOperand(5));
6599 if (!isNarrow)
6600 TmpInst.addOperand(MCOperand::CreateReg(
6601 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6602 Inst = TmpInst;
6603 return true;
6604 }
Jim Grosbach863d2af2011-12-13 22:45:11 +00006605 case ARM::t2MOVsi:
6606 case ARM::t2MOVSsi: {
6607 // Which instruction to expand to depends on the CCOut operand and
6608 // whether we're in an IT block if the register operands are low
6609 // registers.
6610 bool isNarrow = false;
6611 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6612 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6613 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6614 isNarrow = true;
6615 MCInst TmpInst;
6616 unsigned newOpc;
6617 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6618 default: llvm_unreachable("unexpected opcode!");
6619 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6620 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6621 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6622 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach520dc782011-12-21 21:04:19 +00006623 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006624 }
6625 unsigned Ammount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6626 if (Ammount == 32) Ammount = 0;
6627 TmpInst.setOpcode(newOpc);
6628 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6629 if (isNarrow)
6630 TmpInst.addOperand(MCOperand::CreateReg(
6631 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6632 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach520dc782011-12-21 21:04:19 +00006633 if (newOpc != ARM::t2RRX)
6634 TmpInst.addOperand(MCOperand::CreateImm(Ammount));
Jim Grosbach863d2af2011-12-13 22:45:11 +00006635 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6636 TmpInst.addOperand(Inst.getOperand(4));
6637 if (!isNarrow)
6638 TmpInst.addOperand(MCOperand::CreateReg(
6639 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6640 Inst = TmpInst;
6641 return true;
6642 }
6643 // Handle the ARM mode MOV complex aliases.
Jim Grosbach23f22072011-11-16 18:31:45 +00006644 case ARM::ASRr:
6645 case ARM::LSRr:
6646 case ARM::LSLr:
6647 case ARM::RORr: {
6648 ARM_AM::ShiftOpc ShiftTy;
6649 switch(Inst.getOpcode()) {
6650 default: llvm_unreachable("unexpected opcode!");
6651 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6652 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6653 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6654 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6655 }
Jim Grosbach23f22072011-11-16 18:31:45 +00006656 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6657 MCInst TmpInst;
6658 TmpInst.setOpcode(ARM::MOVsr);
6659 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6660 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6661 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6662 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6663 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6664 TmpInst.addOperand(Inst.getOperand(4));
6665 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6666 Inst = TmpInst;
6667 return true;
6668 }
Jim Grosbachee10ff82011-11-10 19:18:01 +00006669 case ARM::ASRi:
6670 case ARM::LSRi:
6671 case ARM::LSLi:
6672 case ARM::RORi: {
6673 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006674 switch(Inst.getOpcode()) {
6675 default: llvm_unreachable("unexpected opcode!");
6676 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6677 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6678 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6679 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6680 }
6681 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach48b368b2011-11-16 19:05:59 +00006682 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachee10ff82011-11-10 19:18:01 +00006683 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6684 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006685 MCInst TmpInst;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006686 TmpInst.setOpcode(Opc);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006687 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6688 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachee10ff82011-11-10 19:18:01 +00006689 if (Opc == ARM::MOVsi)
6690 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach71810ab2011-11-10 16:44:55 +00006691 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6692 TmpInst.addOperand(Inst.getOperand(4));
6693 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6694 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006695 return true;
Jim Grosbach71810ab2011-11-10 16:44:55 +00006696 }
Jim Grosbach48b368b2011-11-16 19:05:59 +00006697 case ARM::RRXi: {
6698 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6699 MCInst TmpInst;
6700 TmpInst.setOpcode(ARM::MOVsi);
6701 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6702 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6703 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6704 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6705 TmpInst.addOperand(Inst.getOperand(3));
6706 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6707 Inst = TmpInst;
6708 return true;
6709 }
Jim Grosbach0352b462011-11-10 23:58:34 +00006710 case ARM::t2LDMIA_UPD: {
6711 // If this is a load of a single register, then we should use
6712 // a post-indexed LDR instruction instead, per the ARM ARM.
6713 if (Inst.getNumOperands() != 5)
6714 return false;
6715 MCInst TmpInst;
6716 TmpInst.setOpcode(ARM::t2LDR_POST);
6717 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6718 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6719 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6720 TmpInst.addOperand(MCOperand::CreateImm(4));
6721 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6722 TmpInst.addOperand(Inst.getOperand(3));
6723 Inst = TmpInst;
6724 return true;
6725 }
6726 case ARM::t2STMDB_UPD: {
6727 // If this is a store of a single register, then we should use
6728 // a pre-indexed STR instruction instead, per the ARM ARM.
6729 if (Inst.getNumOperands() != 5)
6730 return false;
6731 MCInst TmpInst;
6732 TmpInst.setOpcode(ARM::t2STR_PRE);
6733 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6734 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6735 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6736 TmpInst.addOperand(MCOperand::CreateImm(-4));
6737 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6738 TmpInst.addOperand(Inst.getOperand(3));
6739 Inst = TmpInst;
6740 return true;
6741 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00006742 case ARM::LDMIA_UPD:
6743 // If this is a load of a single register via a 'pop', then we should use
6744 // a post-indexed LDR instruction instead, per the ARM ARM.
6745 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6746 Inst.getNumOperands() == 5) {
6747 MCInst TmpInst;
6748 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6749 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6750 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6751 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6752 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6753 TmpInst.addOperand(MCOperand::CreateImm(4));
6754 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6755 TmpInst.addOperand(Inst.getOperand(3));
6756 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006757 return true;
Jim Grosbachf8fce712011-08-11 17:35:48 +00006758 }
6759 break;
Jim Grosbachf6713912011-08-11 18:07:11 +00006760 case ARM::STMDB_UPD:
6761 // If this is a store of a single register via a 'push', then we should use
6762 // a pre-indexed STR instruction instead, per the ARM ARM.
6763 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6764 Inst.getNumOperands() == 5) {
6765 MCInst TmpInst;
6766 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6767 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6768 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6769 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6770 TmpInst.addOperand(MCOperand::CreateImm(-4));
6771 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6772 TmpInst.addOperand(Inst.getOperand(3));
6773 Inst = TmpInst;
6774 }
6775 break;
Jim Grosbachda847862011-12-05 21:06:26 +00006776 case ARM::t2ADDri12:
6777 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6778 // mnemonic was used (not "addw"), encoding T3 is preferred.
6779 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6780 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6781 break;
6782 Inst.setOpcode(ARM::t2ADDri);
6783 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6784 break;
6785 case ARM::t2SUBri12:
6786 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6787 // mnemonic was used (not "subw"), encoding T3 is preferred.
6788 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6789 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6790 break;
6791 Inst.setOpcode(ARM::t2SUBri);
6792 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6793 break;
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006794 case ARM::tADDi8:
Jim Grosbach0f3abd82011-08-31 17:07:33 +00006795 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6796 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6797 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6798 // to encoding T1 if <Rd> is omitted."
Jim Grosbach83ec8772011-11-10 23:42:14 +00006799 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006800 Inst.setOpcode(ARM::tADDi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006801 return true;
6802 }
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006803 break;
Jim Grosbachf67e8552011-09-16 22:58:42 +00006804 case ARM::tSUBi8:
6805 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6806 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6807 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6808 // to encoding T1 if <Rd> is omitted."
Jim Grosbach83ec8772011-11-10 23:42:14 +00006809 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachf67e8552011-09-16 22:58:42 +00006810 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006811 return true;
6812 }
Jim Grosbachf67e8552011-09-16 22:58:42 +00006813 break;
Jim Grosbach927b9df2011-12-05 22:16:39 +00006814 case ARM::t2ADDrr: {
6815 // If the destination and first source operand are the same, and
6816 // there's no setting of the flags, use encoding T2 instead of T3.
6817 // Note that this is only for ADD, not SUB. This mirrors the system
6818 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
6819 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
6820 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbach713c7022011-12-05 22:27:04 +00006821 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6822 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbach927b9df2011-12-05 22:16:39 +00006823 break;
6824 MCInst TmpInst;
6825 TmpInst.setOpcode(ARM::tADDhirr);
6826 TmpInst.addOperand(Inst.getOperand(0));
6827 TmpInst.addOperand(Inst.getOperand(0));
6828 TmpInst.addOperand(Inst.getOperand(2));
6829 TmpInst.addOperand(Inst.getOperand(3));
6830 TmpInst.addOperand(Inst.getOperand(4));
6831 Inst = TmpInst;
6832 return true;
6833 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006834 case ARM::tB:
6835 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006836 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006837 Inst.setOpcode(ARM::tBcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006838 return true;
6839 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006840 break;
6841 case ARM::t2B:
6842 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006843 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006844 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006845 return true;
6846 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006847 break;
Jim Grosbachc0755102011-08-31 21:17:31 +00006848 case ARM::t2Bcc:
Jim Grosbacha1109882011-09-02 23:22:08 +00006849 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006850 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbachc0755102011-08-31 21:17:31 +00006851 Inst.setOpcode(ARM::t2B);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006852 return true;
6853 }
Jim Grosbachc0755102011-08-31 21:17:31 +00006854 break;
Jim Grosbach395b4532011-08-17 22:57:40 +00006855 case ARM::tBcc:
6856 // If the conditional is AL, we really want tB.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006857 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbach395b4532011-08-17 22:57:40 +00006858 Inst.setOpcode(ARM::tB);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006859 return true;
6860 }
Jim Grosbach3ce23d32011-08-18 16:08:39 +00006861 break;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00006862 case ARM::tLDMIA: {
6863 // If the register list contains any high registers, or if the writeback
6864 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
6865 // instead if we're in Thumb2. Otherwise, this should have generated
6866 // an error in validateInstruction().
6867 unsigned Rn = Inst.getOperand(0).getReg();
6868 bool hasWritebackToken =
6869 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6870 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
6871 bool listContainsBase;
6872 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
6873 (!listContainsBase && !hasWritebackToken) ||
6874 (listContainsBase && hasWritebackToken)) {
6875 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
6876 assert (isThumbTwo());
6877 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
6878 // If we're switching to the updating version, we need to insert
6879 // the writeback tied operand.
6880 if (hasWritebackToken)
6881 Inst.insert(Inst.begin(),
6882 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbach83ec8772011-11-10 23:42:14 +00006883 return true;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00006884 }
6885 break;
6886 }
Jim Grosbach8213c962011-09-16 20:50:13 +00006887 case ARM::tSTMIA_UPD: {
6888 // If the register list contains any high registers, we need to use
6889 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
6890 // should have generated an error in validateInstruction().
6891 unsigned Rn = Inst.getOperand(0).getReg();
6892 bool listContainsBase;
6893 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
6894 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
6895 assert (isThumbTwo());
6896 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006897 return true;
Jim Grosbach8213c962011-09-16 20:50:13 +00006898 }
6899 break;
6900 }
Jim Grosbach54026372011-11-10 23:17:11 +00006901 case ARM::tPOP: {
6902 bool listContainsBase;
6903 // If the register list contains any high registers, we need to use
6904 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
6905 // should have generated an error in validateInstruction().
6906 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00006907 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00006908 assert (isThumbTwo());
6909 Inst.setOpcode(ARM::t2LDMIA_UPD);
6910 // Add the base register and writeback operands.
6911 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6912 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00006913 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00006914 }
6915 case ARM::tPUSH: {
6916 bool listContainsBase;
6917 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00006918 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00006919 assert (isThumbTwo());
6920 Inst.setOpcode(ARM::t2STMDB_UPD);
6921 // Add the base register and writeback operands.
6922 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6923 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00006924 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00006925 }
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006926 case ARM::t2MOVi: {
6927 // If we can use the 16-bit encoding and the user didn't explicitly
6928 // request the 32-bit variant, transform it here.
6929 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6930 Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbachc2d31642011-09-14 19:12:11 +00006931 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
6932 Inst.getOperand(4).getReg() == ARM::CPSR) ||
6933 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006934 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6935 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6936 // The operands aren't in the same order for tMOVi8...
6937 MCInst TmpInst;
6938 TmpInst.setOpcode(ARM::tMOVi8);
6939 TmpInst.addOperand(Inst.getOperand(0));
6940 TmpInst.addOperand(Inst.getOperand(4));
6941 TmpInst.addOperand(Inst.getOperand(1));
6942 TmpInst.addOperand(Inst.getOperand(2));
6943 TmpInst.addOperand(Inst.getOperand(3));
6944 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006945 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006946 }
6947 break;
6948 }
6949 case ARM::t2MOVr: {
6950 // If we can use the 16-bit encoding and the user didn't explicitly
6951 // request the 32-bit variant, transform it here.
6952 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6953 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6954 Inst.getOperand(2).getImm() == ARMCC::AL &&
6955 Inst.getOperand(4).getReg() == ARM::CPSR &&
6956 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6957 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6958 // The operands aren't the same for tMOV[S]r... (no cc_out)
6959 MCInst TmpInst;
6960 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
6961 TmpInst.addOperand(Inst.getOperand(0));
6962 TmpInst.addOperand(Inst.getOperand(1));
6963 TmpInst.addOperand(Inst.getOperand(2));
6964 TmpInst.addOperand(Inst.getOperand(3));
6965 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006966 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006967 }
6968 break;
6969 }
Jim Grosbach326efe52011-09-19 20:29:33 +00006970 case ARM::t2SXTH:
Jim Grosbach50f1c372011-09-20 00:46:54 +00006971 case ARM::t2SXTB:
6972 case ARM::t2UXTH:
6973 case ARM::t2UXTB: {
Jim Grosbach326efe52011-09-19 20:29:33 +00006974 // If we can use the 16-bit encoding and the user didn't explicitly
6975 // request the 32-bit variant, transform it here.
6976 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6977 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6978 Inst.getOperand(2).getImm() == 0 &&
6979 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6980 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbach50f1c372011-09-20 00:46:54 +00006981 unsigned NewOpc;
6982 switch (Inst.getOpcode()) {
6983 default: llvm_unreachable("Illegal opcode!");
6984 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
6985 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
6986 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
6987 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
6988 }
Jim Grosbach326efe52011-09-19 20:29:33 +00006989 // The operands aren't the same for thumb1 (no rotate operand).
6990 MCInst TmpInst;
6991 TmpInst.setOpcode(NewOpc);
6992 TmpInst.addOperand(Inst.getOperand(0));
6993 TmpInst.addOperand(Inst.getOperand(1));
6994 TmpInst.addOperand(Inst.getOperand(3));
6995 TmpInst.addOperand(Inst.getOperand(4));
6996 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006997 return true;
Jim Grosbach326efe52011-09-19 20:29:33 +00006998 }
6999 break;
7000 }
Jim Grosbach04b5d932011-12-20 00:59:38 +00007001 case ARM::MOVsi: {
7002 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7003 if (SOpc == ARM_AM::rrx) return false;
7004 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7005 // Shifting by zero is accepted as a vanilla 'MOVr'
7006 MCInst TmpInst;
7007 TmpInst.setOpcode(ARM::MOVr);
7008 TmpInst.addOperand(Inst.getOperand(0));
7009 TmpInst.addOperand(Inst.getOperand(1));
7010 TmpInst.addOperand(Inst.getOperand(3));
7011 TmpInst.addOperand(Inst.getOperand(4));
7012 TmpInst.addOperand(Inst.getOperand(5));
7013 Inst = TmpInst;
7014 return true;
7015 }
7016 return false;
7017 }
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007018 case ARM::ANDrsi:
7019 case ARM::ORRrsi:
7020 case ARM::EORrsi:
7021 case ARM::BICrsi:
7022 case ARM::SUBrsi:
7023 case ARM::ADDrsi: {
7024 unsigned newOpc;
7025 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7026 if (SOpc == ARM_AM::rrx) return false;
7027 switch (Inst.getOpcode()) {
Matt Beaumont-Gay19055cc2012-01-03 19:03:59 +00007028 default: assert(0 && "unexpected opcode!");
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007029 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7030 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7031 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7032 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7033 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7034 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7035 }
7036 // If the shift is by zero, use the non-shifted instruction definition.
7037 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0) {
7038 MCInst TmpInst;
7039 TmpInst.setOpcode(newOpc);
7040 TmpInst.addOperand(Inst.getOperand(0));
7041 TmpInst.addOperand(Inst.getOperand(1));
7042 TmpInst.addOperand(Inst.getOperand(2));
7043 TmpInst.addOperand(Inst.getOperand(4));
7044 TmpInst.addOperand(Inst.getOperand(5));
7045 TmpInst.addOperand(Inst.getOperand(6));
7046 Inst = TmpInst;
7047 return true;
7048 }
7049 return false;
7050 }
Jim Grosbach89df9962011-08-26 21:43:41 +00007051 case ARM::t2IT: {
7052 // The mask bits for all but the first condition are represented as
7053 // the low bit of the condition code value implies 't'. We currently
7054 // always have 1 implies 't', so XOR toggle the bits if the low bit
7055 // of the condition code is zero. The encoding also expects the low
7056 // bit of the condition to be encoded as bit 4 of the mask operand,
7057 // so mask that in if needed
7058 MCOperand &MO = Inst.getOperand(1);
7059 unsigned Mask = MO.getImm();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007060 unsigned OrigMask = Mask;
7061 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach89df9962011-08-26 21:43:41 +00007062 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach89df9962011-08-26 21:43:41 +00007063 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7064 for (unsigned i = 3; i != TZ; --i)
7065 Mask ^= 1 << i;
7066 } else
7067 Mask |= 0x10;
7068 MO.setImm(Mask);
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007069
7070 // Set up the IT block state according to the IT instruction we just
7071 // matched.
7072 assert(!inITBlock() && "nested IT blocks?!");
7073 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7074 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7075 ITState.CurPosition = 0;
7076 ITState.FirstCond = true;
Jim Grosbach89df9962011-08-26 21:43:41 +00007077 break;
7078 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00007079 }
Jim Grosbach83ec8772011-11-10 23:42:14 +00007080 return false;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007081}
7082
Jim Grosbach47a0d522011-08-16 20:45:50 +00007083unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7084 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7085 // suffix depending on whether they're in an IT block or not.
Jim Grosbach194bd892011-08-16 22:20:01 +00007086 unsigned Opc = Inst.getOpcode();
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00007087 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach47a0d522011-08-16 20:45:50 +00007088 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7089 assert(MCID.hasOptionalDef() &&
7090 "optionally flag setting instruction missing optional def operand");
7091 assert(MCID.NumOperands == Inst.getNumOperands() &&
7092 "operand count mismatch!");
7093 // Find the optional-def operand (cc_out).
7094 unsigned OpNo;
7095 for (OpNo = 0;
7096 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7097 ++OpNo)
7098 ;
7099 // If we're parsing Thumb1, reject it completely.
7100 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7101 return Match_MnemonicFail;
7102 // If we're parsing Thumb2, which form is legal depends on whether we're
7103 // in an IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007104 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7105 !inITBlock())
Jim Grosbach47a0d522011-08-16 20:45:50 +00007106 return Match_RequiresITBlock;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007107 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7108 inITBlock())
7109 return Match_RequiresNotITBlock;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007110 }
Jim Grosbach194bd892011-08-16 22:20:01 +00007111 // Some high-register supporting Thumb1 encodings only allow both registers
7112 // to be from r0-r7 when in Thumb2.
7113 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7114 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7115 isARMLowRegister(Inst.getOperand(2).getReg()))
7116 return Match_RequiresThumb2;
7117 // Others only require ARMv6 or later.
Jim Grosbach4ec6e882011-08-19 20:46:54 +00007118 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbach194bd892011-08-16 22:20:01 +00007119 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7120 isARMLowRegister(Inst.getOperand(1).getReg()))
7121 return Match_RequiresV6;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007122 return Match_Success;
7123}
7124
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007125bool ARMAsmParser::
7126MatchAndEmitInstruction(SMLoc IDLoc,
7127 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7128 MCStreamer &Out) {
7129 MCInst Inst;
7130 unsigned ErrorInfo;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007131 unsigned MatchResult;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007132 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007133 switch (MatchResult) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007134 default: break;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007135 case Match_Success:
Jim Grosbach189610f2011-07-26 18:25:39 +00007136 // Context sensitive operand constraints aren't handled by the matcher,
7137 // so check them here.
Jim Grosbacha1109882011-09-02 23:22:08 +00007138 if (validateInstruction(Inst, Operands)) {
7139 // Still progress the IT block, otherwise one wrong condition causes
7140 // nasty cascading errors.
7141 forwardITPosition();
Jim Grosbach189610f2011-07-26 18:25:39 +00007142 return true;
Jim Grosbacha1109882011-09-02 23:22:08 +00007143 }
Jim Grosbach189610f2011-07-26 18:25:39 +00007144
Jim Grosbachf8fce712011-08-11 17:35:48 +00007145 // Some instructions need post-processing to, for example, tweak which
Jim Grosbach83ec8772011-11-10 23:42:14 +00007146 // encoding is selected. Loop on it while changes happen so the
7147 // individual transformations can chain off each other. E.g.,
7148 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7149 while (processInstruction(Inst, Operands))
7150 ;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007151
Jim Grosbacha1109882011-09-02 23:22:08 +00007152 // Only move forward at the very end so that everything in validate
7153 // and process gets a consistent answer about whether we're in an IT
7154 // block.
7155 forwardITPosition();
7156
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007157 Out.EmitInstruction(Inst);
7158 return false;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007159 case Match_MissingFeature:
7160 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
7161 return true;
7162 case Match_InvalidOperand: {
7163 SMLoc ErrorLoc = IDLoc;
7164 if (ErrorInfo != ~0U) {
7165 if (ErrorInfo >= Operands.size())
7166 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00007167
Chris Lattnere73d4f82010-10-28 21:41:58 +00007168 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7169 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7170 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007171
Chris Lattnere73d4f82010-10-28 21:41:58 +00007172 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007173 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007174 case Match_MnemonicFail:
Jim Grosbach47a0d522011-08-16 20:45:50 +00007175 return Error(IDLoc, "invalid instruction");
Daniel Dunbarb4129152011-02-04 17:12:23 +00007176 case Match_ConversionFail:
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00007177 // The converter function will have already emited a diagnostic.
7178 return true;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007179 case Match_RequiresNotITBlock:
7180 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach47a0d522011-08-16 20:45:50 +00007181 case Match_RequiresITBlock:
7182 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbach194bd892011-08-16 22:20:01 +00007183 case Match_RequiresV6:
7184 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7185 case Match_RequiresThumb2:
7186 return Error(IDLoc, "instruction variant requires Thumb2");
Chris Lattnere73d4f82010-10-28 21:41:58 +00007187 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007188
Eric Christopherc223e2b2010-10-29 09:26:59 +00007189 llvm_unreachable("Implement any new match types added!");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007190}
7191
Jim Grosbach1355cf12011-07-26 17:10:22 +00007192/// parseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007193bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7194 StringRef IDVal = DirectiveID.getIdentifier();
7195 if (IDVal == ".word")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007196 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007197 else if (IDVal == ".thumb")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007198 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach9a70df92011-12-07 18:04:19 +00007199 else if (IDVal == ".arm")
7200 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007201 else if (IDVal == ".thumb_func")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007202 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007203 else if (IDVal == ".code")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007204 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007205 else if (IDVal == ".syntax")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007206 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbacha39cda72011-12-14 02:16:11 +00007207 else if (IDVal == ".unreq")
7208 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kimd7c9e082011-12-20 17:38:12 +00007209 else if (IDVal == ".arch")
7210 return parseDirectiveArch(DirectiveID.getLoc());
7211 else if (IDVal == ".eabi_attribute")
7212 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007213 return true;
7214}
7215
Jim Grosbach1355cf12011-07-26 17:10:22 +00007216/// parseDirectiveWord
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007217/// ::= .word [ expression (, expression)* ]
Jim Grosbach1355cf12011-07-26 17:10:22 +00007218bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007219 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7220 for (;;) {
7221 const MCExpr *Value;
7222 if (getParser().ParseExpression(Value))
7223 return true;
7224
Chris Lattneraaec2052010-01-19 19:46:13 +00007225 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007226
7227 if (getLexer().is(AsmToken::EndOfStatement))
7228 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00007229
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007230 // FIXME: Improve diagnostic.
7231 if (getLexer().isNot(AsmToken::Comma))
7232 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007233 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007234 }
7235 }
7236
Sean Callananb9a25b72010-01-19 20:27:46 +00007237 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007238 return false;
7239}
7240
Jim Grosbach1355cf12011-07-26 17:10:22 +00007241/// parseDirectiveThumb
Kevin Enderby515d5092009-10-15 20:48:48 +00007242/// ::= .thumb
Jim Grosbach1355cf12011-07-26 17:10:22 +00007243bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby515d5092009-10-15 20:48:48 +00007244 if (getLexer().isNot(AsmToken::EndOfStatement))
7245 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007246 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007247
Jim Grosbach9a70df92011-12-07 18:04:19 +00007248 if (!isThumb())
7249 SwitchMode();
7250 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7251 return false;
7252}
7253
7254/// parseDirectiveARM
7255/// ::= .arm
7256bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7257 if (getLexer().isNot(AsmToken::EndOfStatement))
7258 return Error(L, "unexpected token in directive");
7259 Parser.Lex();
7260
7261 if (isThumb())
7262 SwitchMode();
7263 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby515d5092009-10-15 20:48:48 +00007264 return false;
7265}
7266
Jim Grosbach1355cf12011-07-26 17:10:22 +00007267/// parseDirectiveThumbFunc
Kevin Enderby515d5092009-10-15 20:48:48 +00007268/// ::= .thumbfunc symbol_name
Jim Grosbach1355cf12011-07-26 17:10:22 +00007269bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00007270 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7271 bool isMachO = MAI.hasSubsectionsViaSymbols();
7272 StringRef Name;
Jim Grosbachde4d8392011-12-21 22:30:16 +00007273 bool needFuncName = true;
Rafael Espindola64695402011-05-16 16:17:21 +00007274
Jim Grosbachde4d8392011-12-21 22:30:16 +00007275 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindola64695402011-05-16 16:17:21 +00007276 // ELF doesn't
7277 if (isMachO) {
7278 const AsmToken &Tok = Parser.getTok();
Jim Grosbachde4d8392011-12-21 22:30:16 +00007279 if (Tok.isNot(AsmToken::EndOfStatement)) {
7280 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7281 return Error(L, "unexpected token in .thumb_func directive");
7282 Name = Tok.getIdentifier();
7283 Parser.Lex(); // Consume the identifier token.
7284 needFuncName = false;
7285 }
Rafael Espindola64695402011-05-16 16:17:21 +00007286 }
7287
Jim Grosbachde4d8392011-12-21 22:30:16 +00007288 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby515d5092009-10-15 20:48:48 +00007289 return Error(L, "unexpected token in directive");
Jim Grosbachde4d8392011-12-21 22:30:16 +00007290
7291 // Eat the end of statement and any blank lines that follow.
7292 while (getLexer().is(AsmToken::EndOfStatement))
7293 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007294
Rafael Espindola64695402011-05-16 16:17:21 +00007295 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbachde4d8392011-12-21 22:30:16 +00007296 // We really should be checking the next symbol definition even if there's
7297 // stuff in between.
7298 if (needFuncName) {
Jim Grosbachd475f862011-11-10 20:48:53 +00007299 Name = Parser.getTok().getIdentifier();
Rafael Espindola64695402011-05-16 16:17:21 +00007300 }
7301
Jim Grosbach642fc9c2010-11-05 22:33:53 +00007302 // Mark symbol as a thumb symbol.
7303 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7304 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00007305 return false;
7306}
7307
Jim Grosbach1355cf12011-07-26 17:10:22 +00007308/// parseDirectiveSyntax
Kevin Enderby515d5092009-10-15 20:48:48 +00007309/// ::= .syntax unified | divided
Jim Grosbach1355cf12011-07-26 17:10:22 +00007310bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007311 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007312 if (Tok.isNot(AsmToken::Identifier))
7313 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00007314 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00007315 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00007316 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007317 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00007318 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00007319 else
7320 return Error(L, "unrecognized syntax mode in .syntax directive");
7321
7322 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007323 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007324 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007325
7326 // TODO tell the MC streamer the mode
7327 // getParser().getStreamer().Emit???();
7328 return false;
7329}
7330
Jim Grosbach1355cf12011-07-26 17:10:22 +00007331/// parseDirectiveCode
Kevin Enderby515d5092009-10-15 20:48:48 +00007332/// ::= .code 16 | 32
Jim Grosbach1355cf12011-07-26 17:10:22 +00007333bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007334 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007335 if (Tok.isNot(AsmToken::Integer))
7336 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00007337 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00007338 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00007339 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007340 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00007341 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007342 else
7343 return Error(L, "invalid operand to .code directive");
7344
7345 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007346 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007347 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007348
Evan Cheng32869202011-07-08 22:36:29 +00007349 if (Val == 16) {
Jim Grosbach98447da2011-09-06 18:46:23 +00007350 if (!isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007351 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007352 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng32869202011-07-08 22:36:29 +00007353 } else {
Jim Grosbach98447da2011-09-06 18:46:23 +00007354 if (isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007355 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007356 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Chengeb0caa12011-07-08 22:49:55 +00007357 }
Jim Grosbach2a301702010-11-05 22:40:53 +00007358
Kevin Enderby515d5092009-10-15 20:48:48 +00007359 return false;
7360}
7361
Jim Grosbacha39cda72011-12-14 02:16:11 +00007362/// parseDirectiveReq
7363/// ::= name .req registername
7364bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7365 Parser.Lex(); // Eat the '.req' token.
7366 unsigned Reg;
7367 SMLoc SRegLoc, ERegLoc;
7368 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7369 Parser.EatToEndOfStatement();
7370 return Error(SRegLoc, "register name expected");
7371 }
7372
7373 // Shouldn't be anything else.
7374 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7375 Parser.EatToEndOfStatement();
7376 return Error(Parser.getTok().getLoc(),
7377 "unexpected input in .req directive.");
7378 }
7379
7380 Parser.Lex(); // Consume the EndOfStatement
7381
7382 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7383 return Error(SRegLoc, "redefinition of '" + Name +
7384 "' does not match original.");
7385
7386 return false;
7387}
7388
7389/// parseDirectiveUneq
7390/// ::= .unreq registername
7391bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7392 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7393 Parser.EatToEndOfStatement();
7394 return Error(L, "unexpected input in .unreq directive.");
7395 }
7396 RegisterReqs.erase(Parser.getTok().getIdentifier());
7397 Parser.Lex(); // Eat the identifier.
7398 return false;
7399}
7400
Jason W Kimd7c9e082011-12-20 17:38:12 +00007401/// parseDirectiveArch
7402/// ::= .arch token
7403bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7404 return true;
7405}
7406
7407/// parseDirectiveEabiAttr
7408/// ::= .eabi_attribute int, int
7409bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7410 return true;
7411}
7412
Sean Callanan90b70972010-04-07 20:29:34 +00007413extern "C" void LLVMInitializeARMAsmLexer();
7414
Kevin Enderby9c41fa82009-10-30 22:55:57 +00007415/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007416extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng94b95502011-07-26 00:24:13 +00007417 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7418 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00007419 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007420}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007421
Chris Lattner0692ee62010-09-06 19:11:01 +00007422#define GET_REGISTER_MATCHER
7423#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007424#include "ARMGenAsmMatcher.inc"