blob: 89f7ec227ebf08ff8388ffc99dee73e152a0be03 [file] [log] [blame]
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Evan Cheng94b95502011-07-26 00:24:13 +000010#include "MCTargetDesc/ARMBaseInfo.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMMCExpr.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000013#include "llvm/MC/MCParser/MCAsmLexer.h"
14#include "llvm/MC/MCParser/MCAsmParser.h"
15#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
Rafael Espindola64695402011-05-16 16:17:21 +000016#include "llvm/MC/MCAsmInfo.h"
Jim Grosbach642fc9c2010-11-05 22:33:53 +000017#include "llvm/MC/MCContext.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000018#include "llvm/MC/MCStreamer.h"
19#include "llvm/MC/MCExpr.h"
20#include "llvm/MC/MCInst.h"
Evan Cheng78011362011-08-23 20:15:21 +000021#include "llvm/MC/MCInstrDesc.h"
Evan Cheng94b95502011-07-26 00:24:13 +000022#include "llvm/MC/MCRegisterInfo.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000023#include "llvm/MC/MCSubtargetInfo.h"
Evan Cheng94b95502011-07-26 00:24:13 +000024#include "llvm/MC/MCTargetAsmParser.h"
Jim Grosbach89df9962011-08-26 21:43:41 +000025#include "llvm/Support/MathExtras.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000026#include "llvm/Support/SourceMgr.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000027#include "llvm/Support/TargetRegistry.h"
Daniel Dunbarfa315de2010-08-11 06:37:12 +000028#include "llvm/Support/raw_ostream.h"
Jim Grosbach11e03e72011-08-22 18:50:36 +000029#include "llvm/ADT/BitVector.h"
Benjamin Kramer75ca4b92011-07-08 21:06:23 +000030#include "llvm/ADT/OwningPtr.h"
Evan Cheng94b95502011-07-26 00:24:13 +000031#include "llvm/ADT/STLExtras.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000032#include "llvm/ADT/SmallVector.h"
Daniel Dunbar345a9a62010-08-11 06:37:20 +000033#include "llvm/ADT/StringSwitch.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000034#include "llvm/ADT/Twine.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000035
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000036using namespace llvm;
37
Chris Lattner3a697562010-10-28 17:20:03 +000038namespace {
Bill Wendling146018f2010-11-06 21:42:12 +000039
40class ARMOperand;
Jim Grosbach16c74252010-10-29 14:46:02 +000041
Jim Grosbach7636bf62011-12-02 00:35:16 +000042enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbach98b05a52011-11-30 01:09:44 +000043
Evan Cheng94b95502011-07-26 00:24:13 +000044class ARMAsmParser : public MCTargetAsmParser {
Evan Chengffc0e732011-07-09 05:47:46 +000045 MCSubtargetInfo &STI;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000046 MCAsmParser &Parser;
Jim Grosbach28f08c92012-03-05 19:33:30 +000047 const MCRegisterInfo *MRI;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000048
Jim Grosbacha39cda72011-12-14 02:16:11 +000049 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
51
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +000052 struct {
53 ARMCC::CondCodes Cond; // Condition for IT block.
54 unsigned Mask:4; // Condition mask for instructions.
55 // Starting at first 1 (from lsb).
56 // '1' condition as indicated in IT.
57 // '0' inverse of condition (else).
58 // Count of instructions in IT block is
59 // 4 - trailingzeroes(mask)
60
61 bool FirstCond; // Explicit flag for when we're parsing the
62 // First instruction in the IT block. It's
63 // implied in the mask, so needs special
64 // handling.
65
66 unsigned CurPosition; // Current position in parsing of IT
67 // block. In range [0,3]. Initialized
68 // according to count of instructions in block.
69 // ~0U if no active IT block.
70 } ITState;
71 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha1109882011-09-02 23:22:08 +000072 void forwardITPosition() {
73 if (!inITBlock()) return;
74 // Move to the next instruction in the IT block, if there is one. If not,
75 // mark the block as done.
76 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
77 if (++ITState.CurPosition == 5 - TZ)
78 ITState.CurPosition = ~0U; // Done with the IT block after this.
79 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +000080
81
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000082 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000083 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
84
Benjamin Kramer362a05a2012-04-15 17:04:27 +000085 bool Warning(SMLoc L, const Twine &Msg,
86 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
87 return Parser.Warning(L, Msg, Ranges);
88 }
89 bool Error(SMLoc L, const Twine &Msg,
90 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
91 return Parser.Error(L, Msg, Ranges);
92 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000093
Jim Grosbach1355cf12011-07-26 17:10:22 +000094 int tryParseRegister();
95 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d87ec22011-07-26 20:41:24 +000096 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +000097 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7ce05792011-08-03 23:50:40 +000098 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +000099 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
100 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000101 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
102 unsigned &ShiftAmount);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000103 bool parseDirectiveWord(unsigned Size, SMLoc L);
104 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach9a70df92011-12-07 18:04:19 +0000105 bool parseDirectiveARM(SMLoc L);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000106 bool parseDirectiveThumbFunc(SMLoc L);
107 bool parseDirectiveCode(SMLoc L);
108 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbacha39cda72011-12-14 02:16:11 +0000109 bool parseDirectiveReq(StringRef Name, SMLoc L);
110 bool parseDirectiveUnreq(SMLoc L);
Jason W Kimd7c9e082011-12-20 17:38:12 +0000111 bool parseDirectiveArch(SMLoc L);
112 bool parseDirectiveEabiAttr(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +0000113
Jim Grosbach1355cf12011-07-26 17:10:22 +0000114 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach89df9962011-08-26 21:43:41 +0000115 bool &CarrySetting, unsigned &ProcessorIMod,
116 StringRef &ITMask);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000117 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +0000118 bool &CanAcceptPredicationCode);
Jim Grosbach16c74252010-10-29 14:46:02 +0000119
Evan Chengebdeeab2011-07-08 01:53:10 +0000120 bool isThumb() const {
121 // FIXME: Can tablegen auto-generate this?
Evan Chengffc0e732011-07-09 05:47:46 +0000122 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Chengebdeeab2011-07-08 01:53:10 +0000123 }
Evan Chengebdeeab2011-07-08 01:53:10 +0000124 bool isThumbOne() const {
Evan Chengffc0e732011-07-09 05:47:46 +0000125 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Chengebdeeab2011-07-08 01:53:10 +0000126 }
Jim Grosbach47a0d522011-08-16 20:45:50 +0000127 bool isThumbTwo() const {
128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
129 }
Jim Grosbach194bd892011-08-16 22:20:01 +0000130 bool hasV6Ops() const {
131 return STI.getFeatureBits() & ARM::HasV6Ops;
132 }
James Molloyacad68d2011-09-28 14:21:38 +0000133 bool hasV7Ops() const {
134 return STI.getFeatureBits() & ARM::HasV7Ops;
135 }
Evan Cheng32869202011-07-08 22:36:29 +0000136 void SwitchMode() {
Evan Chengffc0e732011-07-09 05:47:46 +0000137 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
138 setAvailableFeatures(FB);
Evan Cheng32869202011-07-08 22:36:29 +0000139 }
James Molloyacad68d2011-09-28 14:21:38 +0000140 bool isMClass() const {
141 return STI.getFeatureBits() & ARM::FeatureMClass;
142 }
Evan Chengebdeeab2011-07-08 01:53:10 +0000143
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000144 /// @name Auto-generated Match Functions
145 /// {
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000146
Chris Lattner0692ee62010-09-06 19:11:01 +0000147#define GET_ASSEMBLER_HEADER
148#include "ARMGenAsmMatcher.inc"
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000149
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000150 /// }
151
Jim Grosbach89df9962011-08-26 21:43:41 +0000152 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000153 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbachf922c472011-02-12 01:34:40 +0000154 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000155 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbachf922c472011-02-12 01:34:40 +0000156 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000157 OperandMatchResultTy parseCoprocOptionOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000159 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000160 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000161 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000162 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000163 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000164 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachf6c05252011-07-21 17:23:04 +0000165 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
166 StringRef Op, int Low, int High);
167 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
168 return parsePKHImm(O, "lsl", 0, 31);
169 }
170 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
171 return parsePKHImm(O, "asr", 1, 32);
172 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000173 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach580f4a92011-07-25 22:20:28 +0000174 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000175 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000176 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000177 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach251bf252011-08-10 21:56:18 +0000178 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach9d390362011-10-03 23:38:36 +0000179 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach862019c2011-10-18 23:02:30 +0000180 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7636bf62011-12-02 00:35:16 +0000181 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000182
183 // Asm Match Converter Methods
Jim Grosbacha77295d2011-09-08 22:07:06 +0000184 bool cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
185 const SmallVectorImpl<MCParsedAsmOperand*> &);
186 bool cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
187 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheeec0252011-09-08 00:39:19 +0000188 bool cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
189 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachee2c2a42011-09-16 21:55:56 +0000190 bool cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
191 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000192 bool cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000193 const SmallVectorImpl<MCParsedAsmOperand*> &);
Owen Anderson9ab0f252011-08-26 20:43:14 +0000194 bool cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
195 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach548340c2011-08-11 19:22:40 +0000196 bool cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
197 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000198 bool cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000199 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7b8f46c2011-08-11 21:17:22 +0000200 bool cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
201 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000202 bool cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
203 const SmallVectorImpl<MCParsedAsmOperand*> &);
204 bool cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
205 const SmallVectorImpl<MCParsedAsmOperand*> &);
206 bool cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
207 const SmallVectorImpl<MCParsedAsmOperand*> &);
208 bool cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
209 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000210 bool cvtLdrdPre(MCInst &Inst, unsigned Opcode,
211 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach14605d12011-08-11 20:28:23 +0000212 bool cvtStrdPre(MCInst &Inst, unsigned Opcode,
213 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach623a4542011-08-10 22:42:16 +0000214 bool cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
215 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach88ae2bc2011-08-19 22:07:46 +0000216 bool cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
217 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach12431322011-10-24 22:16:58 +0000218 bool cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
219 const SmallVectorImpl<MCParsedAsmOperand*> &);
220 bool cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
221 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach4334e032011-10-31 21:50:31 +0000222 bool cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
223 const SmallVectorImpl<MCParsedAsmOperand*> &);
224 bool cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
225 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach189610f2011-07-26 18:25:39 +0000226
227 bool validateInstruction(MCInst &Inst,
228 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach83ec8772011-11-10 23:42:14 +0000229 bool processInstruction(MCInst &Inst,
Jim Grosbachf8fce712011-08-11 17:35:48 +0000230 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachd54b4e62011-08-16 21:12:37 +0000231 bool shouldOmitCCOutOperand(StringRef Mnemonic,
232 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach189610f2011-07-26 18:25:39 +0000233
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000234public:
Jim Grosbach47a0d522011-08-16 20:45:50 +0000235 enum ARMMatchResultTy {
Jim Grosbach194bd892011-08-16 22:20:01 +0000236 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000237 Match_RequiresNotITBlock,
Jim Grosbach194bd892011-08-16 22:20:01 +0000238 Match_RequiresV6,
Jim Grosbach70c9bf32012-06-22 23:56:48 +0000239 Match_RequiresThumb2,
240#define GET_OPERAND_DIAGNOSTIC_TYPES
241#include "ARMGenAsmMatcher.inc"
242
Jim Grosbach47a0d522011-08-16 20:45:50 +0000243 };
244
Evan Chengffc0e732011-07-09 05:47:46 +0000245 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Evan Cheng94b95502011-07-26 00:24:13 +0000246 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
Evan Chengebdeeab2011-07-08 01:53:10 +0000247 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng32869202011-07-08 22:36:29 +0000248
Jim Grosbach28f08c92012-03-05 19:33:30 +0000249 // Cache the MCRegisterInfo.
250 MRI = &getContext().getRegisterInfo();
251
Evan Chengebdeeab2011-07-08 01:53:10 +0000252 // Initialize the set of available features.
Evan Chengffc0e732011-07-09 05:47:46 +0000253 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000254
255 // Not in an ITBlock to start with.
256 ITState.CurPosition = ~0U;
Evan Chengebdeeab2011-07-08 01:53:10 +0000257 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000258
Jim Grosbach1355cf12011-07-26 17:10:22 +0000259 // Implementation of the MCTargetAsmParser interface:
260 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
261 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Jim Grosbach189610f2011-07-26 18:25:39 +0000262 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000263 bool ParseDirective(AsmToken DirectiveID);
264
Jim Grosbach47a0d522011-08-16 20:45:50 +0000265 unsigned checkTargetMatchPredicate(MCInst &Inst);
266
Jim Grosbach1355cf12011-07-26 17:10:22 +0000267 bool MatchAndEmitInstruction(SMLoc IDLoc,
268 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
269 MCStreamer &Out);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000270};
Jim Grosbach16c74252010-10-29 14:46:02 +0000271} // end anonymous namespace
272
Chris Lattner3a697562010-10-28 17:20:03 +0000273namespace {
274
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000275/// ARMOperand - Instances of this class represent a parsed ARM machine
276/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000277class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000278 enum KindTy {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000279 k_CondCode,
280 k_CCOut,
281 k_ITCondMask,
282 k_CoprocNum,
283 k_CoprocReg,
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000284 k_CoprocOption,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000285 k_Immediate,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000286 k_MemBarrierOpt,
287 k_Memory,
288 k_PostIndexRegister,
289 k_MSRMask,
290 k_ProcIFlags,
Jim Grosbach460a9052011-10-07 23:56:00 +0000291 k_VectorIndex,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000292 k_Register,
293 k_RegisterList,
294 k_DPRRegisterList,
295 k_SPRRegisterList,
Jim Grosbach862019c2011-10-18 23:02:30 +0000296 k_VectorList,
Jim Grosbach98b05a52011-11-30 01:09:44 +0000297 k_VectorListAllLanes,
Jim Grosbach7636bf62011-12-02 00:35:16 +0000298 k_VectorListIndexed,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000299 k_ShiftedRegister,
300 k_ShiftedImmediate,
301 k_ShifterImmediate,
302 k_RotateImmediate,
303 k_BitfieldDescriptor,
304 k_Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000305 } Kind;
306
Sean Callanan76264762010-04-02 22:27:05 +0000307 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000308 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000309
310 union {
311 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000312 ARMCC::CondCodes Val;
313 } CC;
314
315 struct {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000316 unsigned Val;
317 } Cop;
318
319 struct {
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000320 unsigned Val;
321 } CoprocOption;
322
323 struct {
Jim Grosbach89df9962011-08-26 21:43:41 +0000324 unsigned Mask:4;
325 } ITMask;
326
327 struct {
328 ARM_MB::MemBOpt Val;
329 } MBOpt;
330
331 struct {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000332 ARM_PROC::IFlags Val;
333 } IFlags;
334
335 struct {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000336 unsigned Val;
337 } MMask;
338
339 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000340 const char *Data;
341 unsigned Length;
342 } Tok;
343
344 struct {
345 unsigned RegNum;
346 } Reg;
347
Jim Grosbach862019c2011-10-18 23:02:30 +0000348 // A vector register list is a sequential list of 1 to 4 registers.
349 struct {
350 unsigned RegNum;
351 unsigned Count;
Jim Grosbach7636bf62011-12-02 00:35:16 +0000352 unsigned LaneIndex;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +0000353 bool isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +0000354 } VectorList;
355
Bill Wendling8155e5b2010-11-06 22:19:43 +0000356 struct {
Jim Grosbach460a9052011-10-07 23:56:00 +0000357 unsigned Val;
358 } VectorIndex;
359
360 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000361 const MCExpr *Val;
362 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000363
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000364 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000365 struct {
366 unsigned BaseRegNum;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000367 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
368 // was specified.
369 const MCConstantExpr *OffsetImm; // Offset immediate value
370 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
371 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbach57dcb852011-10-11 17:29:55 +0000372 unsigned ShiftImm; // shift for OffsetReg.
373 unsigned Alignment; // 0 = no alignment specified
Jim Grosbacheeaf1c12011-12-19 18:31:43 +0000374 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbach7ce05792011-08-03 23:50:40 +0000375 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbache53c87b2011-10-11 15:59:20 +0000376 } Memory;
Owen Anderson00828302011-03-18 22:50:18 +0000377
378 struct {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000379 unsigned RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000380 bool isAdd;
381 ARM_AM::ShiftOpc ShiftTy;
382 unsigned ShiftImm;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000383 } PostIdxReg;
384
385 struct {
Jim Grosbach580f4a92011-07-25 22:20:28 +0000386 bool isASR;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000387 unsigned Imm;
Jim Grosbach580f4a92011-07-25 22:20:28 +0000388 } ShifterImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000389 struct {
390 ARM_AM::ShiftOpc ShiftTy;
391 unsigned SrcReg;
392 unsigned ShiftReg;
393 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000394 } RegShiftedReg;
Owen Anderson92a20222011-07-21 18:54:16 +0000395 struct {
396 ARM_AM::ShiftOpc ShiftTy;
397 unsigned SrcReg;
398 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000399 } RegShiftedImm;
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000400 struct {
401 unsigned Imm;
402 } RotImm;
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000403 struct {
404 unsigned LSB;
405 unsigned Width;
406 } Bitfield;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000407 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000408
Bill Wendling146018f2010-11-06 21:42:12 +0000409 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
410public:
Sean Callanan76264762010-04-02 22:27:05 +0000411 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
412 Kind = o.Kind;
413 StartLoc = o.StartLoc;
414 EndLoc = o.EndLoc;
415 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000416 case k_CondCode:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000417 CC = o.CC;
418 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000419 case k_ITCondMask:
Jim Grosbach89df9962011-08-26 21:43:41 +0000420 ITMask = o.ITMask;
421 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000422 case k_Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000423 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000424 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000425 case k_CCOut:
426 case k_Register:
Sean Callanan76264762010-04-02 22:27:05 +0000427 Reg = o.Reg;
428 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000429 case k_RegisterList:
430 case k_DPRRegisterList:
431 case k_SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000432 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000433 break;
Jim Grosbach862019c2011-10-18 23:02:30 +0000434 case k_VectorList:
Jim Grosbach98b05a52011-11-30 01:09:44 +0000435 case k_VectorListAllLanes:
Jim Grosbach7636bf62011-12-02 00:35:16 +0000436 case k_VectorListIndexed:
Jim Grosbach862019c2011-10-18 23:02:30 +0000437 VectorList = o.VectorList;
438 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000439 case k_CoprocNum:
440 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000441 Cop = o.Cop;
442 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000443 case k_CoprocOption:
444 CoprocOption = o.CoprocOption;
445 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000446 case k_Immediate:
Sean Callanan76264762010-04-02 22:27:05 +0000447 Imm = o.Imm;
448 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000449 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000450 MBOpt = o.MBOpt;
451 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000452 case k_Memory:
Jim Grosbache53c87b2011-10-11 15:59:20 +0000453 Memory = o.Memory;
Sean Callanan76264762010-04-02 22:27:05 +0000454 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000455 case k_PostIndexRegister:
Jim Grosbach7ce05792011-08-03 23:50:40 +0000456 PostIdxReg = o.PostIdxReg;
457 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000458 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000459 MMask = o.MMask;
460 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000461 case k_ProcIFlags:
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000462 IFlags = o.IFlags;
Owen Anderson00828302011-03-18 22:50:18 +0000463 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000464 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +0000465 ShifterImm = o.ShifterImm;
Owen Anderson00828302011-03-18 22:50:18 +0000466 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000467 case k_ShiftedRegister:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000468 RegShiftedReg = o.RegShiftedReg;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000469 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000470 case k_ShiftedImmediate:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000471 RegShiftedImm = o.RegShiftedImm;
Owen Anderson92a20222011-07-21 18:54:16 +0000472 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000473 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000474 RotImm = o.RotImm;
475 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000476 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000477 Bitfield = o.Bitfield;
478 break;
Jim Grosbach460a9052011-10-07 23:56:00 +0000479 case k_VectorIndex:
480 VectorIndex = o.VectorIndex;
481 break;
Sean Callanan76264762010-04-02 22:27:05 +0000482 }
483 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000484
Sean Callanan76264762010-04-02 22:27:05 +0000485 /// getStartLoc - Get the location of the first token of this operand.
486 SMLoc getStartLoc() const { return StartLoc; }
487 /// getEndLoc - Get the location of the last token of this operand.
488 SMLoc getEndLoc() const { return EndLoc; }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000489
Benjamin Kramer362a05a2012-04-15 17:04:27 +0000490 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
491
Daniel Dunbar8462b302010-08-11 06:36:53 +0000492 ARMCC::CondCodes getCondCode() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000493 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000494 return CC.Val;
495 }
496
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000497 unsigned getCoproc() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000498 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000499 return Cop.Val;
500 }
501
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000502 StringRef getToken() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000503 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000504 return StringRef(Tok.Data, Tok.Length);
505 }
506
507 unsigned getReg() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000508 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000509 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000510 }
511
Bill Wendling5fa22a12010-11-09 23:28:44 +0000512 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000513 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
514 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000515 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000516 }
517
Kevin Enderbycfe07242009-10-13 22:19:02 +0000518 const MCExpr *getImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000519 assert(isImm() && "Invalid access!");
Kevin Enderbycfe07242009-10-13 22:19:02 +0000520 return Imm.Val;
521 }
522
Jim Grosbach460a9052011-10-07 23:56:00 +0000523 unsigned getVectorIndex() const {
524 assert(Kind == k_VectorIndex && "Invalid access!");
525 return VectorIndex.Val;
526 }
527
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000528 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000529 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000530 return MBOpt.Val;
531 }
532
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000533 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000534 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000535 return IFlags.Val;
536 }
537
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000538 unsigned getMSRMask() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000539 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000540 return MMask.Val;
541 }
542
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000543 bool isCoprocNum() const { return Kind == k_CoprocNum; }
544 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000545 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000546 bool isCondCode() const { return Kind == k_CondCode; }
547 bool isCCOut() const { return Kind == k_CCOut; }
548 bool isITMask() const { return Kind == k_ITCondMask; }
549 bool isITCondCode() const { return Kind == k_CondCode; }
550 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbach51222d12012-01-20 18:09:51 +0000551 bool isFPImm() const {
552 if (!isImm()) return false;
553 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
554 if (!CE) return false;
555 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
556 return Val != -1;
557 }
Jim Grosbach4050bc42011-12-22 22:19:05 +0000558 bool isFBits16() const {
559 if (!isImm()) return false;
560 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
561 if (!CE) return false;
562 int64_t Value = CE->getValue();
563 return Value >= 0 && Value <= 16;
564 }
565 bool isFBits32() const {
566 if (!isImm()) return false;
567 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
568 if (!CE) return false;
569 int64_t Value = CE->getValue();
570 return Value >= 1 && Value <= 32;
571 }
Jim Grosbacha77295d2011-09-08 22:07:06 +0000572 bool isImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000573 if (!isImm()) return false;
Jim Grosbacha77295d2011-09-08 22:07:06 +0000574 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
575 if (!CE) return false;
576 int64_t Value = CE->getValue();
577 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
578 }
Jim Grosbach72f39f82011-08-24 21:22:15 +0000579 bool isImm0_1020s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000580 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000581 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
582 if (!CE) return false;
583 int64_t Value = CE->getValue();
584 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
585 }
586 bool isImm0_508s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000587 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000588 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
589 if (!CE) return false;
590 int64_t Value = CE->getValue();
591 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
592 }
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000593 bool isImm0_508s4Neg() const {
594 if (!isImm()) return false;
595 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
596 if (!CE) return false;
597 int64_t Value = -CE->getValue();
598 // explicitly exclude zero. we want that to use the normal 0_508 version.
599 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
600 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000601 bool isImm0_255() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000602 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
604 if (!CE) return false;
605 int64_t Value = CE->getValue();
606 return Value >= 0 && Value < 256;
607 }
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000608 bool isImm0_4095() const {
609 if (!isImm()) return false;
610 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
611 if (!CE) return false;
612 int64_t Value = CE->getValue();
613 return Value >= 0 && Value < 4096;
614 }
615 bool isImm0_4095Neg() const {
616 if (!isImm()) return false;
617 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
618 if (!CE) return false;
619 int64_t Value = -CE->getValue();
620 return Value > 0 && Value < 4096;
621 }
Jim Grosbach587f5062011-12-02 23:34:39 +0000622 bool isImm0_1() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000623 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000624 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
625 if (!CE) return false;
626 int64_t Value = CE->getValue();
627 return Value >= 0 && Value < 2;
628 }
629 bool isImm0_3() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000630 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000631 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
632 if (!CE) return false;
633 int64_t Value = CE->getValue();
634 return Value >= 0 && Value < 4;
635 }
Jim Grosbach83ab0702011-07-13 22:01:08 +0000636 bool isImm0_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000637 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000638 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
639 if (!CE) return false;
640 int64_t Value = CE->getValue();
641 return Value >= 0 && Value < 8;
642 }
643 bool isImm0_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000644 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000645 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
646 if (!CE) return false;
647 int64_t Value = CE->getValue();
648 return Value >= 0 && Value < 16;
649 }
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000650 bool isImm0_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000651 if (!isImm()) return false;
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000652 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
653 if (!CE) return false;
654 int64_t Value = CE->getValue();
655 return Value >= 0 && Value < 32;
656 }
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000657 bool isImm0_63() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000658 if (!isImm()) return false;
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000659 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
660 if (!CE) return false;
661 int64_t Value = CE->getValue();
662 return Value >= 0 && Value < 64;
663 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000664 bool isImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000665 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000666 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
667 if (!CE) return false;
668 int64_t Value = CE->getValue();
669 return Value == 8;
670 }
671 bool isImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000672 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000673 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
674 if (!CE) return false;
675 int64_t Value = CE->getValue();
676 return Value == 16;
677 }
678 bool isImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000679 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
681 if (!CE) return false;
682 int64_t Value = CE->getValue();
683 return Value == 32;
684 }
Jim Grosbach6b044c22011-12-08 22:06:06 +0000685 bool isShrImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000686 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000687 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
688 if (!CE) return false;
689 int64_t Value = CE->getValue();
690 return Value > 0 && Value <= 8;
691 }
692 bool isShrImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000693 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000694 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
695 if (!CE) return false;
696 int64_t Value = CE->getValue();
697 return Value > 0 && Value <= 16;
698 }
699 bool isShrImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000700 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000701 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
702 if (!CE) return false;
703 int64_t Value = CE->getValue();
704 return Value > 0 && Value <= 32;
705 }
706 bool isShrImm64() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000707 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
709 if (!CE) return false;
710 int64_t Value = CE->getValue();
711 return Value > 0 && Value <= 64;
712 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000713 bool isImm1_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000714 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000715 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
716 if (!CE) return false;
717 int64_t Value = CE->getValue();
718 return Value > 0 && Value < 8;
719 }
720 bool isImm1_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000721 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000722 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
723 if (!CE) return false;
724 int64_t Value = CE->getValue();
725 return Value > 0 && Value < 16;
726 }
727 bool isImm1_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000728 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000729 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
730 if (!CE) return false;
731 int64_t Value = CE->getValue();
732 return Value > 0 && Value < 32;
733 }
Jim Grosbachf4943352011-07-25 23:09:14 +0000734 bool isImm1_16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000735 if (!isImm()) return false;
Jim Grosbachf4943352011-07-25 23:09:14 +0000736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
737 if (!CE) return false;
738 int64_t Value = CE->getValue();
739 return Value > 0 && Value < 17;
740 }
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000741 bool isImm1_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000742 if (!isImm()) return false;
Jim Grosbach4a5ffb32011-07-22 23:16:18 +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 Grosbachee10ff82011-11-10 19:18:01 +0000748 bool isImm0_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000749 if (!isImm()) return false;
Jim Grosbachee10ff82011-11-10 19:18:01 +0000750 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
751 if (!CE) return false;
752 int64_t Value = CE->getValue();
753 return Value >= 0 && Value < 33;
754 }
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000755 bool isImm0_65535() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000756 if (!isImm()) return false;
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000757 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
758 if (!CE) return false;
759 int64_t Value = CE->getValue();
760 return Value >= 0 && Value < 65536;
761 }
Jim Grosbachffa32252011-07-19 19:13:28 +0000762 bool isImm0_65535Expr() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000763 if (!isImm()) return false;
Jim Grosbachffa32252011-07-19 19:13:28 +0000764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
765 // If it's not a constant expression, it'll generate a fixup and be
766 // handled later.
767 if (!CE) return true;
768 int64_t Value = CE->getValue();
769 return Value >= 0 && Value < 65536;
770 }
Jim Grosbached838482011-07-26 16:24:27 +0000771 bool isImm24bit() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000772 if (!isImm()) return false;
Jim Grosbached838482011-07-26 16:24:27 +0000773 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
774 if (!CE) return false;
775 int64_t Value = CE->getValue();
776 return Value >= 0 && Value <= 0xffffff;
777 }
Jim Grosbach70939ee2011-08-17 21:51:27 +0000778 bool isImmThumbSR() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000779 if (!isImm()) return false;
Jim Grosbach70939ee2011-08-17 21:51:27 +0000780 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
781 if (!CE) return false;
782 int64_t Value = CE->getValue();
783 return Value > 0 && Value < 33;
784 }
Jim Grosbachf6c05252011-07-21 17:23:04 +0000785 bool isPKHLSLImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000786 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
788 if (!CE) return false;
789 int64_t Value = CE->getValue();
790 return Value >= 0 && Value < 32;
791 }
792 bool isPKHASRImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000793 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000794 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
795 if (!CE) return false;
796 int64_t Value = CE->getValue();
797 return Value > 0 && Value <= 32;
798 }
Jiangning Liu1fb27ec2012-08-02 08:13:13 +0000799 bool isAdrLabel() const {
800 // If we have an immediate that's not a constant, treat it as a label
801 // reference needing a fixup. If it is a constant, but it can't fit
802 // into shift immediate encoding, we reject it.
803 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
804 else return (isARMSOImm() || isARMSOImmNeg());
805 }
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000806 bool isARMSOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000807 if (!isImm()) return false;
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000808 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
809 if (!CE) return false;
810 int64_t Value = CE->getValue();
811 return ARM_AM::getSOImmVal(Value) != -1;
812 }
Jim Grosbache70ec842011-10-28 22:50:54 +0000813 bool isARMSOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000814 if (!isImm()) return false;
Jim Grosbache70ec842011-10-28 22:50:54 +0000815 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
816 if (!CE) return false;
817 int64_t Value = CE->getValue();
818 return ARM_AM::getSOImmVal(~Value) != -1;
819 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000820 bool isARMSOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000821 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000822 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
823 if (!CE) return false;
824 int64_t Value = CE->getValue();
Jim Grosbachad353c62012-03-30 19:59:02 +0000825 // Only use this when not representable as a plain so_imm.
826 return ARM_AM::getSOImmVal(Value) == -1 &&
827 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000828 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000829 bool isT2SOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000830 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
832 if (!CE) return false;
833 int64_t Value = CE->getValue();
834 return ARM_AM::getT2SOImmVal(Value) != -1;
835 }
Jim Grosbach89a63372011-10-28 22:36:30 +0000836 bool isT2SOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000837 if (!isImm()) return false;
Jim Grosbach89a63372011-10-28 22:36:30 +0000838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
839 if (!CE) return false;
840 int64_t Value = CE->getValue();
841 return ARM_AM::getT2SOImmVal(~Value) != -1;
842 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000843 bool isT2SOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000844 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
846 if (!CE) return false;
847 int64_t Value = CE->getValue();
Jim Grosbachad353c62012-03-30 19:59:02 +0000848 // Only use this when not representable as a plain so_imm.
849 return ARM_AM::getT2SOImmVal(Value) == -1 &&
850 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000851 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000852 bool isSetEndImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000853 if (!isImm()) return false;
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000854 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
855 if (!CE) return false;
856 int64_t Value = CE->getValue();
857 return Value == 1 || Value == 0;
858 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000859 bool isReg() const { return Kind == k_Register; }
860 bool isRegList() const { return Kind == k_RegisterList; }
861 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
862 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
863 bool isToken() const { return Kind == k_Token; }
864 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
865 bool isMemory() const { return Kind == k_Memory; }
866 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
867 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
868 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
869 bool isRotImm() const { return Kind == k_RotateImmediate; }
870 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
871 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000872 bool isPostIdxReg() const {
Jim Grosbach430052b2011-11-14 17:52:47 +0000873 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000874 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000875 bool isMemNoOffset(bool alignOK = false) const {
Jim Grosbachf6c35c52011-10-10 23:06:42 +0000876 if (!isMemory())
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000877 return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000878 // No offset of any kind.
Jim Grosbach57dcb852011-10-11 17:29:55 +0000879 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
880 (alignOK || Memory.Alignment == 0);
881 }
Jim Grosbach0b4c6732012-01-18 22:46:46 +0000882 bool isMemPCRelImm12() const {
883 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
884 return false;
885 // Base register must be PC.
886 if (Memory.BaseRegNum != ARM::PC)
887 return false;
888 // Immediate offset in range [-4095, 4095].
889 if (!Memory.OffsetImm) return true;
890 int64_t Val = Memory.OffsetImm->getValue();
891 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
892 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000893 bool isAlignedMemory() const {
894 return isMemNoOffset(true);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000895 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000896 bool isAddrMode2() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000897 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000898 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000899 if (Memory.OffsetRegNum) return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000900 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000901 if (!Memory.OffsetImm) return true;
902 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach7ce05792011-08-03 23:50:40 +0000903 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000904 }
Jim Grosbach039c2e12011-08-04 23:01:30 +0000905 bool isAM2OffsetImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000906 if (!isImm()) return false;
Jim Grosbach039c2e12011-08-04 23:01:30 +0000907 // Immediate offset in range [-4095, 4095].
908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
909 if (!CE) return false;
910 int64_t Val = CE->getValue();
911 return Val > -4096 && Val < 4096;
912 }
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000913 bool isAddrMode3() const {
Jim Grosbach2f196742011-12-19 23:06:24 +0000914 // If we have an immediate that's not a constant, treat it as a label
915 // reference needing a fixup. If it is a constant, it's something else
916 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000917 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +0000918 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000919 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000920 // No shifts are legal for AM3.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000921 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000922 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000923 if (Memory.OffsetRegNum) return true;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000924 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000925 if (!Memory.OffsetImm) return true;
926 int64_t Val = Memory.OffsetImm->getValue();
Silviu Barangaca3cd412012-05-11 09:10:54 +0000927 // The #-0 offset is encoded as INT32_MIN, and we have to check
928 // for this too.
929 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000930 }
931 bool isAM3Offset() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000932 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000933 return false;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000934 if (Kind == k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000935 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
936 // Immediate offset in range [-255, 255].
937 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
938 if (!CE) return false;
939 int64_t Val = CE->getValue();
Jim Grosbach251bf252011-08-10 21:56:18 +0000940 // Special case, #-0 is INT32_MIN.
941 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000942 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000943 bool isAddrMode5() const {
Jim Grosbach681460f2011-11-01 01:24:45 +0000944 // If we have an immediate that's not a constant, treat it as a label
945 // reference needing a fixup. If it is a constant, it's something else
946 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000947 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach681460f2011-11-01 01:24:45 +0000948 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000949 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000950 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000951 if (Memory.OffsetRegNum) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000952 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000953 if (!Memory.OffsetImm) return true;
954 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +0000955 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbach681460f2011-11-01 01:24:45 +0000956 Val == INT32_MIN;
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000957 }
Jim Grosbach7f739be2011-09-19 22:21:13 +0000958 bool isMemTBB() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000959 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000960 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach7f739be2011-09-19 22:21:13 +0000961 return false;
962 return true;
963 }
964 bool isMemTBH() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000965 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000966 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
967 Memory.Alignment != 0 )
Jim Grosbach7f739be2011-09-19 22:21:13 +0000968 return false;
969 return true;
970 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000971 bool isMemRegOffset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000972 if (!isMemory() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendlingf4caf692010-12-14 03:36:38 +0000973 return false;
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000974 return true;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000975 }
Jim Grosbachab899c12011-09-07 23:10:15 +0000976 bool isT2MemRegOffset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000977 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
978 Memory.Alignment != 0)
Jim Grosbachab899c12011-09-07 23:10:15 +0000979 return false;
980 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000981 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbachab899c12011-09-07 23:10:15 +0000982 return true;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000983 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbachab899c12011-09-07 23:10:15 +0000984 return false;
985 return true;
986 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000987 bool isMemThumbRR() const {
988 // Thumb reg+reg addressing is simple. Just two registers, a base and
989 // an offset. No shifts, negations or any other complicating factors.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000990 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000991 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000992 return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000993 return isARMLowRegister(Memory.BaseRegNum) &&
994 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +0000995 }
996 bool isMemThumbRIs4() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000997 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000998 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach60f91a32011-08-19 17:55:24 +0000999 return false;
1000 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001001 if (!Memory.OffsetImm) return true;
1002 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +00001003 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1004 }
Jim Grosbach38466302011-08-19 18:55:51 +00001005 bool isMemThumbRIs2() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +00001006 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001007 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach38466302011-08-19 18:55:51 +00001008 return false;
1009 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001010 if (!Memory.OffsetImm) return true;
1011 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach38466302011-08-19 18:55:51 +00001012 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1013 }
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001014 bool isMemThumbRIs1() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +00001015 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001016 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001017 return false;
1018 // Immediate offset in range [0, 31].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001019 if (!Memory.OffsetImm) return true;
1020 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001021 return Val >= 0 && Val <= 31;
1022 }
Jim Grosbachecd85892011-08-19 18:13:48 +00001023 bool isMemThumbSPI() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001024 if (!isMemory() || Memory.OffsetRegNum != 0 ||
1025 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbachecd85892011-08-19 18:13:48 +00001026 return false;
1027 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001028 if (!Memory.OffsetImm) return true;
1029 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +00001030 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001031 }
Jim Grosbacha77295d2011-09-08 22:07:06 +00001032 bool isMemImm8s4Offset() const {
Jim Grosbach2f196742011-12-19 23:06:24 +00001033 // If we have an immediate that's not a constant, treat it as a label
1034 // reference needing a fixup. If it is a constant, it's something else
1035 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001036 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +00001037 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +00001038 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha77295d2011-09-08 22:07:06 +00001039 return false;
1040 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001041 if (!Memory.OffsetImm) return true;
1042 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha77295d2011-09-08 22:07:06 +00001043 return Val >= -1020 && Val <= 1020 && (Val & 3) == 0;
1044 }
Jim Grosbachb6aed502011-09-09 18:37:27 +00001045 bool isMemImm0_1020s4Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001046 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachb6aed502011-09-09 18:37:27 +00001047 return false;
1048 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001049 if (!Memory.OffsetImm) return true;
1050 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachb6aed502011-09-09 18:37:27 +00001051 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1052 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001053 bool isMemImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001054 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001055 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001056 // Base reg of PC isn't allowed for these encodings.
1057 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001058 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001059 if (!Memory.OffsetImm) return true;
1060 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson4d2a0012011-09-23 22:25:02 +00001061 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001062 }
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001063 bool isMemPosImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001064 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001065 return false;
1066 // Immediate offset in range [0, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001067 if (!Memory.OffsetImm) return true;
1068 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001069 return Val >= 0 && Val < 256;
1070 }
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001071 bool isMemNegImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001072 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001073 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001074 // Base reg of PC isn't allowed for these encodings.
1075 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001076 // Immediate offset in range [-255, -1].
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001077 if (!Memory.OffsetImm) return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +00001078 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001079 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001080 }
1081 bool isMemUImm12Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001082 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001083 return false;
1084 // Immediate offset in range [0, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001085 if (!Memory.OffsetImm) return true;
1086 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001087 return (Val >= 0 && Val < 4096);
1088 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001089 bool isMemImm12Offset() const {
Jim Grosbach09176e12011-08-08 20:59:31 +00001090 // If we have an immediate that's not a constant, treat it as a label
1091 // reference needing a fixup. If it is a constant, it's something else
1092 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001093 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach09176e12011-08-08 20:59:31 +00001094 return true;
1095
Jim Grosbach57dcb852011-10-11 17:29:55 +00001096 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001097 return false;
1098 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001099 if (!Memory.OffsetImm) return true;
1100 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +00001101 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001102 }
1103 bool isPostIdxImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001104 if (!isImm()) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001105 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1106 if (!CE) return false;
1107 int64_t Val = CE->getValue();
Owen Anderson63553c72011-08-29 17:17:09 +00001108 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001109 }
Jim Grosbach2bd01182011-10-11 21:55:36 +00001110 bool isPostIdxImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001111 if (!isImm()) return false;
Jim Grosbach2bd01182011-10-11 21:55:36 +00001112 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1113 if (!CE) return false;
1114 int64_t Val = CE->getValue();
1115 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1116 (Val == INT32_MIN);
1117 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001118
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001119 bool isMSRMask() const { return Kind == k_MSRMask; }
1120 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001121
Jim Grosbach0e387b22011-10-17 22:26:03 +00001122 // NEON operands.
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001123 bool isSingleSpacedVectorList() const {
1124 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1125 }
1126 bool isDoubleSpacedVectorList() const {
1127 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1128 }
Jim Grosbach862019c2011-10-18 23:02:30 +00001129 bool isVecListOneD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001130 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach862019c2011-10-18 23:02:30 +00001131 return VectorList.Count == 1;
1132 }
1133
Jim Grosbach28f08c92012-03-05 19:33:30 +00001134 bool isVecListDPair() const {
1135 if (!isSingleSpacedVectorList()) return false;
1136 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1137 .contains(VectorList.RegNum));
1138 }
1139
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001140 bool isVecListThreeD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001141 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001142 return VectorList.Count == 3;
1143 }
1144
Jim Grosbachb6310312011-10-21 20:35:01 +00001145 bool isVecListFourD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001146 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachb6310312011-10-21 20:35:01 +00001147 return VectorList.Count == 4;
1148 }
1149
Jim Grosbachc3384c92012-03-05 21:43:40 +00001150 bool isVecListDPairSpaced() const {
Kevin Enderby9f2e1602012-03-20 17:41:51 +00001151 if (isSingleSpacedVectorList()) return false;
Jim Grosbachc3384c92012-03-05 21:43:40 +00001152 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1153 .contains(VectorList.RegNum));
1154 }
1155
Jim Grosbachc387fc62012-01-23 23:20:46 +00001156 bool isVecListThreeQ() const {
1157 if (!isDoubleSpacedVectorList()) return false;
1158 return VectorList.Count == 3;
1159 }
1160
Jim Grosbach7945ead2012-01-24 00:43:12 +00001161 bool isVecListFourQ() const {
1162 if (!isDoubleSpacedVectorList()) return false;
1163 return VectorList.Count == 4;
1164 }
1165
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001166 bool isSingleSpacedVectorAllLanes() const {
1167 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1168 }
1169 bool isDoubleSpacedVectorAllLanes() const {
1170 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1171 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00001172 bool isVecListOneDAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001173 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach98b05a52011-11-30 01:09:44 +00001174 return VectorList.Count == 1;
1175 }
1176
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001177 bool isVecListDPairAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001178 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001179 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1180 .contains(VectorList.RegNum));
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001181 }
1182
Jim Grosbach4d0983a2012-03-06 23:10:38 +00001183 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001184 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach13af2222011-11-30 18:21:25 +00001185 return VectorList.Count == 2;
1186 }
1187
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001188 bool isVecListThreeDAllLanes() const {
1189 if (!isSingleSpacedVectorAllLanes()) return false;
1190 return VectorList.Count == 3;
1191 }
1192
1193 bool isVecListThreeQAllLanes() const {
1194 if (!isDoubleSpacedVectorAllLanes()) return false;
1195 return VectorList.Count == 3;
1196 }
1197
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001198 bool isVecListFourDAllLanes() const {
1199 if (!isSingleSpacedVectorAllLanes()) return false;
1200 return VectorList.Count == 4;
1201 }
1202
1203 bool isVecListFourQAllLanes() const {
1204 if (!isDoubleSpacedVectorAllLanes()) return false;
1205 return VectorList.Count == 4;
1206 }
1207
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001208 bool isSingleSpacedVectorIndexed() const {
1209 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1210 }
1211 bool isDoubleSpacedVectorIndexed() const {
1212 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1213 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00001214 bool isVecListOneDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001215 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach7636bf62011-12-02 00:35:16 +00001216 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1217 }
1218
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001219 bool isVecListOneDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001220 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001221 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1222 }
1223
1224 bool isVecListOneDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001225 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001226 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1227 }
1228
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001229 bool isVecListTwoDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001230 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001231 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1232 }
1233
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001234 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001235 if (!isSingleSpacedVectorIndexed()) return false;
1236 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1237 }
1238
1239 bool isVecListTwoQWordIndexed() const {
1240 if (!isDoubleSpacedVectorIndexed()) return false;
1241 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1242 }
1243
1244 bool isVecListTwoQHWordIndexed() const {
1245 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001246 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1247 }
1248
1249 bool isVecListTwoDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001250 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001251 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1252 }
1253
Jim Grosbach3a678af2012-01-23 21:53:26 +00001254 bool isVecListThreeDByteIndexed() const {
1255 if (!isSingleSpacedVectorIndexed()) return false;
1256 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1257 }
1258
1259 bool isVecListThreeDHWordIndexed() const {
1260 if (!isSingleSpacedVectorIndexed()) return false;
1261 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1262 }
1263
1264 bool isVecListThreeQWordIndexed() const {
1265 if (!isDoubleSpacedVectorIndexed()) return false;
1266 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1267 }
1268
1269 bool isVecListThreeQHWordIndexed() const {
1270 if (!isDoubleSpacedVectorIndexed()) return false;
1271 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1272 }
1273
1274 bool isVecListThreeDWordIndexed() const {
1275 if (!isSingleSpacedVectorIndexed()) return false;
1276 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1277 }
1278
Jim Grosbache983a132012-01-24 18:37:25 +00001279 bool isVecListFourDByteIndexed() const {
1280 if (!isSingleSpacedVectorIndexed()) return false;
1281 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1282 }
1283
1284 bool isVecListFourDHWordIndexed() const {
1285 if (!isSingleSpacedVectorIndexed()) return false;
1286 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1287 }
1288
1289 bool isVecListFourQWordIndexed() const {
1290 if (!isDoubleSpacedVectorIndexed()) return false;
1291 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1292 }
1293
1294 bool isVecListFourQHWordIndexed() const {
1295 if (!isDoubleSpacedVectorIndexed()) return false;
1296 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1297 }
1298
1299 bool isVecListFourDWordIndexed() const {
1300 if (!isSingleSpacedVectorIndexed()) return false;
1301 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1302 }
1303
Jim Grosbach460a9052011-10-07 23:56:00 +00001304 bool isVectorIndex8() const {
1305 if (Kind != k_VectorIndex) return false;
1306 return VectorIndex.Val < 8;
1307 }
1308 bool isVectorIndex16() const {
1309 if (Kind != k_VectorIndex) return false;
1310 return VectorIndex.Val < 4;
1311 }
1312 bool isVectorIndex32() const {
1313 if (Kind != k_VectorIndex) return false;
1314 return VectorIndex.Val < 2;
1315 }
1316
Jim Grosbach0e387b22011-10-17 22:26:03 +00001317 bool isNEONi8splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001318 if (!isImm()) return false;
Jim Grosbach0e387b22011-10-17 22:26:03 +00001319 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1320 // Must be a constant.
1321 if (!CE) return false;
1322 int64_t Value = CE->getValue();
1323 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1324 // value.
Jim Grosbach0e387b22011-10-17 22:26:03 +00001325 return Value >= 0 && Value < 256;
1326 }
Jim Grosbach460a9052011-10-07 23:56:00 +00001327
Jim Grosbachea461102011-10-17 23:09:09 +00001328 bool isNEONi16splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001329 if (!isImm()) return false;
Jim Grosbachea461102011-10-17 23:09:09 +00001330 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1331 // Must be a constant.
1332 if (!CE) return false;
1333 int64_t Value = CE->getValue();
1334 // i16 value in the range [0,255] or [0x0100, 0xff00]
1335 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1336 }
1337
Jim Grosbach6248a542011-10-18 00:22:00 +00001338 bool isNEONi32splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001339 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001340 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1341 // Must be a constant.
1342 if (!CE) return false;
1343 int64_t Value = CE->getValue();
1344 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1345 return (Value >= 0 && Value < 256) ||
1346 (Value >= 0x0100 && Value <= 0xff00) ||
1347 (Value >= 0x010000 && Value <= 0xff0000) ||
1348 (Value >= 0x01000000 && Value <= 0xff000000);
1349 }
1350
1351 bool isNEONi32vmov() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001352 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001353 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1354 // Must be a constant.
1355 if (!CE) return false;
1356 int64_t Value = CE->getValue();
1357 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1358 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1359 return (Value >= 0 && Value < 256) ||
1360 (Value >= 0x0100 && Value <= 0xff00) ||
1361 (Value >= 0x010000 && Value <= 0xff0000) ||
1362 (Value >= 0x01000000 && Value <= 0xff000000) ||
1363 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1364 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1365 }
Jim Grosbach9b087852011-12-19 23:51:07 +00001366 bool isNEONi32vmovNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001367 if (!isImm()) return false;
Jim Grosbach9b087852011-12-19 23:51:07 +00001368 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1369 // Must be a constant.
1370 if (!CE) return false;
1371 int64_t Value = ~CE->getValue();
1372 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1373 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1374 return (Value >= 0 && Value < 256) ||
1375 (Value >= 0x0100 && Value <= 0xff00) ||
1376 (Value >= 0x010000 && Value <= 0xff0000) ||
1377 (Value >= 0x01000000 && Value <= 0xff000000) ||
1378 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1379 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1380 }
Jim Grosbach6248a542011-10-18 00:22:00 +00001381
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001382 bool isNEONi64splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001383 if (!isImm()) return false;
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001384 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1385 // Must be a constant.
1386 if (!CE) return false;
1387 uint64_t Value = CE->getValue();
1388 // i64 value with each byte being either 0 or 0xff.
1389 for (unsigned i = 0; i < 8; ++i)
1390 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1391 return true;
1392 }
1393
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001394 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +00001395 // Add as immediates when possible. Null MCExpr = 0.
1396 if (Expr == 0)
1397 Inst.addOperand(MCOperand::CreateImm(0));
1398 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001399 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1400 else
1401 Inst.addOperand(MCOperand::CreateExpr(Expr));
1402 }
1403
Daniel Dunbar8462b302010-08-11 06:36:53 +00001404 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001405 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +00001406 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +00001407 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1408 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +00001409 }
1410
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001411 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1412 assert(N == 1 && "Invalid number of operands!");
1413 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1414 }
1415
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00001416 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1417 assert(N == 1 && "Invalid number of operands!");
1418 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1419 }
1420
1421 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1422 assert(N == 1 && "Invalid number of operands!");
1423 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1424 }
1425
Jim Grosbach89df9962011-08-26 21:43:41 +00001426 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1427 assert(N == 1 && "Invalid number of operands!");
1428 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1429 }
1430
1431 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1432 assert(N == 1 && "Invalid number of operands!");
1433 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1434 }
1435
Jim Grosbachd67641b2010-12-06 18:21:12 +00001436 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1437 assert(N == 1 && "Invalid number of operands!");
1438 Inst.addOperand(MCOperand::CreateReg(getReg()));
1439 }
1440
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001441 void addRegOperands(MCInst &Inst, unsigned N) const {
1442 assert(N == 1 && "Invalid number of operands!");
1443 Inst.addOperand(MCOperand::CreateReg(getReg()));
1444 }
1445
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001446 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbache8606dc2011-07-13 17:50:29 +00001447 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001448 assert(isRegShiftedReg() &&
1449 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001450 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1451 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001452 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001453 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001454 }
1455
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001456 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson152d4a42011-07-21 23:38:37 +00001457 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001458 assert(isRegShiftedImm() &&
1459 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001460 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonb56e4112012-04-25 18:00:18 +00001461 // Shift of #32 is encoded as 0 where permitted
1462 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Anderson92a20222011-07-21 18:54:16 +00001463 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonb56e4112012-04-25 18:00:18 +00001464 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Anderson92a20222011-07-21 18:54:16 +00001465 }
1466
Jim Grosbach580f4a92011-07-25 22:20:28 +00001467 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson00828302011-03-18 22:50:18 +00001468 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach580f4a92011-07-25 22:20:28 +00001469 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1470 ShifterImm.Imm));
Owen Anderson00828302011-03-18 22:50:18 +00001471 }
1472
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001473 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +00001474 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +00001475 const SmallVectorImpl<unsigned> &RegList = getRegList();
1476 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00001477 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1478 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001479 }
1480
Bill Wendling0f630752010-11-17 04:32:08 +00001481 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1482 addRegListOperands(Inst, N);
1483 }
1484
1485 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1486 addRegListOperands(Inst, N);
1487 }
1488
Jim Grosbach7e1547e2011-07-27 20:15:40 +00001489 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1490 assert(N == 1 && "Invalid number of operands!");
1491 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1492 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1493 }
1494
Jim Grosbach293a2ee2011-07-28 21:34:26 +00001495 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1496 assert(N == 1 && "Invalid number of operands!");
1497 // Munge the lsb/width into a bitfield mask.
1498 unsigned lsb = Bitfield.LSB;
1499 unsigned width = Bitfield.Width;
1500 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1501 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1502 (32 - (lsb + width)));
1503 Inst.addOperand(MCOperand::CreateImm(Mask));
1504 }
1505
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001506 void addImmOperands(MCInst &Inst, unsigned N) const {
1507 assert(N == 1 && "Invalid number of operands!");
1508 addExpr(Inst, getImm());
1509 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001510
Jim Grosbach4050bc42011-12-22 22:19:05 +00001511 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1512 assert(N == 1 && "Invalid number of operands!");
1513 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1514 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1515 }
1516
1517 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1518 assert(N == 1 && "Invalid number of operands!");
1519 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1520 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1521 }
1522
Jim Grosbach9d390362011-10-03 23:38:36 +00001523 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1524 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach51222d12012-01-20 18:09:51 +00001525 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1526 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1527 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach9d390362011-10-03 23:38:36 +00001528 }
1529
Jim Grosbacha77295d2011-09-08 22:07:06 +00001530 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1531 assert(N == 1 && "Invalid number of operands!");
1532 // FIXME: We really want to scale the value here, but the LDRD/STRD
1533 // instruction don't encode operands that way yet.
1534 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1535 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1536 }
1537
Jim Grosbach72f39f82011-08-24 21:22:15 +00001538 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1539 assert(N == 1 && "Invalid number of operands!");
1540 // The immediate is scaled by four in the encoding and is stored
1541 // in the MCInst as such. Lop off the low two bits here.
1542 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1543 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1544 }
1545
Jim Grosbach4e53fe82012-04-05 20:57:13 +00001546 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1547 assert(N == 1 && "Invalid number of operands!");
1548 // The immediate is scaled by four in the encoding and is stored
1549 // in the MCInst as such. Lop off the low two bits here.
1550 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1551 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1552 }
1553
Jim Grosbach72f39f82011-08-24 21:22:15 +00001554 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1555 assert(N == 1 && "Invalid number of operands!");
1556 // The immediate is scaled by four in the encoding and is stored
1557 // in the MCInst as such. Lop off the low two bits here.
1558 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1559 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1560 }
1561
Jim Grosbachf4943352011-07-25 23:09:14 +00001562 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1563 assert(N == 1 && "Invalid number of operands!");
1564 // The constant encodes as the immediate-1, and we store in the instruction
1565 // the bits as encoded, so subtract off one here.
1566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1567 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1568 }
1569
Jim Grosbach4a5ffb32011-07-22 23:16:18 +00001570 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1571 assert(N == 1 && "Invalid number of operands!");
1572 // The constant encodes as the immediate-1, and we store in the instruction
1573 // the bits as encoded, so subtract off one here.
1574 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1575 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1576 }
1577
Jim Grosbach70939ee2011-08-17 21:51:27 +00001578 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1579 assert(N == 1 && "Invalid number of operands!");
1580 // The constant encodes as the immediate, except for 32, which encodes as
1581 // zero.
1582 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1583 unsigned Imm = CE->getValue();
1584 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1585 }
1586
Jim Grosbachf6c05252011-07-21 17:23:04 +00001587 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1588 assert(N == 1 && "Invalid number of operands!");
1589 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1590 // the instruction as well.
1591 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1592 int Val = CE->getValue();
1593 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1594 }
1595
Jim Grosbach89a63372011-10-28 22:36:30 +00001596 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1597 assert(N == 1 && "Invalid number of operands!");
1598 // The operand is actually a t2_so_imm, but we have its bitwise
1599 // negation in the assembly source, so twiddle it here.
1600 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1601 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1602 }
1603
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001604 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1605 assert(N == 1 && "Invalid number of operands!");
1606 // The operand is actually a t2_so_imm, but we have its
1607 // negation in the assembly source, so twiddle it here.
1608 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1609 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1610 }
1611
Jim Grosbach4e53fe82012-04-05 20:57:13 +00001612 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1613 assert(N == 1 && "Invalid number of operands!");
1614 // The operand is actually an imm0_4095, but we have its
1615 // negation in the assembly source, so twiddle it here.
1616 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1617 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1618 }
1619
Jim Grosbache70ec842011-10-28 22:50:54 +00001620 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1621 assert(N == 1 && "Invalid number of operands!");
1622 // The operand is actually a so_imm, but we have its bitwise
1623 // negation in the assembly source, so twiddle it here.
1624 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1625 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1626 }
1627
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001628 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1629 assert(N == 1 && "Invalid number of operands!");
1630 // The operand is actually a so_imm, but we have its
1631 // negation in the assembly source, so twiddle it here.
1632 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1633 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1634 }
1635
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001636 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1637 assert(N == 1 && "Invalid number of operands!");
1638 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1639 }
1640
Jim Grosbach7ce05792011-08-03 23:50:40 +00001641 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1642 assert(N == 1 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001643 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00001644 }
1645
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001646 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1647 assert(N == 1 && "Invalid number of operands!");
1648 int32_t Imm = Memory.OffsetImm->getValue();
1649 // FIXME: Handle #-0
1650 if (Imm == INT32_MIN) Imm = 0;
1651 Inst.addOperand(MCOperand::CreateImm(Imm));
1652 }
1653
Jiangning Liu1fb27ec2012-08-02 08:13:13 +00001654 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1655 assert(N == 1 && "Invalid number of operands!");
1656 assert(isImm() && "Not an immediate!");
1657
1658 // If we have an immediate that's not a constant, treat it as a label
1659 // reference needing a fixup.
1660 if (!isa<MCConstantExpr>(getImm())) {
1661 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1662 return;
1663 }
1664
1665 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1666 int Val = CE->getValue();
1667 Inst.addOperand(MCOperand::CreateImm(Val));
1668 }
1669
Jim Grosbach57dcb852011-10-11 17:29:55 +00001670 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1671 assert(N == 2 && "Invalid number of operands!");
1672 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1673 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1674 }
1675
Jim Grosbach7ce05792011-08-03 23:50:40 +00001676 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1677 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001678 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1679 if (!Memory.OffsetRegNum) {
Jim Grosbach7ce05792011-08-03 23:50:40 +00001680 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1681 // Special case for #-0
1682 if (Val == INT32_MIN) Val = 0;
1683 if (Val < 0) Val = -Val;
1684 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1685 } else {
1686 // For register offset, we encode the shift type and negation flag
1687 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001688 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1689 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001690 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001691 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1692 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001693 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001694 }
1695
Jim Grosbach039c2e12011-08-04 23:01:30 +00001696 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1697 assert(N == 2 && "Invalid number of operands!");
1698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1699 assert(CE && "non-constant AM2OffsetImm operand!");
1700 int32_t Val = CE->getValue();
1701 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1702 // Special case for #-0
1703 if (Val == INT32_MIN) Val = 0;
1704 if (Val < 0) Val = -Val;
1705 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1706 Inst.addOperand(MCOperand::CreateReg(0));
1707 Inst.addOperand(MCOperand::CreateImm(Val));
1708 }
1709
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001710 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1711 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001712 // If we have an immediate that's not a constant, treat it as a label
1713 // reference needing a fixup. If it is a constant, it's something else
1714 // and we reject it.
1715 if (isImm()) {
1716 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1717 Inst.addOperand(MCOperand::CreateReg(0));
1718 Inst.addOperand(MCOperand::CreateImm(0));
1719 return;
1720 }
1721
Jim Grosbache53c87b2011-10-11 15:59:20 +00001722 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1723 if (!Memory.OffsetRegNum) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001724 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1725 // Special case for #-0
1726 if (Val == INT32_MIN) Val = 0;
1727 if (Val < 0) Val = -Val;
1728 Val = ARM_AM::getAM3Opc(AddSub, Val);
1729 } else {
1730 // For register offset, we encode the shift type and negation flag
1731 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001732 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001733 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001734 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1735 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001736 Inst.addOperand(MCOperand::CreateImm(Val));
1737 }
1738
1739 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1740 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001741 if (Kind == k_PostIndexRegister) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001742 int32_t Val =
1743 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1744 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1745 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach251bf252011-08-10 21:56:18 +00001746 return;
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001747 }
1748
1749 // Constant offset.
1750 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1751 int32_t Val = CE->getValue();
1752 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1753 // Special case for #-0
1754 if (Val == INT32_MIN) Val = 0;
1755 if (Val < 0) Val = -Val;
Jim Grosbach251bf252011-08-10 21:56:18 +00001756 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001757 Inst.addOperand(MCOperand::CreateReg(0));
1758 Inst.addOperand(MCOperand::CreateImm(Val));
1759 }
1760
Jim Grosbach7ce05792011-08-03 23:50:40 +00001761 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1762 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach681460f2011-11-01 01:24:45 +00001763 // If we have an immediate that's not a constant, treat it as a label
1764 // reference needing a fixup. If it is a constant, it's something else
1765 // and we reject it.
1766 if (isImm()) {
1767 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1768 Inst.addOperand(MCOperand::CreateImm(0));
1769 return;
1770 }
1771
Jim Grosbach7ce05792011-08-03 23:50:40 +00001772 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001773 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001774 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1775 // Special case for #-0
1776 if (Val == INT32_MIN) Val = 0;
1777 if (Val < 0) Val = -Val;
1778 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001779 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001780 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001781 }
1782
Jim Grosbacha77295d2011-09-08 22:07:06 +00001783 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1784 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001785 // If we have an immediate that's not a constant, treat it as a label
1786 // reference needing a fixup. If it is a constant, it's something else
1787 // and we reject it.
1788 if (isImm()) {
1789 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1790 Inst.addOperand(MCOperand::CreateImm(0));
1791 return;
1792 }
1793
Jim Grosbache53c87b2011-10-11 15:59:20 +00001794 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1795 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha77295d2011-09-08 22:07:06 +00001796 Inst.addOperand(MCOperand::CreateImm(Val));
1797 }
1798
Jim Grosbachb6aed502011-09-09 18:37:27 +00001799 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1800 assert(N == 2 && "Invalid number of operands!");
1801 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001802 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1803 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachb6aed502011-09-09 18:37:27 +00001804 Inst.addOperand(MCOperand::CreateImm(Val));
1805 }
1806
Jim Grosbach7ce05792011-08-03 23:50:40 +00001807 void addMemImm8OffsetOperands(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() : 0;
1810 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001811 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner14b93852010-10-29 00:27:31 +00001812 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001813
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001814 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1815 addMemImm8OffsetOperands(Inst, N);
1816 }
1817
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001818 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001819 addMemImm8OffsetOperands(Inst, N);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001820 }
1821
1822 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1823 assert(N == 2 && "Invalid number of operands!");
1824 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001825 if (isImm()) {
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001826 addExpr(Inst, getImm());
1827 Inst.addOperand(MCOperand::CreateImm(0));
1828 return;
1829 }
1830
1831 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001832 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1833 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001834 Inst.addOperand(MCOperand::CreateImm(Val));
1835 }
1836
Jim Grosbach7ce05792011-08-03 23:50:40 +00001837 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1838 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach09176e12011-08-08 20:59:31 +00001839 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001840 if (isImm()) {
Jim Grosbach09176e12011-08-08 20:59:31 +00001841 addExpr(Inst, getImm());
1842 Inst.addOperand(MCOperand::CreateImm(0));
1843 return;
1844 }
1845
1846 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001847 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1848 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001849 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendlingf4caf692010-12-14 03:36:38 +00001850 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001851
Jim Grosbach7f739be2011-09-19 22:21:13 +00001852 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1853 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001854 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1855 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001856 }
1857
1858 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1859 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001860 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1861 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001862 }
1863
Jim Grosbach7ce05792011-08-03 23:50:40 +00001864 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1865 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001866 unsigned Val =
1867 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1868 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001869 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1870 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001871 Inst.addOperand(MCOperand::CreateImm(Val));
1872 }
1873
Jim Grosbachab899c12011-09-07 23:10:15 +00001874 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1875 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001876 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1877 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1878 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbachab899c12011-09-07 23:10:15 +00001879 }
1880
Jim Grosbach7ce05792011-08-03 23:50:40 +00001881 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1882 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001883 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1884 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001885 }
1886
Jim Grosbach60f91a32011-08-19 17:55:24 +00001887 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1888 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001889 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1890 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +00001891 Inst.addOperand(MCOperand::CreateImm(Val));
1892 }
1893
Jim Grosbach38466302011-08-19 18:55:51 +00001894 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1895 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001896 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1897 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach38466302011-08-19 18:55:51 +00001898 Inst.addOperand(MCOperand::CreateImm(Val));
1899 }
1900
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001901 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1902 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001903 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1904 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001905 Inst.addOperand(MCOperand::CreateImm(Val));
1906 }
1907
Jim Grosbachecd85892011-08-19 18:13:48 +00001908 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1909 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001910 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1911 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachecd85892011-08-19 18:13:48 +00001912 Inst.addOperand(MCOperand::CreateImm(Val));
1913 }
1914
Jim Grosbach7ce05792011-08-03 23:50:40 +00001915 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1916 assert(N == 1 && "Invalid number of operands!");
1917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1918 assert(CE && "non-constant post-idx-imm8 operand!");
1919 int Imm = CE->getValue();
1920 bool isAdd = Imm >= 0;
Owen Anderson63553c72011-08-29 17:17:09 +00001921 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001922 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1923 Inst.addOperand(MCOperand::CreateImm(Imm));
1924 }
1925
Jim Grosbach2bd01182011-10-11 21:55:36 +00001926 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1927 assert(N == 1 && "Invalid number of operands!");
1928 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1929 assert(CE && "non-constant post-idx-imm8s4 operand!");
1930 int Imm = CE->getValue();
1931 bool isAdd = Imm >= 0;
1932 if (Imm == INT32_MIN) Imm = 0;
1933 // Immediate is scaled by 4.
1934 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1935 Inst.addOperand(MCOperand::CreateImm(Imm));
1936 }
1937
Jim Grosbach7ce05792011-08-03 23:50:40 +00001938 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1939 assert(N == 2 && "Invalid number of operands!");
1940 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00001941 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1942 }
1943
1944 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1945 assert(N == 2 && "Invalid number of operands!");
1946 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1947 // The sign, shift type, and shift amount are encoded in a single operand
1948 // using the AM2 encoding helpers.
1949 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1950 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1951 PostIdxReg.ShiftTy);
1952 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001953 }
1954
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001955 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1956 assert(N == 1 && "Invalid number of operands!");
1957 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1958 }
1959
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001960 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1961 assert(N == 1 && "Invalid number of operands!");
1962 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1963 }
1964
Jim Grosbach6029b6d2011-11-29 23:51:09 +00001965 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach862019c2011-10-18 23:02:30 +00001966 assert(N == 1 && "Invalid number of operands!");
1967 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1968 }
1969
Jim Grosbach7636bf62011-12-02 00:35:16 +00001970 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1971 assert(N == 2 && "Invalid number of operands!");
1972 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1973 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1974 }
1975
Jim Grosbach460a9052011-10-07 23:56:00 +00001976 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1977 assert(N == 1 && "Invalid number of operands!");
1978 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1979 }
1980
1981 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1982 assert(N == 1 && "Invalid number of operands!");
1983 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1984 }
1985
1986 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1987 assert(N == 1 && "Invalid number of operands!");
1988 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1989 }
1990
Jim Grosbach0e387b22011-10-17 22:26:03 +00001991 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1992 assert(N == 1 && "Invalid number of operands!");
1993 // The immediate encodes the type of constant as well as the value.
1994 // Mask in that this is an i8 splat.
1995 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1996 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1997 }
1998
Jim Grosbachea461102011-10-17 23:09:09 +00001999 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2000 assert(N == 1 && "Invalid number of operands!");
2001 // The immediate encodes the type of constant as well as the value.
2002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2003 unsigned Value = CE->getValue();
2004 if (Value >= 256)
2005 Value = (Value >> 8) | 0xa00;
2006 else
2007 Value |= 0x800;
2008 Inst.addOperand(MCOperand::CreateImm(Value));
2009 }
2010
Jim Grosbach6248a542011-10-18 00:22:00 +00002011 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2012 assert(N == 1 && "Invalid number of operands!");
2013 // The immediate encodes the type of constant as well as the value.
2014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2015 unsigned Value = CE->getValue();
2016 if (Value >= 256 && Value <= 0xff00)
2017 Value = (Value >> 8) | 0x200;
2018 else if (Value > 0xffff && Value <= 0xff0000)
2019 Value = (Value >> 16) | 0x400;
2020 else if (Value > 0xffffff)
2021 Value = (Value >> 24) | 0x600;
2022 Inst.addOperand(MCOperand::CreateImm(Value));
2023 }
2024
2025 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2026 assert(N == 1 && "Invalid number of operands!");
2027 // The immediate encodes the type of constant as well as the value.
2028 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2029 unsigned Value = CE->getValue();
2030 if (Value >= 256 && Value <= 0xffff)
2031 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2032 else if (Value > 0xffff && Value <= 0xffffff)
2033 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2034 else if (Value > 0xffffff)
2035 Value = (Value >> 24) | 0x600;
2036 Inst.addOperand(MCOperand::CreateImm(Value));
2037 }
2038
Jim Grosbach9b087852011-12-19 23:51:07 +00002039 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2040 assert(N == 1 && "Invalid number of operands!");
2041 // The immediate encodes the type of constant as well as the value.
2042 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2043 unsigned Value = ~CE->getValue();
2044 if (Value >= 256 && Value <= 0xffff)
2045 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2046 else if (Value > 0xffff && Value <= 0xffffff)
2047 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2048 else if (Value > 0xffffff)
2049 Value = (Value >> 24) | 0x600;
2050 Inst.addOperand(MCOperand::CreateImm(Value));
2051 }
2052
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00002053 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2054 assert(N == 1 && "Invalid number of operands!");
2055 // The immediate encodes the type of constant as well as the value.
2056 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2057 uint64_t Value = CE->getValue();
2058 unsigned Imm = 0;
2059 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2060 Imm |= (Value & 1) << i;
2061 }
2062 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2063 }
2064
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002065 virtual void print(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +00002066
Jim Grosbach89df9962011-08-26 21:43:41 +00002067 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002068 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach89df9962011-08-26 21:43:41 +00002069 Op->ITMask.Mask = Mask;
2070 Op->StartLoc = S;
2071 Op->EndLoc = S;
2072 return Op;
2073 }
2074
Chris Lattner3a697562010-10-28 17:20:03 +00002075 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002076 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002077 Op->CC.Val = CC;
2078 Op->StartLoc = S;
2079 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002080 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002081 }
2082
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002083 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002084 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002085 Op->Cop.Val = CopVal;
2086 Op->StartLoc = S;
2087 Op->EndLoc = S;
2088 return Op;
2089 }
2090
2091 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002092 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002093 Op->Cop.Val = CopVal;
2094 Op->StartLoc = S;
2095 Op->EndLoc = S;
2096 return Op;
2097 }
2098
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002099 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2100 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2101 Op->Cop.Val = Val;
2102 Op->StartLoc = S;
2103 Op->EndLoc = E;
2104 return Op;
2105 }
2106
Jim Grosbachd67641b2010-12-06 18:21:12 +00002107 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002108 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbachd67641b2010-12-06 18:21:12 +00002109 Op->Reg.RegNum = RegNum;
2110 Op->StartLoc = S;
2111 Op->EndLoc = S;
2112 return Op;
2113 }
2114
Chris Lattner3a697562010-10-28 17:20:03 +00002115 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002116 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan76264762010-04-02 22:27:05 +00002117 Op->Tok.Data = Str.data();
2118 Op->Tok.Length = Str.size();
2119 Op->StartLoc = S;
2120 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002121 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002122 }
2123
Bill Wendling50d0f582010-11-18 23:43:05 +00002124 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002125 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan76264762010-04-02 22:27:05 +00002126 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +00002127 Op->StartLoc = S;
2128 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002129 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002130 }
2131
Jim Grosbache8606dc2011-07-13 17:50:29 +00002132 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2133 unsigned SrcReg,
2134 unsigned ShiftReg,
2135 unsigned ShiftImm,
2136 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002137 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002138 Op->RegShiftedReg.ShiftTy = ShTy;
2139 Op->RegShiftedReg.SrcReg = SrcReg;
2140 Op->RegShiftedReg.ShiftReg = ShiftReg;
2141 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002142 Op->StartLoc = S;
2143 Op->EndLoc = E;
2144 return Op;
2145 }
2146
Owen Anderson92a20222011-07-21 18:54:16 +00002147 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2148 unsigned SrcReg,
2149 unsigned ShiftImm,
2150 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002151 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002152 Op->RegShiftedImm.ShiftTy = ShTy;
2153 Op->RegShiftedImm.SrcReg = SrcReg;
2154 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Anderson92a20222011-07-21 18:54:16 +00002155 Op->StartLoc = S;
2156 Op->EndLoc = E;
2157 return Op;
2158 }
2159
Jim Grosbach580f4a92011-07-25 22:20:28 +00002160 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002161 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002162 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach580f4a92011-07-25 22:20:28 +00002163 Op->ShifterImm.isASR = isASR;
2164 Op->ShifterImm.Imm = Imm;
Owen Anderson00828302011-03-18 22:50:18 +00002165 Op->StartLoc = S;
2166 Op->EndLoc = E;
2167 return Op;
2168 }
2169
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002170 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002171 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002172 Op->RotImm.Imm = Imm;
2173 Op->StartLoc = S;
2174 Op->EndLoc = E;
2175 return Op;
2176 }
2177
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002178 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2179 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002180 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002181 Op->Bitfield.LSB = LSB;
2182 Op->Bitfield.Width = Width;
2183 Op->StartLoc = S;
2184 Op->EndLoc = E;
2185 return Op;
2186 }
2187
Bill Wendling7729e062010-11-09 22:44:22 +00002188 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +00002189 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002190 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002191 KindTy Kind = k_RegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002192
Jim Grosbachd300b942011-09-13 22:56:44 +00002193 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002194 Kind = k_DPRRegisterList;
Jim Grosbachd300b942011-09-13 22:56:44 +00002195 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng275944a2011-07-25 21:32:49 +00002196 contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002197 Kind = k_SPRRegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002198
2199 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +00002200 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002201 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +00002202 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +00002203 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002204 Op->StartLoc = StartLoc;
2205 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +00002206 return Op;
2207 }
2208
Jim Grosbach862019c2011-10-18 23:02:30 +00002209 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002210 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbach862019c2011-10-18 23:02:30 +00002211 ARMOperand *Op = new ARMOperand(k_VectorList);
2212 Op->VectorList.RegNum = RegNum;
2213 Op->VectorList.Count = Count;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002214 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +00002215 Op->StartLoc = S;
2216 Op->EndLoc = E;
2217 return Op;
2218 }
2219
Jim Grosbach98b05a52011-11-30 01:09:44 +00002220 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002221 bool isDoubleSpaced,
Jim Grosbach98b05a52011-11-30 01:09:44 +00002222 SMLoc S, SMLoc E) {
2223 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2224 Op->VectorList.RegNum = RegNum;
2225 Op->VectorList.Count = Count;
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002226 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002227 Op->StartLoc = S;
2228 Op->EndLoc = E;
2229 return Op;
2230 }
2231
Jim Grosbach7636bf62011-12-02 00:35:16 +00002232 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002233 unsigned Index,
2234 bool isDoubleSpaced,
2235 SMLoc S, SMLoc E) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00002236 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2237 Op->VectorList.RegNum = RegNum;
2238 Op->VectorList.Count = Count;
2239 Op->VectorList.LaneIndex = Index;
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002240 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002241 Op->StartLoc = S;
2242 Op->EndLoc = E;
2243 return Op;
2244 }
2245
Jim Grosbach460a9052011-10-07 23:56:00 +00002246 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2247 MCContext &Ctx) {
2248 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2249 Op->VectorIndex.Val = Idx;
2250 Op->StartLoc = S;
2251 Op->EndLoc = E;
2252 return Op;
2253 }
2254
Chris Lattner3a697562010-10-28 17:20:03 +00002255 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002256 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan76264762010-04-02 22:27:05 +00002257 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +00002258 Op->StartLoc = S;
2259 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002260 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +00002261 }
2262
Jim Grosbach7ce05792011-08-03 23:50:40 +00002263 static ARMOperand *CreateMem(unsigned BaseRegNum,
2264 const MCConstantExpr *OffsetImm,
2265 unsigned OffsetRegNum,
2266 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach0d6fac32011-08-05 22:03:36 +00002267 unsigned ShiftImm,
Jim Grosbach57dcb852011-10-11 17:29:55 +00002268 unsigned Alignment,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002269 bool isNegative,
Chris Lattner3a697562010-10-28 17:20:03 +00002270 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002271 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbache53c87b2011-10-11 15:59:20 +00002272 Op->Memory.BaseRegNum = BaseRegNum;
2273 Op->Memory.OffsetImm = OffsetImm;
2274 Op->Memory.OffsetRegNum = OffsetRegNum;
2275 Op->Memory.ShiftType = ShiftType;
2276 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbach57dcb852011-10-11 17:29:55 +00002277 Op->Memory.Alignment = Alignment;
Jim Grosbache53c87b2011-10-11 15:59:20 +00002278 Op->Memory.isNegative = isNegative;
Jim Grosbach7ce05792011-08-03 23:50:40 +00002279 Op->StartLoc = S;
2280 Op->EndLoc = E;
2281 return Op;
2282 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002283
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002284 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2285 ARM_AM::ShiftOpc ShiftTy,
2286 unsigned ShiftImm,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002287 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002288 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbach7ce05792011-08-03 23:50:40 +00002289 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002290 Op->PostIdxReg.isAdd = isAdd;
2291 Op->PostIdxReg.ShiftTy = ShiftTy;
2292 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan76264762010-04-02 22:27:05 +00002293 Op->StartLoc = S;
2294 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002295 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002296 }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002297
2298 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002299 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002300 Op->MBOpt.Val = Opt;
2301 Op->StartLoc = S;
2302 Op->EndLoc = S;
2303 return Op;
2304 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002305
2306 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002307 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002308 Op->IFlags.Val = IFlags;
2309 Op->StartLoc = S;
2310 Op->EndLoc = S;
2311 return Op;
2312 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002313
2314 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002315 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002316 Op->MMask.Val = MMask;
2317 Op->StartLoc = S;
2318 Op->EndLoc = S;
2319 return Op;
2320 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002321};
2322
2323} // end anonymous namespace.
2324
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002325void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002326 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002327 case k_CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +00002328 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002329 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002330 case k_CCOut:
Jim Grosbachd67641b2010-12-06 18:21:12 +00002331 OS << "<ccout " << getReg() << ">";
2332 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002333 case k_ITCondMask: {
Craig Topper032f4412012-05-24 04:11:15 +00002334 static const char *const MaskStr[] = {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002335 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2336 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2337 };
Jim Grosbach89df9962011-08-26 21:43:41 +00002338 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2339 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2340 break;
2341 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002342 case k_CoprocNum:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002343 OS << "<coprocessor number: " << getCoproc() << ">";
2344 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002345 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002346 OS << "<coprocessor register: " << getCoproc() << ">";
2347 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002348 case k_CoprocOption:
2349 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2350 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002351 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002352 OS << "<mask: " << getMSRMask() << ">";
2353 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002354 case k_Immediate:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002355 getImm()->print(OS);
2356 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002357 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002358 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2359 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002360 case k_Memory:
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002361 OS << "<memory "
Jim Grosbache53c87b2011-10-11 15:59:20 +00002362 << " base:" << Memory.BaseRegNum;
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002363 OS << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002364 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002365 case k_PostIndexRegister:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002366 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2367 << PostIdxReg.RegNum;
2368 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2369 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2370 << PostIdxReg.ShiftImm;
2371 OS << ">";
Jim Grosbach7ce05792011-08-03 23:50:40 +00002372 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002373 case k_ProcIFlags: {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002374 OS << "<ARM_PROC::";
2375 unsigned IFlags = getProcIFlags();
2376 for (int i=2; i >= 0; --i)
2377 if (IFlags & (1 << i))
2378 OS << ARM_PROC::IFlagsToString(1 << i);
2379 OS << ">";
2380 break;
2381 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002382 case k_Register:
Bill Wendling50d0f582010-11-18 23:43:05 +00002383 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002384 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002385 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +00002386 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2387 << " #" << ShifterImm.Imm << ">";
Jim Grosbache8606dc2011-07-13 17:50:29 +00002388 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002389 case k_ShiftedRegister:
Owen Anderson92a20222011-07-21 18:54:16 +00002390 OS << "<so_reg_reg "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002391 << RegShiftedReg.SrcReg << " "
2392 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2393 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson00828302011-03-18 22:50:18 +00002394 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002395 case k_ShiftedImmediate:
Owen Anderson92a20222011-07-21 18:54:16 +00002396 OS << "<so_reg_imm "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002397 << RegShiftedImm.SrcReg << " "
2398 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2399 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Anderson92a20222011-07-21 18:54:16 +00002400 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002401 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002402 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2403 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002404 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002405 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2406 << ", width: " << Bitfield.Width << ">";
2407 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002408 case k_RegisterList:
2409 case k_DPRRegisterList:
2410 case k_SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +00002411 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002412
Bill Wendling5fa22a12010-11-09 23:28:44 +00002413 const SmallVectorImpl<unsigned> &RegList = getRegList();
2414 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002415 I = RegList.begin(), E = RegList.end(); I != E; ) {
2416 OS << *I;
2417 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002418 }
2419
2420 OS << ">";
2421 break;
2422 }
Jim Grosbach862019c2011-10-18 23:02:30 +00002423 case k_VectorList:
2424 OS << "<vector_list " << VectorList.Count << " * "
2425 << VectorList.RegNum << ">";
2426 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002427 case k_VectorListAllLanes:
2428 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2429 << VectorList.RegNum << ">";
2430 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002431 case k_VectorListIndexed:
2432 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2433 << VectorList.Count << " * " << VectorList.RegNum << ">";
2434 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002435 case k_Token:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002436 OS << "'" << getToken() << "'";
2437 break;
Jim Grosbach460a9052011-10-07 23:56:00 +00002438 case k_VectorIndex:
2439 OS << "<vectorindex " << getVectorIndex() << ">";
2440 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002441 }
2442}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002443
2444/// @name Auto-generated Match Functions
2445/// {
2446
2447static unsigned MatchRegisterName(StringRef Name);
2448
2449/// }
2450
Bob Wilson69df7232011-02-03 21:46:10 +00002451bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2452 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbacha39cda72011-12-14 02:16:11 +00002453 StartLoc = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002454 RegNo = tryParseRegister();
Jim Grosbacha39cda72011-12-14 02:16:11 +00002455 EndLoc = Parser.getTok().getLoc();
Roman Divackybf755322011-01-27 17:14:22 +00002456
2457 return (RegNo == (unsigned)-1);
2458}
2459
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002460/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +00002461/// and if it is a register name the token is eaten and the register number is
2462/// returned. Otherwise return -1.
2463///
Jim Grosbach1355cf12011-07-26 17:10:22 +00002464int ARMAsmParser::tryParseRegister() {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002465 const AsmToken &Tok = Parser.getTok();
Jim Grosbach7ce05792011-08-03 23:50:40 +00002466 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002467
Benjamin Kramer59085362011-11-06 20:37:06 +00002468 std::string lowerCase = Tok.getString().lower();
Owen Anderson0c9f2502011-01-13 22:50:36 +00002469 unsigned RegNum = MatchRegisterName(lowerCase);
2470 if (!RegNum) {
2471 RegNum = StringSwitch<unsigned>(lowerCase)
2472 .Case("r13", ARM::SP)
2473 .Case("r14", ARM::LR)
2474 .Case("r15", ARM::PC)
2475 .Case("ip", ARM::R12)
Jim Grosbach40e28552011-12-08 19:27:38 +00002476 // Additional register name aliases for 'gas' compatibility.
2477 .Case("a1", ARM::R0)
2478 .Case("a2", ARM::R1)
2479 .Case("a3", ARM::R2)
2480 .Case("a4", ARM::R3)
2481 .Case("v1", ARM::R4)
2482 .Case("v2", ARM::R5)
2483 .Case("v3", ARM::R6)
2484 .Case("v4", ARM::R7)
2485 .Case("v5", ARM::R8)
2486 .Case("v6", ARM::R9)
2487 .Case("v7", ARM::R10)
2488 .Case("v8", ARM::R11)
2489 .Case("sb", ARM::R9)
2490 .Case("sl", ARM::R10)
2491 .Case("fp", ARM::R11)
Owen Anderson0c9f2502011-01-13 22:50:36 +00002492 .Default(0);
2493 }
Jim Grosbacha39cda72011-12-14 02:16:11 +00002494 if (!RegNum) {
Jim Grosbachaee718b2011-12-20 23:11:00 +00002495 // Check for aliases registered via .req. Canonicalize to lower case.
2496 // That's more consistent since register names are case insensitive, and
2497 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2498 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbacha39cda72011-12-14 02:16:11 +00002499 // If no match, return failure.
2500 if (Entry == RegisterReqs.end())
2501 return -1;
2502 Parser.Lex(); // Eat identifier token.
2503 return Entry->getValue();
2504 }
Bob Wilson69df7232011-02-03 21:46:10 +00002505
Chris Lattnere5658fa2010-10-30 04:09:10 +00002506 Parser.Lex(); // Eat identifier token.
Jim Grosbach460a9052011-10-07 23:56:00 +00002507
Chris Lattnere5658fa2010-10-30 04:09:10 +00002508 return RegNum;
2509}
Jim Grosbachd4462a52010-11-01 16:44:21 +00002510
Jim Grosbach19906722011-07-13 18:49:30 +00002511// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2512// If a recoverable error occurs, return 1. If an irrecoverable error
2513// occurs, return -1. An irrecoverable error is one where tokens have been
2514// consumed in the process of trying to parse the shifter (i.e., when it is
2515// indeed a shifter operand, but malformed).
Jim Grosbach0d87ec22011-07-26 20:41:24 +00002516int ARMAsmParser::tryParseShiftRegister(
Owen Anderson00828302011-03-18 22:50:18 +00002517 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2518 SMLoc S = Parser.getTok().getLoc();
2519 const AsmToken &Tok = Parser.getTok();
2520 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2521
Benjamin Kramer59085362011-11-06 20:37:06 +00002522 std::string lowerCase = Tok.getString().lower();
Owen Anderson00828302011-03-18 22:50:18 +00002523 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbachaf4edea2011-12-07 23:40:58 +00002524 .Case("asl", ARM_AM::lsl)
Owen Anderson00828302011-03-18 22:50:18 +00002525 .Case("lsl", ARM_AM::lsl)
2526 .Case("lsr", ARM_AM::lsr)
2527 .Case("asr", ARM_AM::asr)
2528 .Case("ror", ARM_AM::ror)
2529 .Case("rrx", ARM_AM::rrx)
2530 .Default(ARM_AM::no_shift);
2531
2532 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbach19906722011-07-13 18:49:30 +00002533 return 1;
Owen Anderson00828302011-03-18 22:50:18 +00002534
Jim Grosbache8606dc2011-07-13 17:50:29 +00002535 Parser.Lex(); // Eat the operator.
Owen Anderson00828302011-03-18 22:50:18 +00002536
Jim Grosbache8606dc2011-07-13 17:50:29 +00002537 // The source register for the shift has already been added to the
2538 // operand list, so we need to pop it off and combine it into the shifted
2539 // register operand instead.
Benjamin Kramereac07962011-07-14 18:41:22 +00002540 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbache8606dc2011-07-13 17:50:29 +00002541 if (!PrevOp->isReg())
2542 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2543 int SrcReg = PrevOp->getReg();
2544 int64_t Imm = 0;
2545 int ShiftReg = 0;
2546 if (ShiftTy == ARM_AM::rrx) {
2547 // RRX Doesn't have an explicit shift amount. The encoder expects
2548 // the shift register to be the same as the source register. Seems odd,
2549 // but OK.
2550 ShiftReg = SrcReg;
2551 } else {
2552 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00002553 if (Parser.getTok().is(AsmToken::Hash) ||
2554 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbache8606dc2011-07-13 17:50:29 +00002555 Parser.Lex(); // Eat hash.
2556 SMLoc ImmLoc = Parser.getTok().getLoc();
2557 const MCExpr *ShiftExpr = 0;
Jim Grosbach19906722011-07-13 18:49:30 +00002558 if (getParser().ParseExpression(ShiftExpr)) {
2559 Error(ImmLoc, "invalid immediate shift value");
2560 return -1;
2561 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002562 // The expression must be evaluatable as an immediate.
2563 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbach19906722011-07-13 18:49:30 +00002564 if (!CE) {
2565 Error(ImmLoc, "invalid immediate shift value");
2566 return -1;
2567 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002568 // Range check the immediate.
2569 // lsl, ror: 0 <= imm <= 31
2570 // lsr, asr: 0 <= imm <= 32
2571 Imm = CE->getValue();
2572 if (Imm < 0 ||
2573 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2574 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbach19906722011-07-13 18:49:30 +00002575 Error(ImmLoc, "immediate shift value out of range");
2576 return -1;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002577 }
Jim Grosbachde626ad2011-12-22 17:37:00 +00002578 // shift by zero is a nop. Always send it through as lsl.
2579 // ('as' compatibility)
2580 if (Imm == 0)
2581 ShiftTy = ARM_AM::lsl;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002582 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach1355cf12011-07-26 17:10:22 +00002583 ShiftReg = tryParseRegister();
Jim Grosbache8606dc2011-07-13 17:50:29 +00002584 SMLoc L = Parser.getTok().getLoc();
Jim Grosbach19906722011-07-13 18:49:30 +00002585 if (ShiftReg == -1) {
2586 Error (L, "expected immediate or register in shift operand");
2587 return -1;
2588 }
2589 } else {
2590 Error (Parser.getTok().getLoc(),
Jim Grosbache8606dc2011-07-13 17:50:29 +00002591 "expected immediate or register in shift operand");
Jim Grosbach19906722011-07-13 18:49:30 +00002592 return -1;
2593 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002594 }
2595
Owen Anderson92a20222011-07-21 18:54:16 +00002596 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2597 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002598 ShiftReg, Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002599 S, Parser.getTok().getLoc()));
Owen Anderson92a20222011-07-21 18:54:16 +00002600 else
2601 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2602 S, Parser.getTok().getLoc()));
Owen Anderson00828302011-03-18 22:50:18 +00002603
Jim Grosbach19906722011-07-13 18:49:30 +00002604 return 0;
Owen Anderson00828302011-03-18 22:50:18 +00002605}
2606
2607
Bill Wendling50d0f582010-11-18 23:43:05 +00002608/// Try to parse a register name. The token must be an Identifier when called.
2609/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2610/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +00002611///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002612/// TODO this is likely to change to allow different register types and or to
2613/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +00002614bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002615tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002616 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002617 int RegNo = tryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +00002618 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +00002619 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002620
Bill Wendling50d0f582010-11-18 23:43:05 +00002621 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002622
Chris Lattnere5658fa2010-10-30 04:09:10 +00002623 const AsmToken &ExclaimTok = Parser.getTok();
2624 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +00002625 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2626 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +00002627 Parser.Lex(); // Eat exclaim token
Jim Grosbach460a9052011-10-07 23:56:00 +00002628 return false;
2629 }
2630
2631 // Also check for an index operand. This is only legal for vector registers,
2632 // but that'll get caught OK in operand matching, so we don't need to
2633 // explicitly filter everything else out here.
2634 if (Parser.getTok().is(AsmToken::LBrac)) {
2635 SMLoc SIdx = Parser.getTok().getLoc();
2636 Parser.Lex(); // Eat left bracket token.
2637
2638 const MCExpr *ImmVal;
Jim Grosbach460a9052011-10-07 23:56:00 +00002639 if (getParser().ParseExpression(ImmVal))
Jim Grosbach24dda212012-01-31 23:51:09 +00002640 return true;
Jim Grosbach460a9052011-10-07 23:56:00 +00002641 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002642 if (!MCE)
2643 return TokError("immediate value expected for vector index");
Jim Grosbach460a9052011-10-07 23:56:00 +00002644
2645 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002646 if (Parser.getTok().isNot(AsmToken::RBrac))
2647 return Error(E, "']' expected");
Jim Grosbach460a9052011-10-07 23:56:00 +00002648
2649 Parser.Lex(); // Eat right bracket token.
2650
2651 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2652 SIdx, E,
2653 getContext()));
Kevin Enderby99e6d4e2009-10-07 18:01:35 +00002654 }
2655
Bill Wendling50d0f582010-11-18 23:43:05 +00002656 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002657}
2658
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002659/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2660/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2661/// "c5", ...
2662static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002663 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2664 // but efficient.
2665 switch (Name.size()) {
David Blaikie4d6ccb52012-01-20 21:51:11 +00002666 default: return -1;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002667 case 2:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002668 if (Name[0] != CoprocOp)
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002669 return -1;
2670 switch (Name[1]) {
2671 default: return -1;
2672 case '0': return 0;
2673 case '1': return 1;
2674 case '2': return 2;
2675 case '3': return 3;
2676 case '4': return 4;
2677 case '5': return 5;
2678 case '6': return 6;
2679 case '7': return 7;
2680 case '8': return 8;
2681 case '9': return 9;
2682 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002683 case 3:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002684 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002685 return -1;
2686 switch (Name[2]) {
2687 default: return -1;
2688 case '0': return 10;
2689 case '1': return 11;
2690 case '2': return 12;
2691 case '3': return 13;
2692 case '4': return 14;
2693 case '5': return 15;
2694 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002695 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002696}
2697
Jim Grosbach89df9962011-08-26 21:43:41 +00002698/// parseITCondCode - Try to parse a condition code for an IT instruction.
2699ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2700parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2701 SMLoc S = Parser.getTok().getLoc();
2702 const AsmToken &Tok = Parser.getTok();
2703 if (!Tok.is(AsmToken::Identifier))
2704 return MatchOperand_NoMatch;
Richard Barton04a09a42012-04-27 17:34:01 +00002705 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach89df9962011-08-26 21:43:41 +00002706 .Case("eq", ARMCC::EQ)
2707 .Case("ne", ARMCC::NE)
2708 .Case("hs", ARMCC::HS)
2709 .Case("cs", ARMCC::HS)
2710 .Case("lo", ARMCC::LO)
2711 .Case("cc", ARMCC::LO)
2712 .Case("mi", ARMCC::MI)
2713 .Case("pl", ARMCC::PL)
2714 .Case("vs", ARMCC::VS)
2715 .Case("vc", ARMCC::VC)
2716 .Case("hi", ARMCC::HI)
2717 .Case("ls", ARMCC::LS)
2718 .Case("ge", ARMCC::GE)
2719 .Case("lt", ARMCC::LT)
2720 .Case("gt", ARMCC::GT)
2721 .Case("le", ARMCC::LE)
2722 .Case("al", ARMCC::AL)
2723 .Default(~0U);
2724 if (CC == ~0U)
2725 return MatchOperand_NoMatch;
2726 Parser.Lex(); // Eat the token.
2727
2728 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2729
2730 return MatchOperand_Success;
2731}
2732
Jim Grosbach43904292011-07-25 20:14:50 +00002733/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002734/// token must be an Identifier when called, and if it is a coprocessor
2735/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002736ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002737parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002738 SMLoc S = Parser.getTok().getLoc();
2739 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002740 if (Tok.isNot(AsmToken::Identifier))
2741 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002742
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002743 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002744 if (Num == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002745 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002746
2747 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002748 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002749 return MatchOperand_Success;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002750}
2751
Jim Grosbach43904292011-07-25 20:14:50 +00002752/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002753/// token must be an Identifier when called, and if it is a coprocessor
2754/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002755ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002756parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002757 SMLoc S = Parser.getTok().getLoc();
2758 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002759 if (Tok.isNot(AsmToken::Identifier))
2760 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002761
2762 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2763 if (Reg == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002764 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002765
2766 Parser.Lex(); // Eat identifier token.
2767 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002768 return MatchOperand_Success;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002769}
2770
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002771/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2772/// coproc_option : '{' imm0_255 '}'
2773ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2774parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2775 SMLoc S = Parser.getTok().getLoc();
2776
2777 // If this isn't a '{', this isn't a coprocessor immediate operand.
2778 if (Parser.getTok().isNot(AsmToken::LCurly))
2779 return MatchOperand_NoMatch;
2780 Parser.Lex(); // Eat the '{'
2781
2782 const MCExpr *Expr;
2783 SMLoc Loc = Parser.getTok().getLoc();
2784 if (getParser().ParseExpression(Expr)) {
2785 Error(Loc, "illegal expression");
2786 return MatchOperand_ParseFail;
2787 }
2788 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2789 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2790 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2791 return MatchOperand_ParseFail;
2792 }
2793 int Val = CE->getValue();
2794
2795 // Check for and consume the closing '}'
2796 if (Parser.getTok().isNot(AsmToken::RCurly))
2797 return MatchOperand_ParseFail;
2798 SMLoc E = Parser.getTok().getLoc();
2799 Parser.Lex(); // Eat the '}'
2800
2801 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2802 return MatchOperand_Success;
2803}
2804
Jim Grosbachd0588e22011-09-14 18:08:35 +00002805// For register list parsing, we need to map from raw GPR register numbering
2806// to the enumeration values. The enumeration values aren't sorted by
2807// register number due to our using "sp", "lr" and "pc" as canonical names.
2808static unsigned getNextRegister(unsigned Reg) {
2809 // If this is a GPR, we need to do it manually, otherwise we can rely
2810 // on the sort ordering of the enumeration since the other reg-classes
2811 // are sane.
2812 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2813 return Reg + 1;
2814 switch(Reg) {
Craig Topperbc219812012-02-07 02:50:20 +00002815 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbachd0588e22011-09-14 18:08:35 +00002816 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2817 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2818 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2819 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2820 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2821 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2822 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2823 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2824 }
2825}
2826
Jim Grosbachce485e72011-11-11 21:27:40 +00002827// Return the low-subreg of a given Q register.
2828static unsigned getDRegFromQReg(unsigned QReg) {
2829 switch (QReg) {
2830 default: llvm_unreachable("expected a Q register!");
2831 case ARM::Q0: return ARM::D0;
2832 case ARM::Q1: return ARM::D2;
2833 case ARM::Q2: return ARM::D4;
2834 case ARM::Q3: return ARM::D6;
2835 case ARM::Q4: return ARM::D8;
2836 case ARM::Q5: return ARM::D10;
2837 case ARM::Q6: return ARM::D12;
2838 case ARM::Q7: return ARM::D14;
2839 case ARM::Q8: return ARM::D16;
Jim Grosbach25e0a872011-11-15 21:01:30 +00002840 case ARM::Q9: return ARM::D18;
Jim Grosbachce485e72011-11-11 21:27:40 +00002841 case ARM::Q10: return ARM::D20;
2842 case ARM::Q11: return ARM::D22;
2843 case ARM::Q12: return ARM::D24;
2844 case ARM::Q13: return ARM::D26;
2845 case ARM::Q14: return ARM::D28;
2846 case ARM::Q15: return ARM::D30;
2847 }
2848}
2849
Jim Grosbachd0588e22011-09-14 18:08:35 +00002850/// Parse a register list.
Bill Wendling50d0f582010-11-18 23:43:05 +00002851bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002852parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +00002853 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00002854 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +00002855 SMLoc S = Parser.getTok().getLoc();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002856 Parser.Lex(); // Eat '{' token.
2857 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002858
Jim Grosbachd0588e22011-09-14 18:08:35 +00002859 // Check the first register in the list to see what register class
2860 // this is a list of.
2861 int Reg = tryParseRegister();
2862 if (Reg == -1)
2863 return Error(RegLoc, "register expected");
2864
Jim Grosbachce485e72011-11-11 21:27:40 +00002865 // The reglist instructions have at most 16 registers, so reserve
2866 // space for that many.
2867 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2868
2869 // Allow Q regs and just interpret them as the two D sub-registers.
2870 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2871 Reg = getDRegFromQReg(Reg);
2872 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2873 ++Reg;
2874 }
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002875 const MCRegisterClass *RC;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002876 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2877 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2878 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2879 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2880 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2881 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2882 else
2883 return Error(RegLoc, "invalid register in register list");
2884
Jim Grosbachce485e72011-11-11 21:27:40 +00002885 // Store the register.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002886 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002887
Jim Grosbachd0588e22011-09-14 18:08:35 +00002888 // This starts immediately after the first register token in the list,
2889 // so we can see either a comma or a minus (range separator) as a legal
2890 // next token.
2891 while (Parser.getTok().is(AsmToken::Comma) ||
2892 Parser.getTok().is(AsmToken::Minus)) {
2893 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache43862b2011-11-15 23:19:15 +00002894 Parser.Lex(); // Eat the minus.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002895 SMLoc EndLoc = Parser.getTok().getLoc();
2896 int EndReg = tryParseRegister();
2897 if (EndReg == -1)
2898 return Error(EndLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002899 // Allow Q regs and just interpret them as the two D sub-registers.
2900 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2901 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002902 // If the register is the same as the start reg, there's nothing
2903 // more to do.
2904 if (Reg == EndReg)
2905 continue;
2906 // The register must be in the same register class as the first.
2907 if (!RC->contains(EndReg))
2908 return Error(EndLoc, "invalid register in register list");
2909 // Ranges must go from low to high.
2910 if (getARMRegisterNumbering(Reg) > getARMRegisterNumbering(EndReg))
2911 return Error(EndLoc, "bad range in register list");
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002912
Jim Grosbachd0588e22011-09-14 18:08:35 +00002913 // Add all the registers in the range to the register list.
2914 while (Reg != EndReg) {
2915 Reg = getNextRegister(Reg);
2916 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2917 }
2918 continue;
2919 }
2920 Parser.Lex(); // Eat the comma.
2921 RegLoc = Parser.getTok().getLoc();
2922 int OldReg = Reg;
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002923 const AsmToken RegTok = Parser.getTok();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002924 Reg = tryParseRegister();
2925 if (Reg == -1)
Jim Grosbach2d539692011-09-12 23:36:42 +00002926 return Error(RegLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002927 // Allow Q regs and just interpret them as the two D sub-registers.
2928 bool isQReg = false;
2929 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2930 Reg = getDRegFromQReg(Reg);
2931 isQReg = true;
2932 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002933 // The register must be in the same register class as the first.
2934 if (!RC->contains(Reg))
2935 return Error(RegLoc, "invalid register in register list");
2936 // List must be monotonically increasing.
Jim Grosbachbe7cf2b2012-03-16 20:48:38 +00002937 if (getARMRegisterNumbering(Reg) < getARMRegisterNumbering(OldReg)) {
2938 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2939 Warning(RegLoc, "register list not in ascending order");
2940 else
2941 return Error(RegLoc, "register list not in ascending order");
2942 }
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002943 if (getARMRegisterNumbering(Reg) == getARMRegisterNumbering(OldReg)) {
2944 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2945 ") in register list");
2946 continue;
2947 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002948 // VFP register lists must also be contiguous.
2949 // It's OK to use the enumeration values directly here rather, as the
2950 // VFP register classes have the enum sorted properly.
2951 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2952 Reg != OldReg + 1)
2953 return Error(RegLoc, "non-contiguous register range");
2954 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbachce485e72011-11-11 21:27:40 +00002955 if (isQReg)
2956 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge7176102010-11-06 22:36:58 +00002957 }
2958
Jim Grosbachd0588e22011-09-14 18:08:35 +00002959 SMLoc E = Parser.getTok().getLoc();
2960 if (Parser.getTok().isNot(AsmToken::RCurly))
2961 return Error(E, "'}' expected");
2962 Parser.Lex(); // Eat '}' token.
2963
Jim Grosbach27debd62011-12-13 21:48:29 +00002964 // Push the register list operand.
Bill Wendling50d0f582010-11-18 23:43:05 +00002965 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach27debd62011-12-13 21:48:29 +00002966
2967 // The ARM system instruction variants for LDM/STM have a '^' token here.
2968 if (Parser.getTok().is(AsmToken::Caret)) {
2969 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2970 Parser.Lex(); // Eat '^' token.
2971 }
2972
Bill Wendling50d0f582010-11-18 23:43:05 +00002973 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002974}
2975
Jim Grosbach98b05a52011-11-30 01:09:44 +00002976// Helper function to parse the lane index for vector lists.
2977ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach7636bf62011-12-02 00:35:16 +00002978parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2979 Index = 0; // Always return a defined index value.
Jim Grosbach98b05a52011-11-30 01:09:44 +00002980 if (Parser.getTok().is(AsmToken::LBrac)) {
2981 Parser.Lex(); // Eat the '['.
2982 if (Parser.getTok().is(AsmToken::RBrac)) {
2983 // "Dn[]" is the 'all lanes' syntax.
2984 LaneKind = AllLanes;
2985 Parser.Lex(); // Eat the ']'.
2986 return MatchOperand_Success;
2987 }
Jim Grosbachceee9842012-03-19 20:39:53 +00002988
2989 // There's an optional '#' token here. Normally there wouldn't be, but
2990 // inline assemble puts one in, and it's friendly to accept that.
2991 if (Parser.getTok().is(AsmToken::Hash))
2992 Parser.Lex(); // Eat the '#'
2993
Jim Grosbachc9313252011-12-21 01:19:23 +00002994 const MCExpr *LaneIndex;
2995 SMLoc Loc = Parser.getTok().getLoc();
2996 if (getParser().ParseExpression(LaneIndex)) {
2997 Error(Loc, "illegal expression");
2998 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002999 }
Jim Grosbachc9313252011-12-21 01:19:23 +00003000 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3001 if (!CE) {
3002 Error(Loc, "lane index must be empty or an integer");
3003 return MatchOperand_ParseFail;
3004 }
3005 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3006 Error(Parser.getTok().getLoc(), "']' expected");
3007 return MatchOperand_ParseFail;
3008 }
3009 Parser.Lex(); // Eat the ']'.
3010 int64_t Val = CE->getValue();
3011
3012 // FIXME: Make this range check context sensitive for .8, .16, .32.
3013 if (Val < 0 || Val > 7) {
3014 Error(Parser.getTok().getLoc(), "lane index out of range");
3015 return MatchOperand_ParseFail;
3016 }
3017 Index = Val;
3018 LaneKind = IndexedLane;
3019 return MatchOperand_Success;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003020 }
3021 LaneKind = NoLanes;
3022 return MatchOperand_Success;
3023}
3024
Jim Grosbach862019c2011-10-18 23:02:30 +00003025// parse a vector register list
3026ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3027parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003028 VectorLaneTy LaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003029 unsigned LaneIndex;
Jim Grosbach5c984e42011-11-15 21:45:55 +00003030 SMLoc S = Parser.getTok().getLoc();
3031 // As an extension (to match gas), support a plain D register or Q register
3032 // (without encosing curly braces) as a single or double entry list,
3033 // respectively.
3034 if (Parser.getTok().is(AsmToken::Identifier)) {
3035 int Reg = tryParseRegister();
3036 if (Reg == -1)
3037 return MatchOperand_NoMatch;
3038 SMLoc E = Parser.getTok().getLoc();
3039 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00003040 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00003041 if (Res != MatchOperand_Success)
3042 return Res;
3043 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003044 case NoLanes:
3045 E = Parser.getTok().getLoc();
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003046 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003047 break;
3048 case AllLanes:
3049 E = Parser.getTok().getLoc();
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003050 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3051 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003052 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003053 case IndexedLane:
3054 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003055 LaneIndex,
3056 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003057 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003058 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003059 return MatchOperand_Success;
3060 }
3061 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3062 Reg = getDRegFromQReg(Reg);
Jim Grosbach7636bf62011-12-02 00:35:16 +00003063 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00003064 if (Res != MatchOperand_Success)
3065 return Res;
3066 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003067 case NoLanes:
3068 E = Parser.getTok().getLoc();
Jim Grosbach28f08c92012-03-05 19:33:30 +00003069 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003070 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003071 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003072 break;
3073 case AllLanes:
3074 E = Parser.getTok().getLoc();
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003075 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3076 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003077 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3078 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003079 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003080 case IndexedLane:
3081 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003082 LaneIndex,
3083 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003084 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003085 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003086 return MatchOperand_Success;
3087 }
3088 Error(S, "vector register expected");
3089 return MatchOperand_ParseFail;
3090 }
3091
3092 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbach862019c2011-10-18 23:02:30 +00003093 return MatchOperand_NoMatch;
3094
Jim Grosbach862019c2011-10-18 23:02:30 +00003095 Parser.Lex(); // Eat '{' token.
3096 SMLoc RegLoc = Parser.getTok().getLoc();
3097
3098 int Reg = tryParseRegister();
3099 if (Reg == -1) {
3100 Error(RegLoc, "register expected");
3101 return MatchOperand_ParseFail;
3102 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003103 unsigned Count = 1;
Jim Grosbach276ed032011-12-15 21:54:55 +00003104 int Spacing = 0;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003105 unsigned FirstReg = Reg;
3106 // The list is of D registers, but we also allow Q regs and just interpret
3107 // them as the two D sub-registers.
3108 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3109 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003110 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3111 // it's ambiguous with four-register single spaced.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003112 ++Reg;
3113 ++Count;
3114 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00003115 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003116 return MatchOperand_ParseFail;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003117
Jim Grosbache43862b2011-11-15 23:19:15 +00003118 while (Parser.getTok().is(AsmToken::Comma) ||
3119 Parser.getTok().is(AsmToken::Minus)) {
3120 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003121 if (!Spacing)
3122 Spacing = 1; // Register range implies a single spaced list.
3123 else if (Spacing == 2) {
3124 Error(Parser.getTok().getLoc(),
3125 "sequential registers in double spaced list");
3126 return MatchOperand_ParseFail;
3127 }
Jim Grosbache43862b2011-11-15 23:19:15 +00003128 Parser.Lex(); // Eat the minus.
3129 SMLoc EndLoc = Parser.getTok().getLoc();
3130 int EndReg = tryParseRegister();
3131 if (EndReg == -1) {
3132 Error(EndLoc, "register expected");
3133 return MatchOperand_ParseFail;
3134 }
3135 // Allow Q regs and just interpret them as the two D sub-registers.
3136 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3137 EndReg = getDRegFromQReg(EndReg) + 1;
3138 // If the register is the same as the start reg, there's nothing
3139 // more to do.
3140 if (Reg == EndReg)
3141 continue;
3142 // The register must be in the same register class as the first.
3143 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3144 Error(EndLoc, "invalid register in register list");
3145 return MatchOperand_ParseFail;
3146 }
3147 // Ranges must go from low to high.
3148 if (Reg > EndReg) {
3149 Error(EndLoc, "bad range in register list");
3150 return MatchOperand_ParseFail;
3151 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003152 // Parse the lane specifier if present.
3153 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003154 unsigned NextLaneIndex;
3155 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003156 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003157 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003158 Error(EndLoc, "mismatched lane index in register list");
3159 return MatchOperand_ParseFail;
3160 }
3161 EndLoc = Parser.getTok().getLoc();
Jim Grosbache43862b2011-11-15 23:19:15 +00003162
3163 // Add all the registers in the range to the register list.
3164 Count += EndReg - Reg;
3165 Reg = EndReg;
3166 continue;
3167 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003168 Parser.Lex(); // Eat the comma.
3169 RegLoc = Parser.getTok().getLoc();
3170 int OldReg = Reg;
3171 Reg = tryParseRegister();
3172 if (Reg == -1) {
3173 Error(RegLoc, "register expected");
3174 return MatchOperand_ParseFail;
3175 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003176 // vector register lists must be contiguous.
Jim Grosbach862019c2011-10-18 23:02:30 +00003177 // It's OK to use the enumeration values directly here rather, as the
3178 // VFP register classes have the enum sorted properly.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003179 //
3180 // The list is of D registers, but we also allow Q regs and just interpret
3181 // them as the two D sub-registers.
3182 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003183 if (!Spacing)
3184 Spacing = 1; // Register range implies a single spaced list.
3185 else if (Spacing == 2) {
3186 Error(RegLoc,
3187 "invalid register in double-spaced list (must be 'D' register')");
3188 return MatchOperand_ParseFail;
3189 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003190 Reg = getDRegFromQReg(Reg);
3191 if (Reg != OldReg + 1) {
3192 Error(RegLoc, "non-contiguous register range");
3193 return MatchOperand_ParseFail;
3194 }
3195 ++Reg;
3196 Count += 2;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003197 // Parse the lane specifier if present.
3198 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003199 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003200 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003201 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003202 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003203 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003204 Error(EndLoc, "mismatched lane index in register list");
3205 return MatchOperand_ParseFail;
3206 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003207 continue;
3208 }
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003209 // Normal D register.
3210 // Figure out the register spacing (single or double) of the list if
3211 // we don't know it already.
3212 if (!Spacing)
3213 Spacing = 1 + (Reg == OldReg + 2);
3214
3215 // Just check that it's contiguous and keep going.
3216 if (Reg != OldReg + Spacing) {
Jim Grosbach862019c2011-10-18 23:02:30 +00003217 Error(RegLoc, "non-contiguous register range");
3218 return MatchOperand_ParseFail;
3219 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003220 ++Count;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003221 // Parse the lane specifier if present.
3222 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003223 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003224 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003225 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003226 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003227 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003228 Error(EndLoc, "mismatched lane index in register list");
3229 return MatchOperand_ParseFail;
3230 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003231 }
3232
3233 SMLoc E = Parser.getTok().getLoc();
3234 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3235 Error(E, "'}' expected");
3236 return MatchOperand_ParseFail;
3237 }
3238 Parser.Lex(); // Eat '}' token.
3239
Jim Grosbach98b05a52011-11-30 01:09:44 +00003240 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003241 case NoLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003242 // Two-register operands have been converted to the
Jim Grosbachc3384c92012-03-05 21:43:40 +00003243 // composite register classes.
3244 if (Count == 2) {
3245 const MCRegisterClass *RC = (Spacing == 1) ?
3246 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3247 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3248 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3249 }
Jim Grosbach28f08c92012-03-05 19:33:30 +00003250
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003251 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3252 (Spacing == 2), S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003253 break;
3254 case AllLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003255 // Two-register operands have been converted to the
3256 // composite register classes.
Jim Grosbach4d0983a2012-03-06 23:10:38 +00003257 if (Count == 2) {
3258 const MCRegisterClass *RC = (Spacing == 1) ?
3259 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3260 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003261 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3262 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003263 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003264 (Spacing == 2),
Jim Grosbach98b05a52011-11-30 01:09:44 +00003265 S, E));
3266 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003267 case IndexedLane:
3268 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003269 LaneIndex,
3270 (Spacing == 2),
3271 S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003272 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003273 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003274 return MatchOperand_Success;
3275}
3276
Jim Grosbach43904292011-07-25 20:14:50 +00003277/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbachf922c472011-02-12 01:34:40 +00003278ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003279parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003280 SMLoc S = Parser.getTok().getLoc();
3281 const AsmToken &Tok = Parser.getTok();
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003282 unsigned Opt;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003283
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003284 if (Tok.is(AsmToken::Identifier)) {
3285 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003286
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003287 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3288 .Case("sy", ARM_MB::SY)
3289 .Case("st", ARM_MB::ST)
3290 .Case("sh", ARM_MB::ISH)
3291 .Case("ish", ARM_MB::ISH)
3292 .Case("shst", ARM_MB::ISHST)
3293 .Case("ishst", ARM_MB::ISHST)
3294 .Case("nsh", ARM_MB::NSH)
3295 .Case("un", ARM_MB::NSH)
3296 .Case("nshst", ARM_MB::NSHST)
3297 .Case("unst", ARM_MB::NSHST)
3298 .Case("osh", ARM_MB::OSH)
3299 .Case("oshst", ARM_MB::OSHST)
3300 .Default(~0U);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003301
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003302 if (Opt == ~0U)
3303 return MatchOperand_NoMatch;
3304
3305 Parser.Lex(); // Eat identifier token.
3306 } else if (Tok.is(AsmToken::Hash) ||
3307 Tok.is(AsmToken::Dollar) ||
3308 Tok.is(AsmToken::Integer)) {
3309 if (Parser.getTok().isNot(AsmToken::Integer))
3310 Parser.Lex(); // Eat the '#'.
3311 SMLoc Loc = Parser.getTok().getLoc();
3312
3313 const MCExpr *MemBarrierID;
3314 if (getParser().ParseExpression(MemBarrierID)) {
3315 Error(Loc, "illegal expression");
3316 return MatchOperand_ParseFail;
3317 }
3318
3319 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3320 if (!CE) {
3321 Error(Loc, "constant expression expected");
3322 return MatchOperand_ParseFail;
3323 }
3324
3325 int Val = CE->getValue();
3326 if (Val & ~0xf) {
3327 Error(Loc, "immediate value out of range");
3328 return MatchOperand_ParseFail;
3329 }
3330
3331 Opt = ARM_MB::RESERVED_0 + Val;
3332 } else
3333 return MatchOperand_ParseFail;
3334
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003335 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00003336 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003337}
3338
Jim Grosbach43904292011-07-25 20:14:50 +00003339/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003340ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003341parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003342 SMLoc S = Parser.getTok().getLoc();
3343 const AsmToken &Tok = Parser.getTok();
Richard Bartona1c73672012-06-14 10:48:04 +00003344 if (!Tok.is(AsmToken::Identifier))
3345 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003346 StringRef IFlagsStr = Tok.getString();
3347
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003348 // An iflags string of "none" is interpreted to mean that none of the AIF
3349 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003350 unsigned IFlags = 0;
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003351 if (IFlagsStr != "none") {
3352 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3353 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3354 .Case("a", ARM_PROC::A)
3355 .Case("i", ARM_PROC::I)
3356 .Case("f", ARM_PROC::F)
3357 .Default(~0U);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003358
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003359 // If some specific iflag is already set, it means that some letter is
3360 // present more than once, this is not acceptable.
3361 if (Flag == ~0U || (IFlags & Flag))
3362 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003363
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003364 IFlags |= Flag;
3365 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003366 }
3367
3368 Parser.Lex(); // Eat identifier token.
3369 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3370 return MatchOperand_Success;
3371}
3372
Jim Grosbach43904292011-07-25 20:14:50 +00003373/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003374ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003375parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003376 SMLoc S = Parser.getTok().getLoc();
3377 const AsmToken &Tok = Parser.getTok();
3378 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3379 StringRef Mask = Tok.getString();
3380
James Molloyacad68d2011-09-28 14:21:38 +00003381 if (isMClass()) {
3382 // See ARMv6-M 10.1.1
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00003383 std::string Name = Mask.lower();
3384 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderby0fd4f3c2012-05-17 22:18:01 +00003385 // Note: in the documentation:
3386 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3387 // for MSR APSR_nzcvq.
3388 // but we do make it an alias here. This is so to get the "mask encoding"
3389 // bits correct on MSR APSR writes.
3390 //
3391 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3392 // should really only be allowed when writing a special register. Note
3393 // they get dropped in the MRS instruction reading a special register as
3394 // the SYSm field is only 8 bits.
3395 //
3396 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3397 // includes the DSP extension but that is not checked.
3398 .Case("apsr", 0x800)
3399 .Case("apsr_nzcvq", 0x800)
3400 .Case("apsr_g", 0x400)
3401 .Case("apsr_nzcvqg", 0xc00)
3402 .Case("iapsr", 0x801)
3403 .Case("iapsr_nzcvq", 0x801)
3404 .Case("iapsr_g", 0x401)
3405 .Case("iapsr_nzcvqg", 0xc01)
3406 .Case("eapsr", 0x802)
3407 .Case("eapsr_nzcvq", 0x802)
3408 .Case("eapsr_g", 0x402)
3409 .Case("eapsr_nzcvqg", 0xc02)
3410 .Case("xpsr", 0x803)
3411 .Case("xpsr_nzcvq", 0x803)
3412 .Case("xpsr_g", 0x403)
3413 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderbyf49a4092012-06-15 22:14:44 +00003414 .Case("ipsr", 0x805)
3415 .Case("epsr", 0x806)
3416 .Case("iepsr", 0x807)
3417 .Case("msp", 0x808)
3418 .Case("psp", 0x809)
3419 .Case("primask", 0x810)
3420 .Case("basepri", 0x811)
3421 .Case("basepri_max", 0x812)
3422 .Case("faultmask", 0x813)
3423 .Case("control", 0x814)
James Molloyacad68d2011-09-28 14:21:38 +00003424 .Default(~0U);
Jim Grosbach18c8d122011-12-22 17:17:10 +00003425
James Molloyacad68d2011-09-28 14:21:38 +00003426 if (FlagsVal == ~0U)
3427 return MatchOperand_NoMatch;
3428
Kevin Enderbyf49a4092012-06-15 22:14:44 +00003429 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloyacad68d2011-09-28 14:21:38 +00003430 // basepri, basepri_max and faultmask only valid for V7m.
3431 return MatchOperand_NoMatch;
Jim Grosbach18c8d122011-12-22 17:17:10 +00003432
James Molloyacad68d2011-09-28 14:21:38 +00003433 Parser.Lex(); // Eat identifier token.
3434 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3435 return MatchOperand_Success;
3436 }
3437
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003438 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3439 size_t Start = 0, Next = Mask.find('_');
3440 StringRef Flags = "";
Benjamin Kramer59085362011-11-06 20:37:06 +00003441 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003442 if (Next != StringRef::npos)
3443 Flags = Mask.slice(Next+1, Mask.size());
3444
3445 // FlagsVal contains the complete mask:
3446 // 3-0: Mask
3447 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3448 unsigned FlagsVal = 0;
3449
3450 if (SpecReg == "apsr") {
3451 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +00003452 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003453 .Case("g", 0x4) // same as CPSR_s
3454 .Case("nzcvqg", 0xc) // same as CPSR_fs
3455 .Default(~0U);
3456
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003457 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003458 if (!Flags.empty())
3459 return MatchOperand_NoMatch;
3460 else
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003461 FlagsVal = 8; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003462 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003463 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbachb657a902012-04-05 03:17:53 +00003464 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3465 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00003466 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003467 for (int i = 0, e = Flags.size(); i != e; ++i) {
3468 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3469 .Case("c", 1)
3470 .Case("x", 2)
3471 .Case("s", 4)
3472 .Case("f", 8)
3473 .Default(~0U);
3474
3475 // If some specific flag is already set, it means that some letter is
3476 // present more than once, this is not acceptable.
3477 if (FlagsVal == ~0U || (FlagsVal & Flag))
3478 return MatchOperand_NoMatch;
3479 FlagsVal |= Flag;
3480 }
3481 } else // No match for special register.
3482 return MatchOperand_NoMatch;
3483
Owen Anderson7784f1d2011-10-21 18:43:28 +00003484 // Special register without flags is NOT equivalent to "fc" flags.
3485 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3486 // two lines would enable gas compatibility at the expense of breaking
3487 // round-tripping.
3488 //
3489 // if (!FlagsVal)
3490 // FlagsVal = 0x9;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003491
3492 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3493 if (SpecReg == "spsr")
3494 FlagsVal |= 16;
3495
3496 Parser.Lex(); // Eat identifier token.
3497 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3498 return MatchOperand_Success;
3499}
3500
Jim Grosbachf6c05252011-07-21 17:23:04 +00003501ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3502parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3503 int Low, int High) {
3504 const AsmToken &Tok = Parser.getTok();
3505 if (Tok.isNot(AsmToken::Identifier)) {
3506 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3507 return MatchOperand_ParseFail;
3508 }
3509 StringRef ShiftName = Tok.getString();
Benjamin Kramer59085362011-11-06 20:37:06 +00003510 std::string LowerOp = Op.lower();
3511 std::string UpperOp = Op.upper();
Jim Grosbachf6c05252011-07-21 17:23:04 +00003512 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3513 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3514 return MatchOperand_ParseFail;
3515 }
3516 Parser.Lex(); // Eat shift type token.
3517
3518 // There must be a '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003519 if (Parser.getTok().isNot(AsmToken::Hash) &&
3520 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbachf6c05252011-07-21 17:23:04 +00003521 Error(Parser.getTok().getLoc(), "'#' expected");
3522 return MatchOperand_ParseFail;
3523 }
3524 Parser.Lex(); // Eat hash token.
3525
3526 const MCExpr *ShiftAmount;
3527 SMLoc Loc = Parser.getTok().getLoc();
3528 if (getParser().ParseExpression(ShiftAmount)) {
3529 Error(Loc, "illegal expression");
3530 return MatchOperand_ParseFail;
3531 }
3532 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3533 if (!CE) {
3534 Error(Loc, "constant expression expected");
3535 return MatchOperand_ParseFail;
3536 }
3537 int Val = CE->getValue();
3538 if (Val < Low || Val > High) {
3539 Error(Loc, "immediate value out of range");
3540 return MatchOperand_ParseFail;
3541 }
3542
3543 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3544
3545 return MatchOperand_Success;
3546}
3547
Jim Grosbachc27d4f92011-07-22 17:44:50 +00003548ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3549parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3550 const AsmToken &Tok = Parser.getTok();
3551 SMLoc S = Tok.getLoc();
3552 if (Tok.isNot(AsmToken::Identifier)) {
3553 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3554 return MatchOperand_ParseFail;
3555 }
3556 int Val = StringSwitch<int>(Tok.getString())
3557 .Case("be", 1)
3558 .Case("le", 0)
3559 .Default(-1);
3560 Parser.Lex(); // Eat the token.
3561
3562 if (Val == -1) {
3563 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3564 return MatchOperand_ParseFail;
3565 }
3566 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3567 getContext()),
3568 S, Parser.getTok().getLoc()));
3569 return MatchOperand_Success;
3570}
3571
Jim Grosbach580f4a92011-07-25 22:20:28 +00003572/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3573/// instructions. Legal values are:
3574/// lsl #n 'n' in [0,31]
3575/// asr #n 'n' in [1,32]
3576/// n == 32 encoded as n == 0.
3577ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3578parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3579 const AsmToken &Tok = Parser.getTok();
3580 SMLoc S = Tok.getLoc();
3581 if (Tok.isNot(AsmToken::Identifier)) {
3582 Error(S, "shift operator 'asr' or 'lsl' expected");
3583 return MatchOperand_ParseFail;
3584 }
3585 StringRef ShiftName = Tok.getString();
3586 bool isASR;
3587 if (ShiftName == "lsl" || ShiftName == "LSL")
3588 isASR = false;
3589 else if (ShiftName == "asr" || ShiftName == "ASR")
3590 isASR = true;
3591 else {
3592 Error(S, "shift operator 'asr' or 'lsl' expected");
3593 return MatchOperand_ParseFail;
3594 }
3595 Parser.Lex(); // Eat the operator.
3596
3597 // A '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003598 if (Parser.getTok().isNot(AsmToken::Hash) &&
3599 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach580f4a92011-07-25 22:20:28 +00003600 Error(Parser.getTok().getLoc(), "'#' expected");
3601 return MatchOperand_ParseFail;
3602 }
3603 Parser.Lex(); // Eat hash token.
3604
3605 const MCExpr *ShiftAmount;
3606 SMLoc E = Parser.getTok().getLoc();
3607 if (getParser().ParseExpression(ShiftAmount)) {
3608 Error(E, "malformed shift expression");
3609 return MatchOperand_ParseFail;
3610 }
3611 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3612 if (!CE) {
3613 Error(E, "shift amount must be an immediate");
3614 return MatchOperand_ParseFail;
3615 }
3616
3617 int64_t Val = CE->getValue();
3618 if (isASR) {
3619 // Shift amount must be in [1,32]
3620 if (Val < 1 || Val > 32) {
3621 Error(E, "'asr' shift amount must be in range [1,32]");
3622 return MatchOperand_ParseFail;
3623 }
Owen Anderson0afa0092011-09-26 21:06:22 +00003624 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3625 if (isThumb() && Val == 32) {
3626 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3627 return MatchOperand_ParseFail;
3628 }
Jim Grosbach580f4a92011-07-25 22:20:28 +00003629 if (Val == 32) Val = 0;
3630 } else {
3631 // Shift amount must be in [1,32]
3632 if (Val < 0 || Val > 31) {
3633 Error(E, "'lsr' shift amount must be in range [0,31]");
3634 return MatchOperand_ParseFail;
3635 }
3636 }
3637
3638 E = Parser.getTok().getLoc();
3639 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3640
3641 return MatchOperand_Success;
3642}
3643
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003644/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3645/// of instructions. Legal values are:
3646/// ror #n 'n' in {0, 8, 16, 24}
3647ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3648parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3649 const AsmToken &Tok = Parser.getTok();
3650 SMLoc S = Tok.getLoc();
Jim Grosbach326efe52011-09-19 20:29:33 +00003651 if (Tok.isNot(AsmToken::Identifier))
3652 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003653 StringRef ShiftName = Tok.getString();
Jim Grosbach326efe52011-09-19 20:29:33 +00003654 if (ShiftName != "ror" && ShiftName != "ROR")
3655 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003656 Parser.Lex(); // Eat the operator.
3657
3658 // A '#' and a rotate amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003659 if (Parser.getTok().isNot(AsmToken::Hash) &&
3660 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003661 Error(Parser.getTok().getLoc(), "'#' expected");
3662 return MatchOperand_ParseFail;
3663 }
3664 Parser.Lex(); // Eat hash token.
3665
3666 const MCExpr *ShiftAmount;
3667 SMLoc E = Parser.getTok().getLoc();
3668 if (getParser().ParseExpression(ShiftAmount)) {
3669 Error(E, "malformed rotate expression");
3670 return MatchOperand_ParseFail;
3671 }
3672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3673 if (!CE) {
3674 Error(E, "rotate amount must be an immediate");
3675 return MatchOperand_ParseFail;
3676 }
3677
3678 int64_t Val = CE->getValue();
3679 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3680 // normally, zero is represented in asm by omitting the rotate operand
3681 // entirely.
3682 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3683 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3684 return MatchOperand_ParseFail;
3685 }
3686
3687 E = Parser.getTok().getLoc();
3688 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3689
3690 return MatchOperand_Success;
3691}
3692
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003693ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3694parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3695 SMLoc S = Parser.getTok().getLoc();
3696 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003697 if (Parser.getTok().isNot(AsmToken::Hash) &&
3698 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003699 Error(Parser.getTok().getLoc(), "'#' expected");
3700 return MatchOperand_ParseFail;
3701 }
3702 Parser.Lex(); // Eat hash token.
3703
3704 const MCExpr *LSBExpr;
3705 SMLoc E = Parser.getTok().getLoc();
3706 if (getParser().ParseExpression(LSBExpr)) {
3707 Error(E, "malformed immediate expression");
3708 return MatchOperand_ParseFail;
3709 }
3710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3711 if (!CE) {
3712 Error(E, "'lsb' operand must be an immediate");
3713 return MatchOperand_ParseFail;
3714 }
3715
3716 int64_t LSB = CE->getValue();
3717 // The LSB must be in the range [0,31]
3718 if (LSB < 0 || LSB > 31) {
3719 Error(E, "'lsb' operand must be in the range [0,31]");
3720 return MatchOperand_ParseFail;
3721 }
3722 E = Parser.getTok().getLoc();
3723
3724 // Expect another immediate operand.
3725 if (Parser.getTok().isNot(AsmToken::Comma)) {
3726 Error(Parser.getTok().getLoc(), "too few operands");
3727 return MatchOperand_ParseFail;
3728 }
3729 Parser.Lex(); // Eat hash token.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003730 if (Parser.getTok().isNot(AsmToken::Hash) &&
3731 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003732 Error(Parser.getTok().getLoc(), "'#' expected");
3733 return MatchOperand_ParseFail;
3734 }
3735 Parser.Lex(); // Eat hash token.
3736
3737 const MCExpr *WidthExpr;
3738 if (getParser().ParseExpression(WidthExpr)) {
3739 Error(E, "malformed immediate expression");
3740 return MatchOperand_ParseFail;
3741 }
3742 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3743 if (!CE) {
3744 Error(E, "'width' operand must be an immediate");
3745 return MatchOperand_ParseFail;
3746 }
3747
3748 int64_t Width = CE->getValue();
3749 // The LSB must be in the range [1,32-lsb]
3750 if (Width < 1 || Width > 32 - LSB) {
3751 Error(E, "'width' operand must be in the range [1,32-lsb]");
3752 return MatchOperand_ParseFail;
3753 }
3754 E = Parser.getTok().getLoc();
3755
3756 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3757
3758 return MatchOperand_Success;
3759}
3760
Jim Grosbach7ce05792011-08-03 23:50:40 +00003761ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3762parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3763 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003764 // postidx_reg := '+' register {, shift}
3765 // | '-' register {, shift}
3766 // | register {, shift}
Jim Grosbach7ce05792011-08-03 23:50:40 +00003767
3768 // This method must return MatchOperand_NoMatch without consuming any tokens
3769 // in the case where there is no match, as other alternatives take other
3770 // parse methods.
3771 AsmToken Tok = Parser.getTok();
3772 SMLoc S = Tok.getLoc();
3773 bool haveEaten = false;
Jim Grosbach16578b52011-08-05 16:11:38 +00003774 bool isAdd = true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003775 int Reg = -1;
3776 if (Tok.is(AsmToken::Plus)) {
3777 Parser.Lex(); // Eat the '+' token.
3778 haveEaten = true;
3779 } else if (Tok.is(AsmToken::Minus)) {
3780 Parser.Lex(); // Eat the '-' token.
Jim Grosbach16578b52011-08-05 16:11:38 +00003781 isAdd = false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003782 haveEaten = true;
3783 }
3784 if (Parser.getTok().is(AsmToken::Identifier))
3785 Reg = tryParseRegister();
3786 if (Reg == -1) {
3787 if (!haveEaten)
3788 return MatchOperand_NoMatch;
3789 Error(Parser.getTok().getLoc(), "register expected");
3790 return MatchOperand_ParseFail;
3791 }
3792 SMLoc E = Parser.getTok().getLoc();
3793
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003794 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3795 unsigned ShiftImm = 0;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00003796 if (Parser.getTok().is(AsmToken::Comma)) {
3797 Parser.Lex(); // Eat the ','.
3798 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3799 return MatchOperand_ParseFail;
3800 }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003801
3802 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3803 ShiftImm, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003804
3805 return MatchOperand_Success;
3806}
3807
Jim Grosbach251bf252011-08-10 21:56:18 +00003808ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3809parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3810 // Check for a post-index addressing register operand. Specifically:
3811 // am3offset := '+' register
3812 // | '-' register
3813 // | register
3814 // | # imm
3815 // | # + imm
3816 // | # - imm
3817
3818 // This method must return MatchOperand_NoMatch without consuming any tokens
3819 // in the case where there is no match, as other alternatives take other
3820 // parse methods.
3821 AsmToken Tok = Parser.getTok();
3822 SMLoc S = Tok.getLoc();
3823
3824 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003825 if (Parser.getTok().is(AsmToken::Hash) ||
3826 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach251bf252011-08-10 21:56:18 +00003827 Parser.Lex(); // Eat the '#'.
3828 // Explicitly look for a '-', as we need to encode negative zero
3829 // differently.
3830 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3831 const MCExpr *Offset;
3832 if (getParser().ParseExpression(Offset))
3833 return MatchOperand_ParseFail;
3834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3835 if (!CE) {
3836 Error(S, "constant expression expected");
3837 return MatchOperand_ParseFail;
3838 }
3839 SMLoc E = Tok.getLoc();
3840 // Negative zero is encoded as the flag value INT32_MIN.
3841 int32_t Val = CE->getValue();
3842 if (isNegative && Val == 0)
3843 Val = INT32_MIN;
3844
3845 Operands.push_back(
3846 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3847
3848 return MatchOperand_Success;
3849 }
3850
3851
3852 bool haveEaten = false;
3853 bool isAdd = true;
3854 int Reg = -1;
3855 if (Tok.is(AsmToken::Plus)) {
3856 Parser.Lex(); // Eat the '+' token.
3857 haveEaten = true;
3858 } else if (Tok.is(AsmToken::Minus)) {
3859 Parser.Lex(); // Eat the '-' token.
3860 isAdd = false;
3861 haveEaten = true;
3862 }
3863 if (Parser.getTok().is(AsmToken::Identifier))
3864 Reg = tryParseRegister();
3865 if (Reg == -1) {
3866 if (!haveEaten)
3867 return MatchOperand_NoMatch;
3868 Error(Parser.getTok().getLoc(), "register expected");
3869 return MatchOperand_ParseFail;
3870 }
3871 SMLoc E = Parser.getTok().getLoc();
3872
3873 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3874 0, S, E));
3875
3876 return MatchOperand_Success;
3877}
3878
Jim Grosbacha77295d2011-09-08 22:07:06 +00003879/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3880/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3881/// when they refer multiple MIOperands inside a single one.
3882bool ARMAsmParser::
3883cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
3884 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3885 // Rt, Rt2
3886 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3887 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3888 // Create a writeback register dummy placeholder.
3889 Inst.addOperand(MCOperand::CreateReg(0));
3890 // addr
3891 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3892 // pred
3893 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3894 return true;
3895}
3896
3897/// cvtT2StrdPre - Convert parsed operands to MCInst.
3898/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3899/// when they refer multiple MIOperands inside a single one.
3900bool ARMAsmParser::
3901cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
3902 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3903 // Create a writeback register dummy placeholder.
3904 Inst.addOperand(MCOperand::CreateReg(0));
3905 // Rt, Rt2
3906 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3907 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3908 // addr
3909 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3910 // pred
3911 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3912 return true;
3913}
3914
Jim Grosbacheeec0252011-09-08 00:39:19 +00003915/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3916/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3917/// when they refer multiple MIOperands inside a single one.
3918bool ARMAsmParser::
3919cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3920 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3921 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3922
3923 // Create a writeback register dummy placeholder.
3924 Inst.addOperand(MCOperand::CreateImm(0));
3925
3926 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3927 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3928 return true;
3929}
3930
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003931/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3932/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3933/// when they refer multiple MIOperands inside a single one.
3934bool ARMAsmParser::
3935cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3936 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3937 // Create a writeback register dummy placeholder.
3938 Inst.addOperand(MCOperand::CreateImm(0));
3939 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3940 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3941 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3942 return true;
3943}
3944
Jim Grosbach1355cf12011-07-26 17:10:22 +00003945/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003946/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3947/// when they refer multiple MIOperands inside a single one.
3948bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003949cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003950 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3951 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3952
3953 // Create a writeback register dummy placeholder.
3954 Inst.addOperand(MCOperand::CreateImm(0));
3955
Jim Grosbach7ce05792011-08-03 23:50:40 +00003956 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003957 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3958 return true;
3959}
3960
Owen Anderson9ab0f252011-08-26 20:43:14 +00003961/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3962/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3963/// when they refer multiple MIOperands inside a single one.
3964bool ARMAsmParser::
3965cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3966 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3967 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3968
3969 // Create a writeback register dummy placeholder.
3970 Inst.addOperand(MCOperand::CreateImm(0));
3971
3972 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3973 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3974 return true;
3975}
3976
3977
Jim Grosbach548340c2011-08-11 19:22:40 +00003978/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3979/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3980/// when they refer multiple MIOperands inside a single one.
3981bool ARMAsmParser::
3982cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3983 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3984 // Create a writeback register dummy placeholder.
3985 Inst.addOperand(MCOperand::CreateImm(0));
3986 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3987 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3988 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3989 return true;
3990}
3991
Jim Grosbach1355cf12011-07-26 17:10:22 +00003992/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003993/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3994/// when they refer multiple MIOperands inside a single one.
3995bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003996cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003997 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3998 // Create a writeback register dummy placeholder.
3999 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach548340c2011-08-11 19:22:40 +00004000 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4001 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4002 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004003 return true;
4004}
4005
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00004006/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4007/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4008/// when they refer multiple MIOperands inside a single one.
4009bool ARMAsmParser::
4010cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
4011 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4012 // Create a writeback register dummy placeholder.
4013 Inst.addOperand(MCOperand::CreateImm(0));
4014 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4015 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4016 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4017 return true;
4018}
4019
Jim Grosbach7ce05792011-08-03 23:50:40 +00004020/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4021/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4022/// when they refer multiple MIOperands inside a single one.
4023bool ARMAsmParser::
4024cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
4025 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4026 // Rt
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004027 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004028 // Create a writeback register dummy placeholder.
4029 Inst.addOperand(MCOperand::CreateImm(0));
4030 // addr
4031 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4032 // offset
4033 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4034 // pred
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004035 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4036 return true;
4037}
4038
Jim Grosbach7ce05792011-08-03 23:50:40 +00004039/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004040/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4041/// when they refer multiple MIOperands inside a single one.
4042bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004043cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
4044 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4045 // Rt
Owen Andersonaa3402e2011-07-28 17:18:57 +00004046 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004047 // Create a writeback register dummy placeholder.
4048 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004049 // addr
4050 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4051 // offset
4052 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4053 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004054 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4055 return true;
4056}
4057
Jim Grosbach7ce05792011-08-03 23:50:40 +00004058/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004059/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4060/// when they refer multiple MIOperands inside a single one.
4061bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004062cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
4063 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004064 // Create a writeback register dummy placeholder.
4065 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004066 // Rt
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004067 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004068 // addr
4069 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4070 // offset
4071 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4072 // pred
4073 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4074 return true;
4075}
4076
4077/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4078/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4079/// when they refer multiple MIOperands inside a single one.
4080bool ARMAsmParser::
4081cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
4082 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4083 // Create a writeback register dummy placeholder.
4084 Inst.addOperand(MCOperand::CreateImm(0));
4085 // Rt
4086 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4087 // addr
4088 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4089 // offset
4090 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4091 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004092 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4093 return true;
4094}
4095
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004096/// cvtLdrdPre - Convert parsed operands to MCInst.
4097/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4098/// when they refer multiple MIOperands inside a single one.
4099bool ARMAsmParser::
4100cvtLdrdPre(MCInst &Inst, unsigned Opcode,
4101 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4102 // Rt, Rt2
4103 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4104 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4105 // Create a writeback register dummy placeholder.
4106 Inst.addOperand(MCOperand::CreateImm(0));
4107 // addr
4108 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4109 // pred
4110 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4111 return true;
4112}
4113
Jim Grosbach14605d12011-08-11 20:28:23 +00004114/// cvtStrdPre - Convert parsed operands to MCInst.
4115/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4116/// when they refer multiple MIOperands inside a single one.
4117bool ARMAsmParser::
4118cvtStrdPre(MCInst &Inst, unsigned Opcode,
4119 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4120 // Create a writeback register dummy placeholder.
4121 Inst.addOperand(MCOperand::CreateImm(0));
4122 // Rt, Rt2
4123 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4124 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4125 // addr
4126 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4127 // pred
4128 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4129 return true;
4130}
4131
Jim Grosbach623a4542011-08-10 22:42:16 +00004132/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4133/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4134/// when they refer multiple MIOperands inside a single one.
4135bool ARMAsmParser::
4136cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
4137 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4138 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4139 // Create a writeback register dummy placeholder.
4140 Inst.addOperand(MCOperand::CreateImm(0));
4141 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4142 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4143 return true;
4144}
4145
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004146/// cvtThumbMultiple- Convert parsed operands to MCInst.
4147/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4148/// when they refer multiple MIOperands inside a single one.
4149bool ARMAsmParser::
4150cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
4151 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4152 // The second source operand must be the same register as the destination
4153 // operand.
4154 if (Operands.size() == 6 &&
Jim Grosbach7a010692011-08-19 22:30:46 +00004155 (((ARMOperand*)Operands[3])->getReg() !=
4156 ((ARMOperand*)Operands[5])->getReg()) &&
4157 (((ARMOperand*)Operands[3])->getReg() !=
4158 ((ARMOperand*)Operands[4])->getReg())) {
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004159 Error(Operands[3]->getStartLoc(),
Jim Grosbach7a010692011-08-19 22:30:46 +00004160 "destination register must match source register");
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004161 return false;
4162 }
4163 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4164 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach1b332862011-11-10 22:10:12 +00004165 // If we have a three-operand form, make sure to set Rn to be the operand
4166 // that isn't the same as Rd.
4167 unsigned RegOp = 4;
4168 if (Operands.size() == 6 &&
4169 ((ARMOperand*)Operands[4])->getReg() ==
4170 ((ARMOperand*)Operands[3])->getReg())
4171 RegOp = 5;
4172 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4173 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004174 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4175
4176 return true;
4177}
Jim Grosbach623a4542011-08-10 22:42:16 +00004178
Jim Grosbach12431322011-10-24 22:16:58 +00004179bool ARMAsmParser::
4180cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
4181 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4182 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004183 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004184 // Create a writeback register dummy placeholder.
4185 Inst.addOperand(MCOperand::CreateImm(0));
4186 // Vn
4187 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4188 // pred
4189 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4190 return true;
4191}
4192
4193bool ARMAsmParser::
4194cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
4195 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4196 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004197 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004198 // Create a writeback register dummy placeholder.
4199 Inst.addOperand(MCOperand::CreateImm(0));
4200 // Vn
4201 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4202 // Vm
4203 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4204 // pred
4205 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4206 return true;
4207}
4208
Jim Grosbach4334e032011-10-31 21:50:31 +00004209bool ARMAsmParser::
4210cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
4211 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4212 // Create a writeback register dummy placeholder.
4213 Inst.addOperand(MCOperand::CreateImm(0));
4214 // Vn
4215 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4216 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004217 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004218 // pred
4219 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4220 return true;
4221}
4222
4223bool ARMAsmParser::
4224cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
4225 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4226 // Create a writeback register dummy placeholder.
4227 Inst.addOperand(MCOperand::CreateImm(0));
4228 // Vn
4229 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4230 // Vm
4231 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4232 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004233 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004234 // pred
4235 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4236 return true;
4237}
4238
Bill Wendlinge7176102010-11-06 22:36:58 +00004239/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004240/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00004241bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004242parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +00004243 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00004244 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00004245 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00004246 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004247 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004248
Sean Callanan18b83232010-01-19 21:44:56 +00004249 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbach1355cf12011-07-26 17:10:22 +00004250 int BaseRegNum = tryParseRegister();
Jim Grosbach7ce05792011-08-03 23:50:40 +00004251 if (BaseRegNum == -1)
4252 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004253
Daniel Dunbar05710932011-01-18 05:34:17 +00004254 // The next token must either be a comma or a closing bracket.
4255 const AsmToken &Tok = Parser.getTok();
4256 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004257 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar05710932011-01-18 05:34:17 +00004258
Jim Grosbach7ce05792011-08-03 23:50:40 +00004259 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan76264762010-04-02 22:27:05 +00004260 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004261 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004262
Jim Grosbach7ce05792011-08-03 23:50:40 +00004263 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004264 0, 0, false, S, E));
Jim Grosbach03f44a02010-11-29 23:18:01 +00004265
Jim Grosbachfb12f352011-09-19 18:42:21 +00004266 // If there's a pre-indexing writeback marker, '!', just add it as a token
4267 // operand. It's rather odd, but syntactically valid.
4268 if (Parser.getTok().is(AsmToken::Exclaim)) {
4269 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4270 Parser.Lex(); // Eat the '!'.
4271 }
4272
Jim Grosbach7ce05792011-08-03 23:50:40 +00004273 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004274 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004275
Jim Grosbach7ce05792011-08-03 23:50:40 +00004276 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4277 Parser.Lex(); // Eat the comma.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004278
Jim Grosbach57dcb852011-10-11 17:29:55 +00004279 // If we have a ':', it's an alignment specifier.
4280 if (Parser.getTok().is(AsmToken::Colon)) {
4281 Parser.Lex(); // Eat the ':'.
4282 E = Parser.getTok().getLoc();
4283
4284 const MCExpr *Expr;
4285 if (getParser().ParseExpression(Expr))
4286 return true;
4287
4288 // The expression has to be a constant. Memory references with relocations
4289 // don't come through here, as they use the <label> forms of the relevant
4290 // instructions.
4291 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4292 if (!CE)
4293 return Error (E, "constant expression expected");
4294
4295 unsigned Align = 0;
4296 switch (CE->getValue()) {
4297 default:
Jim Grosbacheeaf1c12011-12-19 18:31:43 +00004298 return Error(E,
4299 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4300 case 16: Align = 2; break;
4301 case 32: Align = 4; break;
Jim Grosbach57dcb852011-10-11 17:29:55 +00004302 case 64: Align = 8; break;
4303 case 128: Align = 16; break;
4304 case 256: Align = 32; break;
4305 }
4306
4307 // Now we should have the closing ']'
4308 E = Parser.getTok().getLoc();
4309 if (Parser.getTok().isNot(AsmToken::RBrac))
4310 return Error(E, "']' expected");
4311 Parser.Lex(); // Eat right bracket token.
4312
4313 // Don't worry about range checking the value here. That's handled by
4314 // the is*() predicates.
4315 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4316 ARM_AM::no_shift, 0, Align,
4317 false, S, E));
4318
4319 // If there's a pre-indexing writeback marker, '!', just add it as a token
4320 // operand.
4321 if (Parser.getTok().is(AsmToken::Exclaim)) {
4322 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4323 Parser.Lex(); // Eat the '!'.
4324 }
4325
4326 return false;
4327 }
4328
4329 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004330 // offset. Be friendly and also accept a plain integer (without a leading
4331 // hash) for gas compatibility.
4332 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004333 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004334 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004335 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004336 Parser.Lex(); // Eat the '#'.
Jim Grosbach7ce05792011-08-03 23:50:40 +00004337 E = Parser.getTok().getLoc();
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004338
Owen Anderson0da10cf2011-08-29 19:36:44 +00004339 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004340 const MCExpr *Offset;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004341 if (getParser().ParseExpression(Offset))
4342 return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004343
4344 // The expression has to be a constant. Memory references with relocations
4345 // don't come through here, as they use the <label> forms of the relevant
4346 // instructions.
4347 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4348 if (!CE)
4349 return Error (E, "constant expression expected");
4350
Owen Anderson0da10cf2011-08-29 19:36:44 +00004351 // If the constant was #-0, represent it as INT32_MIN.
4352 int32_t Val = CE->getValue();
4353 if (isNegative && Val == 0)
4354 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4355
Jim Grosbach7ce05792011-08-03 23:50:40 +00004356 // Now we should have the closing ']'
4357 E = Parser.getTok().getLoc();
4358 if (Parser.getTok().isNot(AsmToken::RBrac))
4359 return Error(E, "']' expected");
4360 Parser.Lex(); // Eat right bracket token.
4361
4362 // Don't worry about range checking the value here. That's handled by
4363 // the is*() predicates.
4364 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004365 ARM_AM::no_shift, 0, 0,
4366 false, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004367
4368 // If there's a pre-indexing writeback marker, '!', just add it as a token
4369 // operand.
4370 if (Parser.getTok().is(AsmToken::Exclaim)) {
4371 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4372 Parser.Lex(); // Eat the '!'.
4373 }
4374
4375 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004376 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004377
4378 // The register offset is optionally preceded by a '+' or '-'
4379 bool isNegative = false;
4380 if (Parser.getTok().is(AsmToken::Minus)) {
4381 isNegative = true;
4382 Parser.Lex(); // Eat the '-'.
4383 } else if (Parser.getTok().is(AsmToken::Plus)) {
4384 // Nothing to do.
4385 Parser.Lex(); // Eat the '+'.
4386 }
4387
4388 E = Parser.getTok().getLoc();
4389 int OffsetRegNum = tryParseRegister();
4390 if (OffsetRegNum == -1)
4391 return Error(E, "register expected");
4392
4393 // If there's a shift operator, handle it.
4394 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004395 unsigned ShiftImm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004396 if (Parser.getTok().is(AsmToken::Comma)) {
4397 Parser.Lex(); // Eat the ','.
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004398 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004399 return true;
4400 }
4401
4402 // Now we should have the closing ']'
4403 E = Parser.getTok().getLoc();
4404 if (Parser.getTok().isNot(AsmToken::RBrac))
4405 return Error(E, "']' expected");
4406 Parser.Lex(); // Eat right bracket token.
4407
4408 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004409 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004410 S, E));
4411
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00004412 // If there's a pre-indexing writeback marker, '!', just add it as a token
4413 // operand.
4414 if (Parser.getTok().is(AsmToken::Exclaim)) {
4415 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4416 Parser.Lex(); // Eat the '!'.
4417 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004418
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004419 return false;
4420}
4421
Jim Grosbach7ce05792011-08-03 23:50:40 +00004422/// parseMemRegOffsetShift - one of these two:
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004423/// ( lsl | lsr | asr | ror ) , # shift_amount
4424/// rrx
Jim Grosbach7ce05792011-08-03 23:50:40 +00004425/// return true if it parses a shift otherwise it returns false.
4426bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4427 unsigned &Amount) {
4428 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan18b83232010-01-19 21:44:56 +00004429 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004430 if (Tok.isNot(AsmToken::Identifier))
4431 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00004432 StringRef ShiftName = Tok.getString();
Jim Grosbachaf4edea2011-12-07 23:40:58 +00004433 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4434 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson00828302011-03-18 22:50:18 +00004435 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004436 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00004437 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004438 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00004439 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004440 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00004441 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004442 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00004443 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004444 else
Jim Grosbach7ce05792011-08-03 23:50:40 +00004445 return Error(Loc, "illegal shift operator");
Sean Callananb9a25b72010-01-19 20:27:46 +00004446 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004447
Jim Grosbach7ce05792011-08-03 23:50:40 +00004448 // rrx stands alone.
4449 Amount = 0;
4450 if (St != ARM_AM::rrx) {
4451 Loc = Parser.getTok().getLoc();
4452 // A '#' and a shift amount.
4453 const AsmToken &HashTok = Parser.getTok();
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004454 if (HashTok.isNot(AsmToken::Hash) &&
4455 HashTok.isNot(AsmToken::Dollar))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004456 return Error(HashTok.getLoc(), "'#' expected");
4457 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004458
Jim Grosbach7ce05792011-08-03 23:50:40 +00004459 const MCExpr *Expr;
4460 if (getParser().ParseExpression(Expr))
4461 return true;
4462 // Range check the immediate.
4463 // lsl, ror: 0 <= imm <= 31
4464 // lsr, asr: 0 <= imm <= 32
4465 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4466 if (!CE)
4467 return Error(Loc, "shift amount must be an immediate");
4468 int64_t Imm = CE->getValue();
4469 if (Imm < 0 ||
4470 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4471 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4472 return Error(Loc, "immediate shift value out of range");
4473 Amount = Imm;
4474 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004475
4476 return false;
4477}
4478
Jim Grosbach9d390362011-10-03 23:38:36 +00004479/// parseFPImm - A floating point immediate expression operand.
4480ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4481parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004482 // Anything that can accept a floating point constant as an operand
4483 // needs to go through here, as the regular ParseExpression is
4484 // integer only.
4485 //
4486 // This routine still creates a generic Immediate operand, containing
4487 // a bitcast of the 64-bit floating point value. The various operands
4488 // that accept floats can check whether the value is valid for them
4489 // via the standard is*() predicates.
4490
Jim Grosbach9d390362011-10-03 23:38:36 +00004491 SMLoc S = Parser.getTok().getLoc();
4492
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004493 if (Parser.getTok().isNot(AsmToken::Hash) &&
4494 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbach9d390362011-10-03 23:38:36 +00004495 return MatchOperand_NoMatch;
Jim Grosbach0e387b22011-10-17 22:26:03 +00004496
4497 // Disambiguate the VMOV forms that can accept an FP immediate.
4498 // vmov.f32 <sreg>, #imm
4499 // vmov.f64 <dreg>, #imm
4500 // vmov.f32 <dreg>, #imm @ vector f32x2
4501 // vmov.f32 <qreg>, #imm @ vector f32x4
4502 //
4503 // There are also the NEON VMOV instructions which expect an
4504 // integer constant. Make sure we don't try to parse an FPImm
4505 // for these:
4506 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4507 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4508 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4509 TyOp->getToken() != ".f64"))
4510 return MatchOperand_NoMatch;
4511
Jim Grosbach9d390362011-10-03 23:38:36 +00004512 Parser.Lex(); // Eat the '#'.
4513
4514 // Handle negation, as that still comes through as a separate token.
4515 bool isNegative = false;
4516 if (Parser.getTok().is(AsmToken::Minus)) {
4517 isNegative = true;
4518 Parser.Lex();
4519 }
4520 const AsmToken &Tok = Parser.getTok();
Jim Grosbachae69f702012-01-19 02:47:30 +00004521 SMLoc Loc = Tok.getLoc();
Jim Grosbach9d390362011-10-03 23:38:36 +00004522 if (Tok.is(AsmToken::Real)) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004523 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbach9d390362011-10-03 23:38:36 +00004524 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4525 // If we had a '-' in front, toggle the sign bit.
Jim Grosbach51222d12012-01-20 18:09:51 +00004526 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbach9d390362011-10-03 23:38:36 +00004527 Parser.Lex(); // Eat the token.
Jim Grosbach51222d12012-01-20 18:09:51 +00004528 Operands.push_back(ARMOperand::CreateImm(
4529 MCConstantExpr::Create(IntVal, getContext()),
4530 S, Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004531 return MatchOperand_Success;
4532 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004533 // Also handle plain integers. Instructions which allow floating point
4534 // immediates also allow a raw encoded 8-bit value.
Jim Grosbach9d390362011-10-03 23:38:36 +00004535 if (Tok.is(AsmToken::Integer)) {
4536 int64_t Val = Tok.getIntVal();
4537 Parser.Lex(); // Eat the token.
4538 if (Val > 255 || Val < 0) {
Jim Grosbachae69f702012-01-19 02:47:30 +00004539 Error(Loc, "encoded floating point value out of range");
Jim Grosbach9d390362011-10-03 23:38:36 +00004540 return MatchOperand_ParseFail;
4541 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004542 double RealVal = ARM_AM::getFPImmFloat(Val);
4543 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4544 Operands.push_back(ARMOperand::CreateImm(
4545 MCConstantExpr::Create(Val, getContext()), S,
4546 Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004547 return MatchOperand_Success;
4548 }
4549
Jim Grosbachae69f702012-01-19 02:47:30 +00004550 Error(Loc, "invalid floating point immediate");
Jim Grosbach9d390362011-10-03 23:38:36 +00004551 return MatchOperand_ParseFail;
4552}
Jim Grosbach51222d12012-01-20 18:09:51 +00004553
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004554/// Parse a arm instruction operand. For now this parses the operand regardless
4555/// of the mnemonic.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004556bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004557 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00004558 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004559
4560 // Check if the current operand has a custom associated parser, if so, try to
4561 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00004562 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4563 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004564 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00004565 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4566 // there was a match, but an error occurred, in which case, just return that
4567 // the operand parsing failed.
4568 if (ResTy == MatchOperand_ParseFail)
4569 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004570
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004571 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00004572 default:
4573 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00004574 return true;
Jim Grosbach19906722011-07-13 18:49:30 +00004575 case AsmToken::Identifier: {
Jim Grosbach1355cf12011-07-26 17:10:22 +00004576 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling50d0f582010-11-18 23:43:05 +00004577 return false;
Jim Grosbach0d87ec22011-07-26 20:41:24 +00004578 int Res = tryParseShiftRegister(Operands);
Jim Grosbach19906722011-07-13 18:49:30 +00004579 if (Res == 0) // success
Owen Anderson00828302011-03-18 22:50:18 +00004580 return false;
Jim Grosbach19906722011-07-13 18:49:30 +00004581 else if (Res == -1) // irrecoverable error
4582 return true;
Jim Grosbach3cbe43f2011-12-20 22:26:38 +00004583 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004584 if (Mnemonic == "vmrs" &&
4585 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004586 S = Parser.getTok().getLoc();
4587 Parser.Lex();
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004588 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004589 return false;
4590 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00004591
4592 // Fall though for the Identifier case that is not a register or a
4593 // special name.
Jim Grosbach19906722011-07-13 18:49:30 +00004594 }
Jim Grosbach758a5192011-10-26 21:14:08 +00004595 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderby67b212e2011-01-13 20:32:36 +00004596 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach6284afc2011-11-01 22:38:31 +00004597 case AsmToken::String: // quoted label names.
Kevin Enderby67b212e2011-01-13 20:32:36 +00004598 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00004599 // This was not a register so parse other operands that start with an
4600 // identifier (like labels) as expressions and create them as immediates.
4601 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00004602 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00004603 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004604 return true;
Sean Callanan76264762010-04-02 22:27:05 +00004605 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004606 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4607 return false;
4608 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004609 case AsmToken::LBrac:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004610 return parseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00004611 case AsmToken::LCurly:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004612 return parseRegisterList(Operands);
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004613 case AsmToken::Dollar:
Owen Anderson63553c72011-08-29 17:17:09 +00004614 case AsmToken::Hash: {
Kevin Enderby079469f2009-10-13 23:33:38 +00004615 // #42 -> immediate.
Sean Callanan76264762010-04-02 22:27:05 +00004616 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004617 Parser.Lex();
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004618
4619 if (Parser.getTok().isNot(AsmToken::Colon)) {
4620 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4621 const MCExpr *ImmVal;
4622 if (getParser().ParseExpression(ImmVal))
4623 return true;
4624 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4625 if (CE) {
4626 int32_t Val = CE->getValue();
4627 if (isNegative && Val == 0)
4628 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4629 }
4630 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4631 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4632 return false;
Owen Anderson63553c72011-08-29 17:17:09 +00004633 }
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004634 // w/ a ':' after the '#', it's just like a plain ':'.
4635 // FALLTHROUGH
Owen Anderson63553c72011-08-29 17:17:09 +00004636 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004637 case AsmToken::Colon: {
4638 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00004639 // FIXME: Check it's an expression prefix,
4640 // e.g. (FOO - :lower16:BAR) isn't legal.
4641 ARMMCExpr::VariantKind RefKind;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004642 if (parsePrefix(RefKind))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004643 return true;
4644
Evan Cheng75972122011-01-13 07:58:56 +00004645 const MCExpr *SubExprVal;
4646 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004647 return true;
4648
Evan Cheng75972122011-01-13 07:58:56 +00004649 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4650 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00004651 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00004652 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00004653 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004654 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004655 }
4656}
4657
Jim Grosbach1355cf12011-07-26 17:10:22 +00004658// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng75972122011-01-13 07:58:56 +00004659// :lower16: and :upper16:.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004660bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng75972122011-01-13 07:58:56 +00004661 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004662
4663 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00004664 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00004665 Parser.Lex(); // Eat ':'
4666
4667 if (getLexer().isNot(AsmToken::Identifier)) {
4668 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4669 return true;
4670 }
4671
4672 StringRef IDVal = Parser.getTok().getIdentifier();
4673 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00004674 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004675 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00004676 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004677 } else {
4678 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4679 return true;
4680 }
4681 Parser.Lex();
4682
4683 if (getLexer().isNot(AsmToken::Colon)) {
4684 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4685 return true;
4686 }
4687 Parser.Lex(); // Eat the last ':'
4688 return false;
4689}
4690
Daniel Dunbar352e1482011-01-11 15:59:50 +00004691/// \brief Given a mnemonic, split out possible predication code and carry
4692/// setting letters to form a canonical mnemonic and flags.
4693//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004694// FIXME: Would be nice to autogen this.
Jim Grosbach89df9962011-08-26 21:43:41 +00004695// FIXME: This is a bit of a maze of special cases.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004696StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5f160572011-07-19 20:10:31 +00004697 unsigned &PredicationCode,
4698 bool &CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004699 unsigned &ProcessorIMod,
4700 StringRef &ITMask) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004701 PredicationCode = ARMCC::AL;
4702 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004703 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004704
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004705 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00004706 //
4707 // FIXME: Would be nice to autogen this.
Jim Grosbach5f160572011-07-19 20:10:31 +00004708 if ((Mnemonic == "movs" && isThumb()) ||
4709 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4710 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4711 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4712 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4713 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4714 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbach68490192011-12-19 19:43:50 +00004715 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4716 Mnemonic == "fmuls")
Daniel Dunbar352e1482011-01-11 15:59:50 +00004717 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00004718
Jim Grosbach3f00e312011-07-11 17:09:57 +00004719 // First, split out any predication code. Ignore mnemonics we know aren't
4720 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbachab40f4b2011-07-20 18:20:31 +00004721 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach71725a02011-07-27 21:58:11 +00004722 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach04d55f12011-08-22 23:55:58 +00004723 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbach2f25d9b2011-09-01 18:22:13 +00004724 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbach3f00e312011-07-11 17:09:57 +00004725 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4726 .Case("eq", ARMCC::EQ)
4727 .Case("ne", ARMCC::NE)
4728 .Case("hs", ARMCC::HS)
4729 .Case("cs", ARMCC::HS)
4730 .Case("lo", ARMCC::LO)
4731 .Case("cc", ARMCC::LO)
4732 .Case("mi", ARMCC::MI)
4733 .Case("pl", ARMCC::PL)
4734 .Case("vs", ARMCC::VS)
4735 .Case("vc", ARMCC::VC)
4736 .Case("hi", ARMCC::HI)
4737 .Case("ls", ARMCC::LS)
4738 .Case("ge", ARMCC::GE)
4739 .Case("lt", ARMCC::LT)
4740 .Case("gt", ARMCC::GT)
4741 .Case("le", ARMCC::LE)
4742 .Case("al", ARMCC::AL)
4743 .Default(~0U);
4744 if (CC != ~0U) {
4745 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4746 PredicationCode = CC;
4747 }
Bill Wendling52925b62010-10-29 23:50:21 +00004748 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004749
Daniel Dunbar352e1482011-01-11 15:59:50 +00004750 // Next, determine if we have a carry setting bit. We explicitly ignore all
4751 // the instructions we know end in 's'.
4752 if (Mnemonic.endswith("s") &&
Jim Grosbach00f5d982011-08-17 22:49:09 +00004753 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5f160572011-07-19 20:10:31 +00004754 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4755 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4756 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach67ca1ad2011-12-08 00:49:29 +00004757 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach48171e72011-12-10 00:01:02 +00004758 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach9c397892011-12-19 19:02:41 +00004759 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbach6357cae2012-03-15 20:48:18 +00004760 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004761 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbache1cf5902011-07-29 20:26:09 +00004762 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004763 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4764 CarrySetting = true;
4765 }
4766
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004767 // The "cps" instruction can have a interrupt mode operand which is glued into
4768 // the mnemonic. Check if this is the case, split it and parse the imod op
4769 if (Mnemonic.startswith("cps")) {
4770 // Split out any imod code.
4771 unsigned IMod =
4772 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4773 .Case("ie", ARM_PROC::IE)
4774 .Case("id", ARM_PROC::ID)
4775 .Default(~0U);
4776 if (IMod != ~0U) {
4777 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4778 ProcessorIMod = IMod;
4779 }
4780 }
4781
Jim Grosbach89df9962011-08-26 21:43:41 +00004782 // The "it" instruction has the condition mask on the end of the mnemonic.
4783 if (Mnemonic.startswith("it")) {
4784 ITMask = Mnemonic.slice(2, Mnemonic.size());
4785 Mnemonic = Mnemonic.slice(0, 2);
4786 }
4787
Daniel Dunbar352e1482011-01-11 15:59:50 +00004788 return Mnemonic;
4789}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004790
4791/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4792/// inclusion of carry set or predication code operands.
4793//
4794// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004795void ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00004796getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004797 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004798 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4799 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004800 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004801 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004802 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004803 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004804 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004805 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004806 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004807 Mnemonic == "mla" || Mnemonic == "smlal" ||
4808 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004809 CanAcceptCarrySet = true;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004810 } else
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004811 CanAcceptCarrySet = false;
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004812
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004813 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4814 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4815 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4816 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbachad2dad92011-09-06 20:27:04 +00004817 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4818 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach0780b632011-08-19 23:24:36 +00004819 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach2bd01182011-10-11 21:55:36 +00004820 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4821 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4822 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbach4af54a42011-08-26 22:21:51 +00004823 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4824 !isThumb()) ||
Jim Grosbach1ad60c22011-09-10 00:15:36 +00004825 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004826 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004827 } else
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004828 CanAcceptPredicationCode = true;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004829
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004830 if (isThumb()) {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004831 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00004832 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004833 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004834 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004835}
4836
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004837bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4838 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004839 // FIXME: This is all horribly hacky. We really need a better way to deal
4840 // with optional operands like this in the matcher table.
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004841
4842 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4843 // another does not. Specifically, the MOVW instruction does not. So we
4844 // special case it here and remove the defaulted (non-setting) cc_out
4845 // operand if that's the instruction we're trying to match.
4846 //
4847 // We do this as post-processing of the explicit operands rather than just
4848 // conditionally adding the cc_out in the first place because we need
4849 // to check the type of the parsed immediate operand.
Owen Anderson8adf6202011-09-14 22:46:14 +00004850 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004851 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4852 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4853 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4854 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004855
4856 // Register-register 'add' for thumb does not have a cc_out operand
4857 // when there are only two register operands.
4858 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4859 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4860 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4861 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4862 return true;
Jim Grosbach72f39f82011-08-24 21:22:15 +00004863 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004864 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4865 // have to check the immediate range here since Thumb2 has a variant
4866 // that can handle a different range and has a cc_out operand.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004867 if (((isThumb() && Mnemonic == "add") ||
4868 (isThumbTwo() && Mnemonic == "sub")) &&
4869 Operands.size() == 6 &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004870 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4871 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4872 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004873 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004874 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004875 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004876 return true;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004877 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4878 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004879 // selecting via the generic "add" mnemonic, so to know that we
4880 // should remove the cc_out operand, we have to explicitly check that
4881 // it's not one of the other variants. Ugh.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004882 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4883 Operands.size() == 6 &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004884 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4885 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4886 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4887 // Nest conditions rather than one big 'if' statement for readability.
4888 //
4889 // If either register is a high reg, it's either one of the SP
4890 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach12a88632012-01-21 00:07:56 +00004891 // check against T3. If the second register is the PC, this is an
4892 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004893 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4894 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach12a88632012-01-21 00:07:56 +00004895 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004896 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4897 return false;
4898 // If both registers are low, we're in an IT block, and the immediate is
4899 // in range, we should use encoding T1 instead, which has a cc_out.
4900 if (inITBlock() &&
Jim Grosbach64944f42011-09-14 21:00:40 +00004901 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004902 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4903 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4904 return false;
4905
4906 // Otherwise, we use encoding T4, which does not have a cc_out
4907 // operand.
4908 return true;
4909 }
4910
Jim Grosbach64944f42011-09-14 21:00:40 +00004911 // The thumb2 multiply instruction doesn't have a CCOut register, so
4912 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4913 // use the 16-bit encoding or not.
4914 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4915 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4916 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4917 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4918 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4919 // If the registers aren't low regs, the destination reg isn't the
4920 // same as one of the source regs, or the cc_out operand is zero
4921 // outside of an IT block, we have to use the 32-bit encoding, so
4922 // remove the cc_out operand.
4923 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4924 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach1de0bd12011-11-15 19:29:45 +00004925 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach64944f42011-09-14 21:00:40 +00004926 !inITBlock() ||
4927 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4928 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4929 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4930 static_cast<ARMOperand*>(Operands[4])->getReg())))
4931 return true;
4932
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004933 // Also check the 'mul' syntax variant that doesn't specify an explicit
4934 // destination register.
4935 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4936 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4937 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4938 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4939 // If the registers aren't low regs or the cc_out operand is zero
4940 // outside of an IT block, we have to use the 32-bit encoding, so
4941 // remove the cc_out operand.
4942 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4943 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4944 !inITBlock()))
4945 return true;
4946
Jim Grosbach64944f42011-09-14 21:00:40 +00004947
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004948
Jim Grosbachf69c8042011-08-24 21:42:27 +00004949 // Register-register 'add/sub' for thumb does not have a cc_out operand
4950 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4951 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4952 // right, this will result in better diagnostics (which operand is off)
4953 // anyway.
4954 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4955 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004956 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4957 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004958 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4959 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4960 (Operands.size() == 6 &&
4961 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004962 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004963
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004964 return false;
4965}
4966
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004967static bool isDataTypeToken(StringRef Tok) {
4968 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4969 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4970 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4971 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4972 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4973 Tok == ".f" || Tok == ".d";
4974}
4975
4976// FIXME: This bit should probably be handled via an explicit match class
4977// in the .td files that matches the suffix instead of having it be
4978// a literal string token the way it is now.
4979static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4980 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4981}
4982
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004983static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004984/// Parse an arm instruction mnemonic followed by its operands.
4985bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4986 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004987 // Apply mnemonic aliases before doing anything else, as the destination
4988 // mnemnonic may include suffices and we want to handle them normally.
4989 // The generic tblgen'erated code does this later, at the start of
4990 // MatchInstructionImpl(), but that's too late for aliases that include
4991 // any sort of suffix.
4992 unsigned AvailableFeatures = getAvailableFeatures();
4993 applyMnemonicAliases(Name, AvailableFeatures);
4994
Jim Grosbacha39cda72011-12-14 02:16:11 +00004995 // First check for the ARM-specific .req directive.
4996 if (Parser.getTok().is(AsmToken::Identifier) &&
4997 Parser.getTok().getIdentifier() == ".req") {
4998 parseDirectiveReq(Name, NameLoc);
4999 // We always return 'error' for this, as we're done with this
5000 // statement and don't need to match the 'instruction."
5001 return true;
5002 }
5003
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00005004 // Create the leading tokens for the mnemonic, split by '.' characters.
5005 size_t Start = 0, Next = Name.find('.');
Jim Grosbachffa32252011-07-19 19:13:28 +00005006 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00005007
Daniel Dunbar352e1482011-01-11 15:59:50 +00005008 // Split out the predication code and carry setting flag from the mnemonic.
5009 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005010 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00005011 bool CarrySetting;
Jim Grosbach89df9962011-08-26 21:43:41 +00005012 StringRef ITMask;
Jim Grosbach1355cf12011-07-26 17:10:22 +00005013 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00005014 ProcessorIMod, ITMask);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00005015
Jim Grosbach0c49ac02011-08-25 17:23:55 +00005016 // In Thumb1, only the branch (B) instruction can be predicated.
5017 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5018 Parser.EatToEndOfStatement();
5019 return Error(NameLoc, "conditional execution not supported in Thumb1");
5020 }
5021
Jim Grosbachffa32252011-07-19 19:13:28 +00005022 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5023
Jim Grosbach89df9962011-08-26 21:43:41 +00005024 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5025 // is the mask as it will be for the IT encoding if the conditional
5026 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5027 // where the conditional bit0 is zero, the instruction post-processing
5028 // will adjust the mask accordingly.
5029 if (Mnemonic == "it") {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005030 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5031 if (ITMask.size() > 3) {
5032 Parser.EatToEndOfStatement();
5033 return Error(Loc, "too many conditions on IT instruction");
5034 }
Jim Grosbach89df9962011-08-26 21:43:41 +00005035 unsigned Mask = 8;
5036 for (unsigned i = ITMask.size(); i != 0; --i) {
5037 char pos = ITMask[i - 1];
5038 if (pos != 't' && pos != 'e') {
5039 Parser.EatToEndOfStatement();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005040 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach89df9962011-08-26 21:43:41 +00005041 }
5042 Mask >>= 1;
5043 if (ITMask[i - 1] == 't')
5044 Mask |= 8;
5045 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005046 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach89df9962011-08-26 21:43:41 +00005047 }
5048
Jim Grosbachffa32252011-07-19 19:13:28 +00005049 // FIXME: This is all a pretty gross hack. We should automatically handle
5050 // optional operands like this via tblgen.
Bill Wendling9717fa92010-11-21 10:56:05 +00005051
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005052 // Next, add the CCOut and ConditionCode operands, if needed.
5053 //
5054 // For mnemonics which can ever incorporate a carry setting bit or predication
5055 // code, our matching model involves us always generating CCOut and
5056 // ConditionCode operands to match the mnemonic "as written" and then we let
5057 // the matcher deal with finding the right instruction or generating an
5058 // appropriate error.
5059 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbach1355cf12011-07-26 17:10:22 +00005060 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005061
Jim Grosbach33c16a22011-07-14 22:04:21 +00005062 // If we had a carry-set on an instruction that can't do that, issue an
5063 // error.
5064 if (!CanAcceptCarrySet && CarrySetting) {
5065 Parser.EatToEndOfStatement();
Jim Grosbachffa32252011-07-19 19:13:28 +00005066 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach33c16a22011-07-14 22:04:21 +00005067 "' can not set flags, but 's' suffix specified");
5068 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +00005069 // If we had a predication code on an instruction that can't do that, issue an
5070 // error.
5071 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5072 Parser.EatToEndOfStatement();
5073 return Error(NameLoc, "instruction '" + Mnemonic +
5074 "' is not predicable, but condition code specified");
5075 }
Jim Grosbach33c16a22011-07-14 22:04:21 +00005076
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005077 // Add the carry setting operand, if necessary.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005078 if (CanAcceptCarrySet) {
5079 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005080 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005081 Loc));
5082 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005083
5084 // Add the predication code operand, if necessary.
5085 if (CanAcceptPredicationCode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005086 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5087 CarrySetting);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005088 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005089 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00005090 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005091
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005092 // Add the processor imod operand, if necessary.
5093 if (ProcessorIMod) {
5094 Operands.push_back(ARMOperand::CreateImm(
5095 MCConstantExpr::Create(ProcessorIMod, getContext()),
5096 NameLoc, NameLoc));
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005097 }
5098
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005099 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00005100 while (Next != StringRef::npos) {
5101 Start = Next;
5102 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005103 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005104
Jim Grosbach7aef99b2011-11-11 23:08:10 +00005105 // Some NEON instructions have an optional datatype suffix that is
5106 // completely ignored. Check for that.
5107 if (isDataTypeToken(ExtraToken) &&
5108 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5109 continue;
5110
Jim Grosbach81d2e392011-09-07 16:06:04 +00005111 if (ExtraToken != ".n") {
5112 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5113 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5114 }
Daniel Dunbar5747b132010-08-11 06:37:16 +00005115 }
5116
5117 // Read the remaining operands.
5118 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005119 // Read the first operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005120 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005121 Parser.EatToEndOfStatement();
5122 return true;
5123 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005124
5125 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00005126 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005127
5128 // Parse and remember the operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005129 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005130 Parser.EatToEndOfStatement();
5131 return true;
5132 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005133 }
5134 }
Jim Grosbach16c74252010-10-29 14:46:02 +00005135
Chris Lattnercbf8a982010-09-11 16:18:25 +00005136 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbach186ffac2011-10-07 18:27:04 +00005137 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00005138 Parser.EatToEndOfStatement();
Jim Grosbach186ffac2011-10-07 18:27:04 +00005139 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00005140 }
Bill Wendling146018f2010-11-06 21:42:12 +00005141
Chris Lattner34e53142010-09-08 05:10:46 +00005142 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbachffa32252011-07-19 19:13:28 +00005143
Jim Grosbachd54b4e62011-08-16 21:12:37 +00005144 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5145 // do and don't have a cc_out optional-def operand. With some spot-checks
5146 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach20ed2e72011-09-01 00:28:52 +00005147 // parse and adjust accordingly before actually matching. We shouldn't ever
5148 // try to remove a cc_out operand that was explicitly set on the the
5149 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5150 // table driven matcher doesn't fit well with the ARM instruction set.
5151 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbachffa32252011-07-19 19:13:28 +00005152 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5153 Operands.erase(Operands.begin() + 1);
5154 delete Op;
5155 }
5156
Jim Grosbachcf121c32011-07-28 21:57:55 +00005157 // ARM mode 'blx' need special handling, as the register operand version
5158 // is predicable, but the label operand version is not. So, we can't rely
5159 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach21ff17c2011-10-07 23:24:09 +00005160 // a k_CondCode operand in the list. If we're trying to match the label
5161 // version, remove the k_CondCode operand here.
Jim Grosbachcf121c32011-07-28 21:57:55 +00005162 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5163 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5164 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5165 Operands.erase(Operands.begin() + 1);
5166 delete Op;
5167 }
Jim Grosbach857e1a72011-08-11 23:51:13 +00005168
5169 // The vector-compare-to-zero instructions have a literal token "#0" at
5170 // the end that comes to here as an immediate operand. Convert it to a
5171 // token to play nicely with the matcher.
5172 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5173 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5174 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5175 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5177 if (CE && CE->getValue() == 0) {
5178 Operands.erase(Operands.begin() + 5);
5179 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5180 delete Op;
5181 }
5182 }
Jim Grosbach68259142011-10-03 22:30:24 +00005183 // VCMP{E} does the same thing, but with a different operand count.
5184 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5185 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5186 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5187 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5188 if (CE && CE->getValue() == 0) {
5189 Operands.erase(Operands.begin() + 4);
5190 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5191 delete Op;
5192 }
5193 }
Jim Grosbach934755a2011-08-22 23:47:13 +00005194 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach55b02f22011-12-13 20:50:38 +00005195 // end. Convert it to a token here. Take care not to convert those
5196 // that should hit the Thumb2 encoding.
Jim Grosbach934755a2011-08-22 23:47:13 +00005197 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach55b02f22011-12-13 20:50:38 +00005198 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5199 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbach934755a2011-08-22 23:47:13 +00005200 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5201 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5202 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach55b02f22011-12-13 20:50:38 +00005203 if (CE && CE->getValue() == 0 &&
5204 (isThumbOne() ||
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005205 // The cc_out operand matches the IT block.
5206 ((inITBlock() != CarrySetting) &&
5207 // Neither register operand is a high register.
Jim Grosbach55b02f22011-12-13 20:50:38 +00005208 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005209 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbach934755a2011-08-22 23:47:13 +00005210 Operands.erase(Operands.begin() + 5);
5211 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5212 delete Op;
5213 }
5214 }
5215
Chris Lattner98986712010-01-14 22:21:20 +00005216 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00005217}
5218
Jim Grosbach189610f2011-07-26 18:25:39 +00005219// Validate context-sensitive operand constraints.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005220
5221// return 'true' if register list contains non-low GPR registers,
5222// 'false' otherwise. If Reg is in the register list or is HiReg, set
5223// 'containsReg' to true.
5224static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5225 unsigned HiReg, bool &containsReg) {
5226 containsReg = false;
5227 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5228 unsigned OpReg = Inst.getOperand(i).getReg();
5229 if (OpReg == Reg)
5230 containsReg = true;
5231 // Anything other than a low register isn't legal here.
5232 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5233 return true;
5234 }
5235 return false;
5236}
5237
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005238// Check if the specified regisgter is in the register list of the inst,
5239// starting at the indicated operand number.
5240static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5241 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5242 unsigned OpReg = Inst.getOperand(i).getReg();
5243 if (OpReg == Reg)
5244 return true;
5245 }
5246 return false;
5247}
5248
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005249// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5250// the ARMInsts array) instead. Getting that here requires awkward
5251// API changes, though. Better way?
5252namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005253extern const MCInstrDesc ARMInsts[];
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005254}
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005255static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005256 return ARMInsts[Opcode];
5257}
5258
Jim Grosbach189610f2011-07-26 18:25:39 +00005259// FIXME: We would really like to be able to tablegen'erate this.
5260bool ARMAsmParser::
5261validateInstruction(MCInst &Inst,
5262 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005263 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005264 SMLoc Loc = Operands[0]->getStartLoc();
5265 // Check the IT block state first.
Jim Grosbach74423e32012-01-25 19:52:01 +00005266 // NOTE: BKPT instruction has the interesting property of being
5267 // allowed in IT blocks, but not being predicable. It just always
Owen Andersonb6b7f512011-09-13 17:59:19 +00005268 // executes.
Jim Grosbach74423e32012-01-25 19:52:01 +00005269 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5270 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005271 unsigned bit = 1;
5272 if (ITState.FirstCond)
5273 ITState.FirstCond = false;
5274 else
Jim Grosbacha1109882011-09-02 23:22:08 +00005275 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005276 // The instruction must be predicable.
5277 if (!MCID.isPredicable())
5278 return Error(Loc, "instructions in IT block must be predicable");
5279 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5280 unsigned ITCond = bit ? ITState.Cond :
5281 ARMCC::getOppositeCondition(ITState.Cond);
5282 if (Cond != ITCond) {
5283 // Find the condition code Operand to get its SMLoc information.
5284 SMLoc CondLoc;
5285 for (unsigned i = 1; i < Operands.size(); ++i)
5286 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5287 CondLoc = Operands[i]->getStartLoc();
5288 return Error(CondLoc, "incorrect condition in IT block; got '" +
5289 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5290 "', but expected '" +
5291 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5292 }
Jim Grosbachc9a9b442011-08-31 18:29:05 +00005293 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005294 } else if (isThumbTwo() && MCID.isPredicable() &&
5295 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson51f6a7a2011-09-09 21:48:23 +00005296 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5297 Inst.getOpcode() != ARM::t2B)
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005298 return Error(Loc, "predicated instructions must be in IT block");
5299
Jim Grosbach189610f2011-07-26 18:25:39 +00005300 switch (Inst.getOpcode()) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00005301 case ARM::LDRD:
5302 case ARM::LDRD_PRE:
5303 case ARM::LDRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005304 case ARM::LDREXD: {
5305 // Rt2 must be Rt + 1.
5306 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5307 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5308 if (Rt2 != Rt + 1)
5309 return Error(Operands[3]->getStartLoc(),
5310 "destination operands must be sequential");
5311 return false;
5312 }
Jim Grosbach14605d12011-08-11 20:28:23 +00005313 case ARM::STRD: {
5314 // Rt2 must be Rt + 1.
5315 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5316 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5317 if (Rt2 != Rt + 1)
5318 return Error(Operands[3]->getStartLoc(),
5319 "source operands must be sequential");
5320 return false;
5321 }
Jim Grosbach53642c52011-08-10 20:49:18 +00005322 case ARM::STRD_PRE:
5323 case ARM::STRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005324 case ARM::STREXD: {
5325 // Rt2 must be Rt + 1.
5326 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5327 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(2).getReg());
5328 if (Rt2 != Rt + 1)
Jim Grosbach14605d12011-08-11 20:28:23 +00005329 return Error(Operands[3]->getStartLoc(),
Jim Grosbach189610f2011-07-26 18:25:39 +00005330 "source operands must be sequential");
5331 return false;
5332 }
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005333 case ARM::SBFX:
5334 case ARM::UBFX: {
5335 // width must be in range [1, 32-lsb]
5336 unsigned lsb = Inst.getOperand(2).getImm();
5337 unsigned widthm1 = Inst.getOperand(3).getImm();
5338 if (widthm1 >= 32 - lsb)
5339 return Error(Operands[5]->getStartLoc(),
5340 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach00c9a512011-08-16 21:42:31 +00005341 return false;
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005342 }
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005343 case ARM::tLDMIA: {
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005344 // If we're parsing Thumb2, the .w variant is available and handles
5345 // most cases that are normally illegal for a Thumb1 LDM
5346 // instruction. We'll make the transformation in processInstruction()
5347 // if necessary.
5348 //
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005349 // Thumb LDM instructions are writeback iff the base register is not
5350 // in the register list.
5351 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005352 bool hasWritebackToken =
5353 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5354 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbachaa875f82011-08-23 18:13:04 +00005355 bool listContainsBase;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005356 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005357 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5358 "registers must be in range r0-r7");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005359 // If we should have writeback, then there should be a '!' token.
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005360 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005361 return Error(Operands[2]->getStartLoc(),
5362 "writeback operator '!' expected");
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005363 // If we should not have writeback, there must not be a '!'. This is
5364 // true even for the 32-bit wide encodings.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005365 if (listContainsBase && hasWritebackToken)
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005366 return Error(Operands[3]->getStartLoc(),
5367 "writeback operator '!' not allowed when base register "
5368 "in register list");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005369
5370 break;
5371 }
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005372 case ARM::t2LDMIA_UPD: {
5373 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5374 return Error(Operands[4]->getStartLoc(),
5375 "writeback operator '!' not allowed when base register "
5376 "in register list");
5377 break;
5378 }
Jim Grosbach54026372011-11-10 23:17:11 +00005379 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5380 // so only issue a diagnostic for thumb1. The instructions will be
5381 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005382 case ARM::tPOP: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005383 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005384 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5385 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005386 return Error(Operands[2]->getStartLoc(),
5387 "registers must be in range r0-r7 or pc");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005388 break;
5389 }
5390 case ARM::tPUSH: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005391 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005392 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5393 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005394 return Error(Operands[2]->getStartLoc(),
5395 "registers must be in range r0-r7 or lr");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005396 break;
5397 }
Jim Grosbach1e84f192011-08-23 18:15:37 +00005398 case ARM::tSTMIA_UPD: {
5399 bool listContainsBase;
Jim Grosbach8213c962011-09-16 20:50:13 +00005400 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach1e84f192011-08-23 18:15:37 +00005401 return Error(Operands[4]->getStartLoc(),
5402 "registers must be in range r0-r7");
5403 break;
5404 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00005405 case ARM::tADDrSP: {
5406 // If the non-SP source operand and the destination operand are not the
5407 // same, we need thumb2 (for the wide encoding), or we have an error.
5408 if (!isThumbTwo() &&
5409 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5410 return Error(Operands[4]->getStartLoc(),
5411 "source register must be the same as destination");
5412 }
5413 break;
5414 }
Jim Grosbach189610f2011-07-26 18:25:39 +00005415 }
5416
5417 return false;
5418}
5419
Jim Grosbachd7433e22012-01-23 23:45:44 +00005420static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach84defb52011-12-02 22:34:51 +00005421 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005422 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005423 // VST1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005424 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5425 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5426 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5427 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5428 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5429 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5430 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5431 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5432 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005433
5434 // VST2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005435 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5436 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5437 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5438 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5439 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005440
Jim Grosbach7945ead2012-01-24 00:43:12 +00005441 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5442 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5443 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5444 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5445 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005446
Jim Grosbach7945ead2012-01-24 00:43:12 +00005447 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5448 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5449 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5450 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5451 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005452
Jim Grosbach4adb1822012-01-24 00:07:41 +00005453 // VST3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005454 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5455 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5456 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5457 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5458 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5459 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5460 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5461 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5462 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5463 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5464 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5465 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5466 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5467 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5468 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbach4adb1822012-01-24 00:07:41 +00005469
Jim Grosbachd7433e22012-01-23 23:45:44 +00005470 // VST3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005471 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5472 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5473 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5474 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5475 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5476 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5477 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5478 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5479 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5480 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5481 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5482 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5483 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5484 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5485 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5486 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5487 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5488 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbach539aab72012-01-24 00:58:13 +00005489
Jim Grosbach88a54de2012-01-24 18:53:13 +00005490 // VST4LN
5491 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5492 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5493 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5494 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5495 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5496 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5497 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5498 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5499 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5500 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5501 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5502 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5503 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5504 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5505 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5506
Jim Grosbach539aab72012-01-24 00:58:13 +00005507 // VST4
5508 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5509 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5510 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5511 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5512 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5513 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5514 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5515 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5516 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5517 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5518 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5519 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5520 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5521 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5522 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5523 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5524 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5525 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbach84defb52011-12-02 22:34:51 +00005526 }
5527}
5528
Jim Grosbachd7433e22012-01-23 23:45:44 +00005529static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00005530 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005531 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005532 // VLD1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005533 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5534 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5535 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5536 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5537 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5538 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5539 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5540 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5541 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005542
5543 // VLD2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005544 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5545 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5546 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5547 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5548 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5549 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5550 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5551 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5552 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5553 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5554 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5555 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5556 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5557 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5558 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbach3a678af2012-01-23 21:53:26 +00005559
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00005560 // VLD3DUP
5561 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5562 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5563 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5564 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5565 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5566 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5567 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5568 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5569 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5570 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5571 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5572 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5573 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5574 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5575 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5576 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5577 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5578 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5579
Jim Grosbach3a678af2012-01-23 21:53:26 +00005580 // VLD3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005581 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5582 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5583 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5584 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5585 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5586 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5587 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5588 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5589 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5590 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5591 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5592 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5593 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5594 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5595 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachc387fc62012-01-23 23:20:46 +00005596
5597 // VLD3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005598 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5599 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5600 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5601 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5602 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5603 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5604 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5605 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5606 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5607 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5608 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5609 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5610 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5611 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5612 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5613 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5614 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5615 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005616
Jim Grosbache983a132012-01-24 18:37:25 +00005617 // VLD4LN
5618 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5619 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5620 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5621 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5622 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5623 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5624 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5625 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5626 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5627 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5628 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5629 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5630 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5631 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5632 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5633
Jim Grosbacha57a36a2012-01-25 00:01:08 +00005634 // VLD4DUP
5635 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5636 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5637 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5638 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5639 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5640 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5641 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5642 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5643 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5644 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5645 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5646 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5647 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5648 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5649 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5650 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5651 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5652 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5653
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005654 // VLD4
5655 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5656 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5657 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5658 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5659 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5660 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5661 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5662 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5663 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5664 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5665 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5666 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5667 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5668 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5669 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5670 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5671 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5672 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach7636bf62011-12-02 00:35:16 +00005673 }
5674}
5675
Jim Grosbach83ec8772011-11-10 23:42:14 +00005676bool ARMAsmParser::
Jim Grosbachf8fce712011-08-11 17:35:48 +00005677processInstruction(MCInst &Inst,
5678 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5679 switch (Inst.getOpcode()) {
Jim Grosbach0b4c6732012-01-18 22:46:46 +00005680 // Aliases for alternate PC+imm syntax of LDR instructions.
5681 case ARM::t2LDRpcrel:
5682 Inst.setOpcode(ARM::t2LDRpci);
5683 return true;
5684 case ARM::t2LDRBpcrel:
5685 Inst.setOpcode(ARM::t2LDRBpci);
5686 return true;
5687 case ARM::t2LDRHpcrel:
5688 Inst.setOpcode(ARM::t2LDRHpci);
5689 return true;
5690 case ARM::t2LDRSBpcrel:
5691 Inst.setOpcode(ARM::t2LDRSBpci);
5692 return true;
5693 case ARM::t2LDRSHpcrel:
5694 Inst.setOpcode(ARM::t2LDRSHpci);
5695 return true;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005696 // Handle NEON VST complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005697 case ARM::VST1LNdWB_register_Asm_8:
5698 case ARM::VST1LNdWB_register_Asm_16:
5699 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005700 MCInst TmpInst;
5701 // Shuffle the operands around so the lane index operand is in the
5702 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005703 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005704 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005705 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5706 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5707 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5708 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5709 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5710 TmpInst.addOperand(Inst.getOperand(1)); // lane
5711 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5712 TmpInst.addOperand(Inst.getOperand(6));
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::VST2LNdWB_register_Asm_8:
5718 case ARM::VST2LNdWB_register_Asm_16:
5719 case ARM::VST2LNdWB_register_Asm_32:
5720 case ARM::VST2LNqWB_register_Asm_16:
5721 case ARM::VST2LNqWB_register_Asm_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_wb
5728 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5729 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5730 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5731 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5733 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005734 TmpInst.addOperand(Inst.getOperand(1)); // lane
5735 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5736 TmpInst.addOperand(Inst.getOperand(6));
5737 Inst = TmpInst;
5738 return true;
5739 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005740
5741 case ARM::VST3LNdWB_register_Asm_8:
5742 case ARM::VST3LNdWB_register_Asm_16:
5743 case ARM::VST3LNdWB_register_Asm_32:
5744 case ARM::VST3LNqWB_register_Asm_16:
5745 case ARM::VST3LNqWB_register_Asm_32: {
5746 MCInst TmpInst;
5747 // Shuffle the operands around so the lane index operand is in the
5748 // right place.
5749 unsigned Spacing;
5750 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5751 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5752 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5753 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5754 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5755 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5756 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5757 Spacing));
5758 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5759 Spacing * 2));
5760 TmpInst.addOperand(Inst.getOperand(1)); // lane
5761 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5762 TmpInst.addOperand(Inst.getOperand(6));
5763 Inst = TmpInst;
5764 return true;
5765 }
5766
Jim Grosbach88a54de2012-01-24 18:53:13 +00005767 case ARM::VST4LNdWB_register_Asm_8:
5768 case ARM::VST4LNdWB_register_Asm_16:
5769 case ARM::VST4LNdWB_register_Asm_32:
5770 case ARM::VST4LNqWB_register_Asm_16:
5771 case ARM::VST4LNqWB_register_Asm_32: {
5772 MCInst TmpInst;
5773 // Shuffle the operands around so the lane index operand is in the
5774 // right place.
5775 unsigned Spacing;
5776 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5777 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5778 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5779 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5780 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5781 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5782 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5783 Spacing));
5784 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5785 Spacing * 2));
5786 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5787 Spacing * 3));
5788 TmpInst.addOperand(Inst.getOperand(1)); // lane
5789 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5790 TmpInst.addOperand(Inst.getOperand(6));
5791 Inst = TmpInst;
5792 return true;
5793 }
5794
Jim Grosbach8b31f952012-01-23 19:39:08 +00005795 case ARM::VST1LNdWB_fixed_Asm_8:
5796 case ARM::VST1LNdWB_fixed_Asm_16:
5797 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005798 MCInst TmpInst;
5799 // Shuffle the operands around so the lane index operand is in the
5800 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005801 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005802 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005803 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5804 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5805 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5806 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5807 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5808 TmpInst.addOperand(Inst.getOperand(1)); // lane
5809 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5810 TmpInst.addOperand(Inst.getOperand(5));
5811 Inst = TmpInst;
5812 return true;
5813 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005814
Jim Grosbach8b31f952012-01-23 19:39:08 +00005815 case ARM::VST2LNdWB_fixed_Asm_8:
5816 case ARM::VST2LNdWB_fixed_Asm_16:
5817 case ARM::VST2LNdWB_fixed_Asm_32:
5818 case ARM::VST2LNqWB_fixed_Asm_16:
5819 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005820 MCInst TmpInst;
5821 // Shuffle the operands around so the lane index operand is in the
5822 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005823 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005824 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005825 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5826 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5827 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5828 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5829 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005830 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5831 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005832 TmpInst.addOperand(Inst.getOperand(1)); // lane
5833 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5834 TmpInst.addOperand(Inst.getOperand(5));
5835 Inst = TmpInst;
5836 return true;
5837 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005838
5839 case ARM::VST3LNdWB_fixed_Asm_8:
5840 case ARM::VST3LNdWB_fixed_Asm_16:
5841 case ARM::VST3LNdWB_fixed_Asm_32:
5842 case ARM::VST3LNqWB_fixed_Asm_16:
5843 case ARM::VST3LNqWB_fixed_Asm_32: {
5844 MCInst TmpInst;
5845 // Shuffle the operands around so the lane index operand is in the
5846 // right place.
5847 unsigned Spacing;
5848 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5849 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5850 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5851 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5852 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5853 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5854 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5855 Spacing));
5856 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5857 Spacing * 2));
5858 TmpInst.addOperand(Inst.getOperand(1)); // lane
5859 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5860 TmpInst.addOperand(Inst.getOperand(5));
5861 Inst = TmpInst;
5862 return true;
5863 }
5864
Jim Grosbach88a54de2012-01-24 18:53:13 +00005865 case ARM::VST4LNdWB_fixed_Asm_8:
5866 case ARM::VST4LNdWB_fixed_Asm_16:
5867 case ARM::VST4LNdWB_fixed_Asm_32:
5868 case ARM::VST4LNqWB_fixed_Asm_16:
5869 case ARM::VST4LNqWB_fixed_Asm_32: {
5870 MCInst TmpInst;
5871 // Shuffle the operands around so the lane index operand is in the
5872 // right place.
5873 unsigned Spacing;
5874 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5875 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5876 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5877 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5878 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
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(1)); // lane
5887 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5888 TmpInst.addOperand(Inst.getOperand(5));
5889 Inst = TmpInst;
5890 return true;
5891 }
5892
Jim Grosbach8b31f952012-01-23 19:39:08 +00005893 case ARM::VST1LNdAsm_8:
5894 case ARM::VST1LNdAsm_16:
5895 case ARM::VST1LNdAsm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005896 MCInst TmpInst;
5897 // Shuffle the operands around so the lane index operand is in the
5898 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005899 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005900 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005901 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5902 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5903 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5904 TmpInst.addOperand(Inst.getOperand(1)); // lane
5905 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5906 TmpInst.addOperand(Inst.getOperand(5));
5907 Inst = TmpInst;
5908 return true;
5909 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005910
Jim Grosbach8b31f952012-01-23 19:39:08 +00005911 case ARM::VST2LNdAsm_8:
5912 case ARM::VST2LNdAsm_16:
5913 case ARM::VST2LNdAsm_32:
5914 case ARM::VST2LNqAsm_16:
5915 case ARM::VST2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005916 MCInst TmpInst;
5917 // Shuffle the operands around so the lane index operand is in the
5918 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005919 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005920 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005921 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5922 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5923 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005924 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5925 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005926 TmpInst.addOperand(Inst.getOperand(1)); // lane
5927 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5928 TmpInst.addOperand(Inst.getOperand(5));
5929 Inst = TmpInst;
5930 return true;
5931 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005932
5933 case ARM::VST3LNdAsm_8:
5934 case ARM::VST3LNdAsm_16:
5935 case ARM::VST3LNdAsm_32:
5936 case ARM::VST3LNqAsm_16:
5937 case ARM::VST3LNqAsm_32: {
5938 MCInst TmpInst;
5939 // Shuffle the operands around so the lane index operand is in the
5940 // right place.
5941 unsigned Spacing;
5942 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5943 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5944 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5945 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5946 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5947 Spacing));
5948 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5949 Spacing * 2));
5950 TmpInst.addOperand(Inst.getOperand(1)); // lane
5951 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5952 TmpInst.addOperand(Inst.getOperand(5));
5953 Inst = TmpInst;
5954 return true;
5955 }
5956
Jim Grosbach88a54de2012-01-24 18:53:13 +00005957 case ARM::VST4LNdAsm_8:
5958 case ARM::VST4LNdAsm_16:
5959 case ARM::VST4LNdAsm_32:
5960 case ARM::VST4LNqAsm_16:
5961 case ARM::VST4LNqAsm_32: {
5962 MCInst TmpInst;
5963 // Shuffle the operands around so the lane index operand is in the
5964 // right place.
5965 unsigned Spacing;
5966 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5967 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5968 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5969 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5970 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5971 Spacing));
5972 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5973 Spacing * 2));
5974 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5975 Spacing * 3));
5976 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 Grosbach9b1b3902011-12-14 23:25:46 +00005983 // Handle NEON VLD complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005984 case ARM::VLD1LNdWB_register_Asm_8:
5985 case ARM::VLD1LNdWB_register_Asm_16:
5986 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005987 MCInst TmpInst;
5988 // Shuffle the operands around so the lane index operand is in the
5989 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005990 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005991 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005992 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5993 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5994 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5995 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5996 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5997 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5998 TmpInst.addOperand(Inst.getOperand(1)); // lane
5999 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6000 TmpInst.addOperand(Inst.getOperand(6));
6001 Inst = TmpInst;
6002 return true;
6003 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006004
Jim Grosbach8b31f952012-01-23 19:39:08 +00006005 case ARM::VLD2LNdWB_register_Asm_8:
6006 case ARM::VLD2LNdWB_register_Asm_16:
6007 case ARM::VLD2LNdWB_register_Asm_32:
6008 case ARM::VLD2LNqWB_register_Asm_16:
6009 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006010 MCInst TmpInst;
6011 // Shuffle the operands around so the lane index operand is in the
6012 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006013 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006014 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006015 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6017 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006018 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6019 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6020 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6021 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6022 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006023 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6024 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006025 TmpInst.addOperand(Inst.getOperand(1)); // lane
6026 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6027 TmpInst.addOperand(Inst.getOperand(6));
6028 Inst = TmpInst;
6029 return true;
6030 }
6031
Jim Grosbach3a678af2012-01-23 21:53:26 +00006032 case ARM::VLD3LNdWB_register_Asm_8:
6033 case ARM::VLD3LNdWB_register_Asm_16:
6034 case ARM::VLD3LNdWB_register_Asm_32:
6035 case ARM::VLD3LNqWB_register_Asm_16:
6036 case ARM::VLD3LNqWB_register_Asm_32: {
6037 MCInst TmpInst;
6038 // Shuffle the operands around so the lane index operand is in the
6039 // right place.
6040 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006041 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006042 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6043 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6044 Spacing));
6045 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006046 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006047 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6048 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6049 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6050 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6051 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6052 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6053 Spacing));
6054 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006055 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006056 TmpInst.addOperand(Inst.getOperand(1)); // lane
6057 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6058 TmpInst.addOperand(Inst.getOperand(6));
6059 Inst = TmpInst;
6060 return true;
6061 }
6062
Jim Grosbache983a132012-01-24 18:37:25 +00006063 case ARM::VLD4LNdWB_register_Asm_8:
6064 case ARM::VLD4LNdWB_register_Asm_16:
6065 case ARM::VLD4LNdWB_register_Asm_32:
6066 case ARM::VLD4LNqWB_register_Asm_16:
6067 case ARM::VLD4LNqWB_register_Asm_32: {
6068 MCInst TmpInst;
6069 // Shuffle the operands around so the lane index operand is in the
6070 // right place.
6071 unsigned Spacing;
6072 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6073 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6074 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6075 Spacing));
6076 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6077 Spacing * 2));
6078 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6079 Spacing * 3));
6080 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6081 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6082 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6083 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6084 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6085 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6086 Spacing));
6087 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6088 Spacing * 2));
6089 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6090 Spacing * 3));
6091 TmpInst.addOperand(Inst.getOperand(1)); // lane
6092 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6093 TmpInst.addOperand(Inst.getOperand(6));
6094 Inst = TmpInst;
6095 return true;
6096 }
6097
Jim Grosbach8b31f952012-01-23 19:39:08 +00006098 case ARM::VLD1LNdWB_fixed_Asm_8:
6099 case ARM::VLD1LNdWB_fixed_Asm_16:
6100 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00006101 MCInst TmpInst;
6102 // Shuffle the operands around so the lane index operand is in the
6103 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006104 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006105 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00006106 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6107 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6108 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6109 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6110 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6111 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6112 TmpInst.addOperand(Inst.getOperand(1)); // lane
6113 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6114 TmpInst.addOperand(Inst.getOperand(5));
6115 Inst = TmpInst;
6116 return true;
6117 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006118
Jim Grosbach8b31f952012-01-23 19:39:08 +00006119 case ARM::VLD2LNdWB_fixed_Asm_8:
6120 case ARM::VLD2LNdWB_fixed_Asm_16:
6121 case ARM::VLD2LNdWB_fixed_Asm_32:
6122 case ARM::VLD2LNqWB_fixed_Asm_16:
6123 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006124 MCInst TmpInst;
6125 // Shuffle the operands around so the lane index operand is in the
6126 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006127 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006128 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006129 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006130 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6131 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006132 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6133 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6134 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6135 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6136 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006137 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6138 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006139 TmpInst.addOperand(Inst.getOperand(1)); // lane
6140 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6141 TmpInst.addOperand(Inst.getOperand(5));
6142 Inst = TmpInst;
6143 return true;
6144 }
6145
Jim Grosbach3a678af2012-01-23 21:53:26 +00006146 case ARM::VLD3LNdWB_fixed_Asm_8:
6147 case ARM::VLD3LNdWB_fixed_Asm_16:
6148 case ARM::VLD3LNdWB_fixed_Asm_32:
6149 case ARM::VLD3LNqWB_fixed_Asm_16:
6150 case ARM::VLD3LNqWB_fixed_Asm_32: {
6151 MCInst TmpInst;
6152 // Shuffle the operands around so the lane index operand is in the
6153 // right place.
6154 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006155 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006156 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() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006160 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006161 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6162 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6163 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6164 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6165 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6166 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6167 Spacing));
6168 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006169 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006170 TmpInst.addOperand(Inst.getOperand(1)); // lane
6171 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6172 TmpInst.addOperand(Inst.getOperand(5));
6173 Inst = TmpInst;
6174 return true;
6175 }
6176
Jim Grosbache983a132012-01-24 18:37:25 +00006177 case ARM::VLD4LNdWB_fixed_Asm_8:
6178 case ARM::VLD4LNdWB_fixed_Asm_16:
6179 case ARM::VLD4LNdWB_fixed_Asm_32:
6180 case ARM::VLD4LNqWB_fixed_Asm_16:
6181 case ARM::VLD4LNqWB_fixed_Asm_32: {
6182 MCInst TmpInst;
6183 // Shuffle the operands around so the lane index operand is in the
6184 // right place.
6185 unsigned Spacing;
6186 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6187 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6188 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6189 Spacing));
6190 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6191 Spacing * 2));
6192 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6193 Spacing * 3));
6194 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6195 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6196 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6197 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6198 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6199 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6200 Spacing));
6201 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6202 Spacing * 2));
6203 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6204 Spacing * 3));
6205 TmpInst.addOperand(Inst.getOperand(1)); // lane
6206 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6207 TmpInst.addOperand(Inst.getOperand(5));
6208 Inst = TmpInst;
6209 return true;
6210 }
6211
Jim Grosbach8b31f952012-01-23 19:39:08 +00006212 case ARM::VLD1LNdAsm_8:
6213 case ARM::VLD1LNdAsm_16:
6214 case ARM::VLD1LNdAsm_32: {
Jim Grosbach7636bf62011-12-02 00:35:16 +00006215 MCInst TmpInst;
6216 // Shuffle the operands around so the lane index operand is in the
6217 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006218 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006219 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach7636bf62011-12-02 00:35:16 +00006220 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6221 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6222 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6223 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6224 TmpInst.addOperand(Inst.getOperand(1)); // lane
6225 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6226 TmpInst.addOperand(Inst.getOperand(5));
6227 Inst = TmpInst;
6228 return true;
6229 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006230
Jim Grosbach8b31f952012-01-23 19:39:08 +00006231 case ARM::VLD2LNdAsm_8:
6232 case ARM::VLD2LNdAsm_16:
6233 case ARM::VLD2LNdAsm_32:
6234 case ARM::VLD2LNqAsm_16:
6235 case ARM::VLD2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006236 MCInst TmpInst;
6237 // Shuffle the operands around so the lane index operand is in the
6238 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006239 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006240 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006241 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006242 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6243 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006244 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6245 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6246 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6248 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006249 TmpInst.addOperand(Inst.getOperand(1)); // lane
6250 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6251 TmpInst.addOperand(Inst.getOperand(5));
6252 Inst = TmpInst;
6253 return true;
6254 }
Jim Grosbach3a678af2012-01-23 21:53:26 +00006255
6256 case ARM::VLD3LNdAsm_8:
6257 case ARM::VLD3LNdAsm_16:
6258 case ARM::VLD3LNdAsm_32:
6259 case ARM::VLD3LNqAsm_16:
6260 case ARM::VLD3LNqAsm_32: {
6261 MCInst TmpInst;
6262 // Shuffle the operands around so the lane index operand is in the
6263 // right place.
6264 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006265 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006266 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6267 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6268 Spacing));
6269 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006270 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006271 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6272 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6273 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6274 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6275 Spacing));
6276 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006277 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006278 TmpInst.addOperand(Inst.getOperand(1)); // lane
6279 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6280 TmpInst.addOperand(Inst.getOperand(5));
6281 Inst = TmpInst;
6282 return true;
6283 }
6284
Jim Grosbache983a132012-01-24 18:37:25 +00006285 case ARM::VLD4LNdAsm_8:
6286 case ARM::VLD4LNdAsm_16:
6287 case ARM::VLD4LNdAsm_32:
6288 case ARM::VLD4LNqAsm_16:
6289 case ARM::VLD4LNqAsm_32: {
6290 MCInst TmpInst;
6291 // Shuffle the operands around so the lane index operand is in the
6292 // right place.
6293 unsigned Spacing;
6294 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6295 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6297 Spacing));
6298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6299 Spacing * 2));
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6301 Spacing * 3));
6302 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6303 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6304 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6305 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6306 Spacing));
6307 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6308 Spacing * 2));
6309 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6310 Spacing * 3));
6311 TmpInst.addOperand(Inst.getOperand(1)); // lane
6312 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6313 TmpInst.addOperand(Inst.getOperand(5));
6314 Inst = TmpInst;
6315 return true;
6316 }
6317
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00006318 // VLD3DUP single 3-element structure to all lanes instructions.
6319 case ARM::VLD3DUPdAsm_8:
6320 case ARM::VLD3DUPdAsm_16:
6321 case ARM::VLD3DUPdAsm_32:
6322 case ARM::VLD3DUPqAsm_8:
6323 case ARM::VLD3DUPqAsm_16:
6324 case ARM::VLD3DUPqAsm_32: {
6325 MCInst TmpInst;
6326 unsigned Spacing;
6327 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6328 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6329 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6330 Spacing));
6331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6332 Spacing * 2));
6333 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6334 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6335 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6336 TmpInst.addOperand(Inst.getOperand(4));
6337 Inst = TmpInst;
6338 return true;
6339 }
6340
6341 case ARM::VLD3DUPdWB_fixed_Asm_8:
6342 case ARM::VLD3DUPdWB_fixed_Asm_16:
6343 case ARM::VLD3DUPdWB_fixed_Asm_32:
6344 case ARM::VLD3DUPqWB_fixed_Asm_8:
6345 case ARM::VLD3DUPqWB_fixed_Asm_16:
6346 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6347 MCInst TmpInst;
6348 unsigned Spacing;
6349 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6350 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6351 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6352 Spacing));
6353 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6354 Spacing * 2));
6355 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6356 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6357 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6358 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6359 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6360 TmpInst.addOperand(Inst.getOperand(4));
6361 Inst = TmpInst;
6362 return true;
6363 }
6364
6365 case ARM::VLD3DUPdWB_register_Asm_8:
6366 case ARM::VLD3DUPdWB_register_Asm_16:
6367 case ARM::VLD3DUPdWB_register_Asm_32:
6368 case ARM::VLD3DUPqWB_register_Asm_8:
6369 case ARM::VLD3DUPqWB_register_Asm_16:
6370 case ARM::VLD3DUPqWB_register_Asm_32: {
6371 MCInst TmpInst;
6372 unsigned Spacing;
6373 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6374 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6375 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6376 Spacing));
6377 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6378 Spacing * 2));
6379 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6380 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6381 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6382 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6383 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6384 TmpInst.addOperand(Inst.getOperand(5));
6385 Inst = TmpInst;
6386 return true;
6387 }
6388
Jim Grosbachc387fc62012-01-23 23:20:46 +00006389 // VLD3 multiple 3-element structure instructions.
6390 case ARM::VLD3dAsm_8:
6391 case ARM::VLD3dAsm_16:
6392 case ARM::VLD3dAsm_32:
6393 case ARM::VLD3qAsm_8:
6394 case ARM::VLD3qAsm_16:
6395 case ARM::VLD3qAsm_32: {
6396 MCInst TmpInst;
6397 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006398 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006399 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6401 Spacing));
6402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6403 Spacing * 2));
6404 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6405 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6406 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6407 TmpInst.addOperand(Inst.getOperand(4));
6408 Inst = TmpInst;
6409 return true;
6410 }
6411
6412 case ARM::VLD3dWB_fixed_Asm_8:
6413 case ARM::VLD3dWB_fixed_Asm_16:
6414 case ARM::VLD3dWB_fixed_Asm_32:
6415 case ARM::VLD3qWB_fixed_Asm_8:
6416 case ARM::VLD3qWB_fixed_Asm_16:
6417 case ARM::VLD3qWB_fixed_Asm_32: {
6418 MCInst TmpInst;
6419 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006420 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006421 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6423 Spacing));
6424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6425 Spacing * 2));
6426 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6427 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6428 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6429 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6430 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6431 TmpInst.addOperand(Inst.getOperand(4));
6432 Inst = TmpInst;
6433 return true;
6434 }
6435
6436 case ARM::VLD3dWB_register_Asm_8:
6437 case ARM::VLD3dWB_register_Asm_16:
6438 case ARM::VLD3dWB_register_Asm_32:
6439 case ARM::VLD3qWB_register_Asm_8:
6440 case ARM::VLD3qWB_register_Asm_16:
6441 case ARM::VLD3qWB_register_Asm_32: {
6442 MCInst TmpInst;
6443 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006444 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006445 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6446 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6447 Spacing));
6448 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6449 Spacing * 2));
6450 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6451 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6452 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6453 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6454 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6455 TmpInst.addOperand(Inst.getOperand(5));
6456 Inst = TmpInst;
6457 return true;
6458 }
6459
Jim Grosbacha57a36a2012-01-25 00:01:08 +00006460 // VLD4DUP single 3-element structure to all lanes instructions.
6461 case ARM::VLD4DUPdAsm_8:
6462 case ARM::VLD4DUPdAsm_16:
6463 case ARM::VLD4DUPdAsm_32:
6464 case ARM::VLD4DUPqAsm_8:
6465 case ARM::VLD4DUPqAsm_16:
6466 case ARM::VLD4DUPqAsm_32: {
6467 MCInst TmpInst;
6468 unsigned Spacing;
6469 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6470 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6472 Spacing));
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6474 Spacing * 2));
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 Spacing * 3));
6477 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6478 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6479 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6480 TmpInst.addOperand(Inst.getOperand(4));
6481 Inst = TmpInst;
6482 return true;
6483 }
6484
6485 case ARM::VLD4DUPdWB_fixed_Asm_8:
6486 case ARM::VLD4DUPdWB_fixed_Asm_16:
6487 case ARM::VLD4DUPdWB_fixed_Asm_32:
6488 case ARM::VLD4DUPqWB_fixed_Asm_8:
6489 case ARM::VLD4DUPqWB_fixed_Asm_16:
6490 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6491 MCInst TmpInst;
6492 unsigned Spacing;
6493 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6494 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6496 Spacing));
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6498 Spacing * 2));
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6500 Spacing * 3));
6501 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6502 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6503 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6504 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6505 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6506 TmpInst.addOperand(Inst.getOperand(4));
6507 Inst = TmpInst;
6508 return true;
6509 }
6510
6511 case ARM::VLD4DUPdWB_register_Asm_8:
6512 case ARM::VLD4DUPdWB_register_Asm_16:
6513 case ARM::VLD4DUPdWB_register_Asm_32:
6514 case ARM::VLD4DUPqWB_register_Asm_8:
6515 case ARM::VLD4DUPqWB_register_Asm_16:
6516 case ARM::VLD4DUPqWB_register_Asm_32: {
6517 MCInst TmpInst;
6518 unsigned Spacing;
6519 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6520 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6521 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6522 Spacing));
6523 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6524 Spacing * 2));
6525 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6526 Spacing * 3));
6527 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6528 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6529 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6530 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6531 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6532 TmpInst.addOperand(Inst.getOperand(5));
6533 Inst = TmpInst;
6534 return true;
6535 }
6536
6537 // VLD4 multiple 4-element structure instructions.
Jim Grosbach8abe7e32012-01-24 00:43:17 +00006538 case ARM::VLD4dAsm_8:
6539 case ARM::VLD4dAsm_16:
6540 case ARM::VLD4dAsm_32:
6541 case ARM::VLD4qAsm_8:
6542 case ARM::VLD4qAsm_16:
6543 case ARM::VLD4qAsm_32: {
6544 MCInst TmpInst;
6545 unsigned Spacing;
6546 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6547 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6549 Spacing));
6550 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6551 Spacing * 2));
6552 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6553 Spacing * 3));
6554 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6555 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6556 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6557 TmpInst.addOperand(Inst.getOperand(4));
6558 Inst = TmpInst;
6559 return true;
6560 }
6561
6562 case ARM::VLD4dWB_fixed_Asm_8:
6563 case ARM::VLD4dWB_fixed_Asm_16:
6564 case ARM::VLD4dWB_fixed_Asm_32:
6565 case ARM::VLD4qWB_fixed_Asm_8:
6566 case ARM::VLD4qWB_fixed_Asm_16:
6567 case ARM::VLD4qWB_fixed_Asm_32: {
6568 MCInst TmpInst;
6569 unsigned Spacing;
6570 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6571 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6573 Spacing));
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6575 Spacing * 2));
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 Spacing * 3));
6578 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6579 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6580 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6581 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6582 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6583 TmpInst.addOperand(Inst.getOperand(4));
6584 Inst = TmpInst;
6585 return true;
6586 }
6587
6588 case ARM::VLD4dWB_register_Asm_8:
6589 case ARM::VLD4dWB_register_Asm_16:
6590 case ARM::VLD4dWB_register_Asm_32:
6591 case ARM::VLD4qWB_register_Asm_8:
6592 case ARM::VLD4qWB_register_Asm_16:
6593 case ARM::VLD4qWB_register_Asm_32: {
6594 MCInst TmpInst;
6595 unsigned Spacing;
6596 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6597 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6598 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6599 Spacing));
6600 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6601 Spacing * 2));
6602 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6603 Spacing * 3));
6604 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6605 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6606 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6607 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6608 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6609 TmpInst.addOperand(Inst.getOperand(5));
6610 Inst = TmpInst;
6611 return true;
6612 }
6613
Jim Grosbachd7433e22012-01-23 23:45:44 +00006614 // VST3 multiple 3-element structure instructions.
6615 case ARM::VST3dAsm_8:
6616 case ARM::VST3dAsm_16:
6617 case ARM::VST3dAsm_32:
6618 case ARM::VST3qAsm_8:
6619 case ARM::VST3qAsm_16:
6620 case ARM::VST3qAsm_32: {
6621 MCInst TmpInst;
6622 unsigned Spacing;
6623 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6624 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6625 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6626 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6627 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6628 Spacing));
6629 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6630 Spacing * 2));
6631 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6632 TmpInst.addOperand(Inst.getOperand(4));
6633 Inst = TmpInst;
6634 return true;
6635 }
6636
6637 case ARM::VST3dWB_fixed_Asm_8:
6638 case ARM::VST3dWB_fixed_Asm_16:
6639 case ARM::VST3dWB_fixed_Asm_32:
6640 case ARM::VST3qWB_fixed_Asm_8:
6641 case ARM::VST3qWB_fixed_Asm_16:
6642 case ARM::VST3qWB_fixed_Asm_32: {
6643 MCInst TmpInst;
6644 unsigned Spacing;
6645 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6646 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6647 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6648 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6649 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6650 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6651 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6652 Spacing));
6653 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6654 Spacing * 2));
6655 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6656 TmpInst.addOperand(Inst.getOperand(4));
6657 Inst = TmpInst;
6658 return true;
6659 }
6660
6661 case ARM::VST3dWB_register_Asm_8:
6662 case ARM::VST3dWB_register_Asm_16:
6663 case ARM::VST3dWB_register_Asm_32:
6664 case ARM::VST3qWB_register_Asm_8:
6665 case ARM::VST3qWB_register_Asm_16:
6666 case ARM::VST3qWB_register_Asm_32: {
6667 MCInst TmpInst;
6668 unsigned Spacing;
6669 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6670 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6671 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6672 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6673 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6674 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6675 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6676 Spacing));
6677 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6678 Spacing * 2));
6679 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6680 TmpInst.addOperand(Inst.getOperand(5));
6681 Inst = TmpInst;
6682 return true;
6683 }
6684
Jim Grosbach539aab72012-01-24 00:58:13 +00006685 // VST4 multiple 3-element structure instructions.
6686 case ARM::VST4dAsm_8:
6687 case ARM::VST4dAsm_16:
6688 case ARM::VST4dAsm_32:
6689 case ARM::VST4qAsm_8:
6690 case ARM::VST4qAsm_16:
6691 case ARM::VST4qAsm_32: {
6692 MCInst TmpInst;
6693 unsigned Spacing;
6694 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6695 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6696 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6697 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6699 Spacing));
6700 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6701 Spacing * 2));
6702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6703 Spacing * 3));
6704 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6705 TmpInst.addOperand(Inst.getOperand(4));
6706 Inst = TmpInst;
6707 return true;
6708 }
6709
6710 case ARM::VST4dWB_fixed_Asm_8:
6711 case ARM::VST4dWB_fixed_Asm_16:
6712 case ARM::VST4dWB_fixed_Asm_32:
6713 case ARM::VST4qWB_fixed_Asm_8:
6714 case ARM::VST4qWB_fixed_Asm_16:
6715 case ARM::VST4qWB_fixed_Asm_32: {
6716 MCInst TmpInst;
6717 unsigned Spacing;
6718 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6719 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6720 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6721 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6722 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6723 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 Spacing));
6726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6727 Spacing * 2));
6728 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6729 Spacing * 3));
6730 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6731 TmpInst.addOperand(Inst.getOperand(4));
6732 Inst = TmpInst;
6733 return true;
6734 }
6735
6736 case ARM::VST4dWB_register_Asm_8:
6737 case ARM::VST4dWB_register_Asm_16:
6738 case ARM::VST4dWB_register_Asm_32:
6739 case ARM::VST4qWB_register_Asm_8:
6740 case ARM::VST4qWB_register_Asm_16:
6741 case ARM::VST4qWB_register_Asm_32: {
6742 MCInst TmpInst;
6743 unsigned Spacing;
6744 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6745 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6746 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6747 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6748 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6749 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6750 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6751 Spacing));
6752 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6753 Spacing * 2));
6754 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6755 Spacing * 3));
6756 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6757 TmpInst.addOperand(Inst.getOperand(5));
6758 Inst = TmpInst;
6759 return true;
6760 }
6761
Jim Grosbacha5378eb2012-04-11 00:15:16 +00006762 // Handle encoding choice for the shift-immediate instructions.
6763 case ARM::t2LSLri:
6764 case ARM::t2LSRri:
6765 case ARM::t2ASRri: {
6766 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6767 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6768 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6769 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6770 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6771 unsigned NewOpc;
6772 switch (Inst.getOpcode()) {
6773 default: llvm_unreachable("unexpected opcode");
6774 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6775 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6776 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6777 }
6778 // The Thumb1 operands aren't in the same order. Awesome, eh?
6779 MCInst TmpInst;
6780 TmpInst.setOpcode(NewOpc);
6781 TmpInst.addOperand(Inst.getOperand(0));
6782 TmpInst.addOperand(Inst.getOperand(5));
6783 TmpInst.addOperand(Inst.getOperand(1));
6784 TmpInst.addOperand(Inst.getOperand(2));
6785 TmpInst.addOperand(Inst.getOperand(3));
6786 TmpInst.addOperand(Inst.getOperand(4));
6787 Inst = TmpInst;
6788 return true;
6789 }
6790 return false;
6791 }
6792
Jim Grosbach863d2af2011-12-13 22:45:11 +00006793 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00006794 case ARM::t2MOVsr:
6795 case ARM::t2MOVSsr: {
6796 // Which instruction to expand to depends on the CCOut operand and
6797 // whether we're in an IT block if the register operands are low
6798 // registers.
6799 bool isNarrow = false;
6800 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6801 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6802 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6803 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6804 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6805 isNarrow = true;
6806 MCInst TmpInst;
6807 unsigned newOpc;
6808 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6809 default: llvm_unreachable("unexpected opcode!");
6810 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6811 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6812 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6813 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6814 }
6815 TmpInst.setOpcode(newOpc);
6816 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6817 if (isNarrow)
6818 TmpInst.addOperand(MCOperand::CreateReg(
6819 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6820 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6821 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6822 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6823 TmpInst.addOperand(Inst.getOperand(5));
6824 if (!isNarrow)
6825 TmpInst.addOperand(MCOperand::CreateReg(
6826 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6827 Inst = TmpInst;
6828 return true;
6829 }
Jim Grosbach863d2af2011-12-13 22:45:11 +00006830 case ARM::t2MOVsi:
6831 case ARM::t2MOVSsi: {
6832 // Which instruction to expand to depends on the CCOut operand and
6833 // whether we're in an IT block if the register operands are low
6834 // registers.
6835 bool isNarrow = false;
6836 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6837 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6838 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6839 isNarrow = true;
6840 MCInst TmpInst;
6841 unsigned newOpc;
6842 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6843 default: llvm_unreachable("unexpected opcode!");
6844 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6845 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6846 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6847 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach520dc782011-12-21 21:04:19 +00006848 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006849 }
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006850 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6851 if (Amount == 32) Amount = 0;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006852 TmpInst.setOpcode(newOpc);
6853 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6854 if (isNarrow)
6855 TmpInst.addOperand(MCOperand::CreateReg(
6856 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6857 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach520dc782011-12-21 21:04:19 +00006858 if (newOpc != ARM::t2RRX)
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006859 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach863d2af2011-12-13 22:45:11 +00006860 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6861 TmpInst.addOperand(Inst.getOperand(4));
6862 if (!isNarrow)
6863 TmpInst.addOperand(MCOperand::CreateReg(
6864 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6865 Inst = TmpInst;
6866 return true;
6867 }
6868 // Handle the ARM mode MOV complex aliases.
Jim Grosbach23f22072011-11-16 18:31:45 +00006869 case ARM::ASRr:
6870 case ARM::LSRr:
6871 case ARM::LSLr:
6872 case ARM::RORr: {
6873 ARM_AM::ShiftOpc ShiftTy;
6874 switch(Inst.getOpcode()) {
6875 default: llvm_unreachable("unexpected opcode!");
6876 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6877 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6878 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6879 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6880 }
Jim Grosbach23f22072011-11-16 18:31:45 +00006881 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6882 MCInst TmpInst;
6883 TmpInst.setOpcode(ARM::MOVsr);
6884 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6885 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6886 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6887 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6888 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6889 TmpInst.addOperand(Inst.getOperand(4));
6890 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6891 Inst = TmpInst;
6892 return true;
6893 }
Jim Grosbachee10ff82011-11-10 19:18:01 +00006894 case ARM::ASRi:
6895 case ARM::LSRi:
6896 case ARM::LSLi:
6897 case ARM::RORi: {
6898 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006899 switch(Inst.getOpcode()) {
6900 default: llvm_unreachable("unexpected opcode!");
6901 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6902 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6903 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6904 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6905 }
6906 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach48b368b2011-11-16 19:05:59 +00006907 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachee10ff82011-11-10 19:18:01 +00006908 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonb56e4112012-04-25 18:00:18 +00006909 // A shift by 32 should be encoded as 0 when permitted
6910 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6911 Amt = 0;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006912 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006913 MCInst TmpInst;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006914 TmpInst.setOpcode(Opc);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006915 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6916 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachee10ff82011-11-10 19:18:01 +00006917 if (Opc == ARM::MOVsi)
6918 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach71810ab2011-11-10 16:44:55 +00006919 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6920 TmpInst.addOperand(Inst.getOperand(4));
6921 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6922 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006923 return true;
Jim Grosbach71810ab2011-11-10 16:44:55 +00006924 }
Jim Grosbach48b368b2011-11-16 19:05:59 +00006925 case ARM::RRXi: {
6926 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6927 MCInst TmpInst;
6928 TmpInst.setOpcode(ARM::MOVsi);
6929 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6930 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6931 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6932 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6933 TmpInst.addOperand(Inst.getOperand(3));
6934 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6935 Inst = TmpInst;
6936 return true;
6937 }
Jim Grosbach0352b462011-11-10 23:58:34 +00006938 case ARM::t2LDMIA_UPD: {
6939 // If this is a load of a single register, then we should use
6940 // a post-indexed LDR instruction instead, per the ARM ARM.
6941 if (Inst.getNumOperands() != 5)
6942 return false;
6943 MCInst TmpInst;
6944 TmpInst.setOpcode(ARM::t2LDR_POST);
6945 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6946 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6947 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6948 TmpInst.addOperand(MCOperand::CreateImm(4));
6949 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6950 TmpInst.addOperand(Inst.getOperand(3));
6951 Inst = TmpInst;
6952 return true;
6953 }
6954 case ARM::t2STMDB_UPD: {
6955 // If this is a store of a single register, then we should use
6956 // a pre-indexed STR instruction instead, per the ARM ARM.
6957 if (Inst.getNumOperands() != 5)
6958 return false;
6959 MCInst TmpInst;
6960 TmpInst.setOpcode(ARM::t2STR_PRE);
6961 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6962 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6963 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6964 TmpInst.addOperand(MCOperand::CreateImm(-4));
6965 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6966 TmpInst.addOperand(Inst.getOperand(3));
6967 Inst = TmpInst;
6968 return true;
6969 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00006970 case ARM::LDMIA_UPD:
6971 // If this is a load of a single register via a 'pop', then we should use
6972 // a post-indexed LDR instruction instead, per the ARM ARM.
6973 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6974 Inst.getNumOperands() == 5) {
6975 MCInst TmpInst;
6976 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6977 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6978 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6979 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6980 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6981 TmpInst.addOperand(MCOperand::CreateImm(4));
6982 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6983 TmpInst.addOperand(Inst.getOperand(3));
6984 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006985 return true;
Jim Grosbachf8fce712011-08-11 17:35:48 +00006986 }
6987 break;
Jim Grosbachf6713912011-08-11 18:07:11 +00006988 case ARM::STMDB_UPD:
6989 // If this is a store of a single register via a 'push', then we should use
6990 // a pre-indexed STR instruction instead, per the ARM ARM.
6991 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6992 Inst.getNumOperands() == 5) {
6993 MCInst TmpInst;
6994 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6995 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6996 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6997 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6998 TmpInst.addOperand(MCOperand::CreateImm(-4));
6999 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7000 TmpInst.addOperand(Inst.getOperand(3));
7001 Inst = TmpInst;
7002 }
7003 break;
Jim Grosbachda847862011-12-05 21:06:26 +00007004 case ARM::t2ADDri12:
7005 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7006 // mnemonic was used (not "addw"), encoding T3 is preferred.
7007 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7008 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7009 break;
7010 Inst.setOpcode(ARM::t2ADDri);
7011 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7012 break;
7013 case ARM::t2SUBri12:
7014 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7015 // mnemonic was used (not "subw"), encoding T3 is preferred.
7016 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7017 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7018 break;
7019 Inst.setOpcode(ARM::t2SUBri);
7020 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7021 break;
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007022 case ARM::tADDi8:
Jim Grosbach0f3abd82011-08-31 17:07:33 +00007023 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7024 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7025 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7026 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007027 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007028 Inst.setOpcode(ARM::tADDi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007029 return true;
7030 }
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007031 break;
Jim Grosbachf67e8552011-09-16 22:58:42 +00007032 case ARM::tSUBi8:
7033 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7034 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7035 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7036 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007037 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachf67e8552011-09-16 22:58:42 +00007038 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007039 return true;
7040 }
Jim Grosbachf67e8552011-09-16 22:58:42 +00007041 break;
Jim Grosbach2d30d942012-03-30 17:20:40 +00007042 case ARM::t2ADDri:
7043 case ARM::t2SUBri: {
7044 // If the destination and first source operand are the same, and
7045 // the flags are compatible with the current IT status, use encoding T2
7046 // instead of T3. For compatibility with the system 'as'. Make sure the
7047 // wide encoding wasn't explicit.
7048 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach8f1148b2012-03-30 18:39:43 +00007049 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbach2d30d942012-03-30 17:20:40 +00007050 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7051 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7052 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7053 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7054 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7055 break;
7056 MCInst TmpInst;
7057 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7058 ARM::tADDi8 : ARM::tSUBi8);
7059 TmpInst.addOperand(Inst.getOperand(0));
7060 TmpInst.addOperand(Inst.getOperand(5));
7061 TmpInst.addOperand(Inst.getOperand(0));
7062 TmpInst.addOperand(Inst.getOperand(2));
7063 TmpInst.addOperand(Inst.getOperand(3));
7064 TmpInst.addOperand(Inst.getOperand(4));
7065 Inst = TmpInst;
7066 return true;
7067 }
Jim Grosbach927b9df2011-12-05 22:16:39 +00007068 case ARM::t2ADDrr: {
7069 // If the destination and first source operand are the same, and
7070 // there's no setting of the flags, use encoding T2 instead of T3.
7071 // Note that this is only for ADD, not SUB. This mirrors the system
7072 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7073 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7074 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbach713c7022011-12-05 22:27:04 +00007075 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7076 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbach927b9df2011-12-05 22:16:39 +00007077 break;
7078 MCInst TmpInst;
7079 TmpInst.setOpcode(ARM::tADDhirr);
7080 TmpInst.addOperand(Inst.getOperand(0));
7081 TmpInst.addOperand(Inst.getOperand(0));
7082 TmpInst.addOperand(Inst.getOperand(2));
7083 TmpInst.addOperand(Inst.getOperand(3));
7084 TmpInst.addOperand(Inst.getOperand(4));
7085 Inst = TmpInst;
7086 return true;
7087 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00007088 case ARM::tADDrSP: {
7089 // If the non-SP source operand and the destination operand are not the
7090 // same, we need to use the 32-bit encoding if it's available.
7091 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7092 Inst.setOpcode(ARM::t2ADDrr);
7093 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7094 return true;
7095 }
7096 break;
7097 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007098 case ARM::tB:
7099 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007100 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007101 Inst.setOpcode(ARM::tBcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007102 return true;
7103 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007104 break;
7105 case ARM::t2B:
7106 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007107 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007108 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007109 return true;
7110 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007111 break;
Jim Grosbachc0755102011-08-31 21:17:31 +00007112 case ARM::t2Bcc:
Jim Grosbacha1109882011-09-02 23:22:08 +00007113 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007114 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbachc0755102011-08-31 21:17:31 +00007115 Inst.setOpcode(ARM::t2B);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007116 return true;
7117 }
Jim Grosbachc0755102011-08-31 21:17:31 +00007118 break;
Jim Grosbach395b4532011-08-17 22:57:40 +00007119 case ARM::tBcc:
7120 // If the conditional is AL, we really want tB.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007121 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbach395b4532011-08-17 22:57:40 +00007122 Inst.setOpcode(ARM::tB);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007123 return true;
7124 }
Jim Grosbach3ce23d32011-08-18 16:08:39 +00007125 break;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007126 case ARM::tLDMIA: {
7127 // If the register list contains any high registers, or if the writeback
7128 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7129 // instead if we're in Thumb2. Otherwise, this should have generated
7130 // an error in validateInstruction().
7131 unsigned Rn = Inst.getOperand(0).getReg();
7132 bool hasWritebackToken =
7133 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7134 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7135 bool listContainsBase;
7136 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7137 (!listContainsBase && !hasWritebackToken) ||
7138 (listContainsBase && hasWritebackToken)) {
7139 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7140 assert (isThumbTwo());
7141 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7142 // If we're switching to the updating version, we need to insert
7143 // the writeback tied operand.
7144 if (hasWritebackToken)
7145 Inst.insert(Inst.begin(),
7146 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007147 return true;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007148 }
7149 break;
7150 }
Jim Grosbach8213c962011-09-16 20:50:13 +00007151 case ARM::tSTMIA_UPD: {
7152 // If the register list contains any high registers, we need to use
7153 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7154 // should have generated an error in validateInstruction().
7155 unsigned Rn = Inst.getOperand(0).getReg();
7156 bool listContainsBase;
7157 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7158 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7159 assert (isThumbTwo());
7160 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007161 return true;
Jim Grosbach8213c962011-09-16 20:50:13 +00007162 }
7163 break;
7164 }
Jim Grosbach54026372011-11-10 23:17:11 +00007165 case ARM::tPOP: {
7166 bool listContainsBase;
7167 // If the register list contains any high registers, we need to use
7168 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7169 // should have generated an error in validateInstruction().
7170 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007171 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007172 assert (isThumbTwo());
7173 Inst.setOpcode(ARM::t2LDMIA_UPD);
7174 // Add the base register and writeback operands.
7175 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7176 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007177 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007178 }
7179 case ARM::tPUSH: {
7180 bool listContainsBase;
7181 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007182 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007183 assert (isThumbTwo());
7184 Inst.setOpcode(ARM::t2STMDB_UPD);
7185 // Add the base register and writeback operands.
7186 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7187 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007188 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007189 }
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007190 case ARM::t2MOVi: {
7191 // If we can use the 16-bit encoding and the user didn't explicitly
7192 // request the 32-bit variant, transform it here.
7193 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbachc0164f82012-03-30 16:31:31 +00007194 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbachc2d31642011-09-14 19:12:11 +00007195 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7196 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7197 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007198 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7199 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7200 // The operands aren't in the same order for tMOVi8...
7201 MCInst TmpInst;
7202 TmpInst.setOpcode(ARM::tMOVi8);
7203 TmpInst.addOperand(Inst.getOperand(0));
7204 TmpInst.addOperand(Inst.getOperand(4));
7205 TmpInst.addOperand(Inst.getOperand(1));
7206 TmpInst.addOperand(Inst.getOperand(2));
7207 TmpInst.addOperand(Inst.getOperand(3));
7208 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007209 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007210 }
7211 break;
7212 }
7213 case ARM::t2MOVr: {
7214 // If we can use the 16-bit encoding and the user didn't explicitly
7215 // request the 32-bit variant, transform it here.
7216 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7217 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7218 Inst.getOperand(2).getImm() == ARMCC::AL &&
7219 Inst.getOperand(4).getReg() == ARM::CPSR &&
7220 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7221 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7222 // The operands aren't the same for tMOV[S]r... (no cc_out)
7223 MCInst TmpInst;
7224 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7225 TmpInst.addOperand(Inst.getOperand(0));
7226 TmpInst.addOperand(Inst.getOperand(1));
7227 TmpInst.addOperand(Inst.getOperand(2));
7228 TmpInst.addOperand(Inst.getOperand(3));
7229 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007230 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007231 }
7232 break;
7233 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007234 case ARM::t2SXTH:
Jim Grosbach50f1c372011-09-20 00:46:54 +00007235 case ARM::t2SXTB:
7236 case ARM::t2UXTH:
7237 case ARM::t2UXTB: {
Jim Grosbach326efe52011-09-19 20:29:33 +00007238 // If we can use the 16-bit encoding and the user didn't explicitly
7239 // request the 32-bit variant, transform it here.
7240 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7241 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7242 Inst.getOperand(2).getImm() == 0 &&
7243 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7244 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbach50f1c372011-09-20 00:46:54 +00007245 unsigned NewOpc;
7246 switch (Inst.getOpcode()) {
7247 default: llvm_unreachable("Illegal opcode!");
7248 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7249 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7250 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7251 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7252 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007253 // The operands aren't the same for thumb1 (no rotate operand).
7254 MCInst TmpInst;
7255 TmpInst.setOpcode(NewOpc);
7256 TmpInst.addOperand(Inst.getOperand(0));
7257 TmpInst.addOperand(Inst.getOperand(1));
7258 TmpInst.addOperand(Inst.getOperand(3));
7259 TmpInst.addOperand(Inst.getOperand(4));
7260 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007261 return true;
Jim Grosbach326efe52011-09-19 20:29:33 +00007262 }
7263 break;
7264 }
Jim Grosbach04b5d932011-12-20 00:59:38 +00007265 case ARM::MOVsi: {
7266 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonb56e4112012-04-25 18:00:18 +00007267 // rrx shifts and asr/lsr of #32 is encoded as 0
7268 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7269 return false;
Jim Grosbach04b5d932011-12-20 00:59:38 +00007270 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7271 // Shifting by zero is accepted as a vanilla 'MOVr'
7272 MCInst TmpInst;
7273 TmpInst.setOpcode(ARM::MOVr);
7274 TmpInst.addOperand(Inst.getOperand(0));
7275 TmpInst.addOperand(Inst.getOperand(1));
7276 TmpInst.addOperand(Inst.getOperand(3));
7277 TmpInst.addOperand(Inst.getOperand(4));
7278 TmpInst.addOperand(Inst.getOperand(5));
7279 Inst = TmpInst;
7280 return true;
7281 }
7282 return false;
7283 }
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007284 case ARM::ANDrsi:
7285 case ARM::ORRrsi:
7286 case ARM::EORrsi:
7287 case ARM::BICrsi:
7288 case ARM::SUBrsi:
7289 case ARM::ADDrsi: {
7290 unsigned newOpc;
7291 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7292 if (SOpc == ARM_AM::rrx) return false;
7293 switch (Inst.getOpcode()) {
Craig Topperbc219812012-02-07 02:50:20 +00007294 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007295 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7296 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7297 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7298 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7299 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7300 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7301 }
7302 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton8ed97ef2012-07-09 16:31:14 +00007303 // The exception is for right shifts, where 0 == 32
7304 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7305 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007306 MCInst TmpInst;
7307 TmpInst.setOpcode(newOpc);
7308 TmpInst.addOperand(Inst.getOperand(0));
7309 TmpInst.addOperand(Inst.getOperand(1));
7310 TmpInst.addOperand(Inst.getOperand(2));
7311 TmpInst.addOperand(Inst.getOperand(4));
7312 TmpInst.addOperand(Inst.getOperand(5));
7313 TmpInst.addOperand(Inst.getOperand(6));
7314 Inst = TmpInst;
7315 return true;
7316 }
7317 return false;
7318 }
Jim Grosbach74423e32012-01-25 19:52:01 +00007319 case ARM::ITasm:
Jim Grosbach89df9962011-08-26 21:43:41 +00007320 case ARM::t2IT: {
7321 // The mask bits for all but the first condition are represented as
7322 // the low bit of the condition code value implies 't'. We currently
7323 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Barton4d2f0772012-04-27 08:42:59 +00007324 // of the condition code is zero.
Jim Grosbach89df9962011-08-26 21:43:41 +00007325 MCOperand &MO = Inst.getOperand(1);
7326 unsigned Mask = MO.getImm();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007327 unsigned OrigMask = Mask;
7328 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach89df9962011-08-26 21:43:41 +00007329 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach89df9962011-08-26 21:43:41 +00007330 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7331 for (unsigned i = 3; i != TZ; --i)
7332 Mask ^= 1 << i;
Richard Barton4d2f0772012-04-27 08:42:59 +00007333 }
Jim Grosbach89df9962011-08-26 21:43:41 +00007334 MO.setImm(Mask);
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007335
7336 // Set up the IT block state according to the IT instruction we just
7337 // matched.
7338 assert(!inITBlock() && "nested IT blocks?!");
7339 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7340 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7341 ITState.CurPosition = 0;
7342 ITState.FirstCond = true;
Jim Grosbach89df9962011-08-26 21:43:41 +00007343 break;
7344 }
Richard Barton2b6652f2012-07-09 16:12:24 +00007345 case ARM::t2LSLrr:
7346 case ARM::t2LSRrr:
7347 case ARM::t2ASRrr:
7348 case ARM::t2SBCrr:
7349 case ARM::t2RORrr:
7350 case ARM::t2BICrr:
7351 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007352 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007353 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7354 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7355 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton874b8632012-07-09 18:30:56 +00007356 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7357 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007358 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7359 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7360 unsigned NewOpc;
7361 switch (Inst.getOpcode()) {
7362 default: llvm_unreachable("unexpected opcode");
7363 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7364 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7365 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7366 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7367 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7368 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7369 }
7370 MCInst TmpInst;
7371 TmpInst.setOpcode(NewOpc);
7372 TmpInst.addOperand(Inst.getOperand(0));
7373 TmpInst.addOperand(Inst.getOperand(5));
7374 TmpInst.addOperand(Inst.getOperand(1));
7375 TmpInst.addOperand(Inst.getOperand(2));
7376 TmpInst.addOperand(Inst.getOperand(3));
7377 TmpInst.addOperand(Inst.getOperand(4));
7378 Inst = TmpInst;
7379 return true;
7380 }
7381 return false;
7382 }
7383 case ARM::t2ANDrr:
7384 case ARM::t2EORrr:
7385 case ARM::t2ADCrr:
7386 case ARM::t2ORRrr:
7387 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007388 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007389 // These instructions are special in that they are commutable, so shorter encodings
7390 // are available more often.
7391 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7392 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7393 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7394 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton874b8632012-07-09 18:30:56 +00007395 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7396 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007397 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7398 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7399 unsigned NewOpc;
7400 switch (Inst.getOpcode()) {
7401 default: llvm_unreachable("unexpected opcode");
7402 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7403 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7404 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7405 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7406 }
7407 MCInst TmpInst;
7408 TmpInst.setOpcode(NewOpc);
7409 TmpInst.addOperand(Inst.getOperand(0));
7410 TmpInst.addOperand(Inst.getOperand(5));
7411 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7412 TmpInst.addOperand(Inst.getOperand(1));
7413 TmpInst.addOperand(Inst.getOperand(2));
7414 } else {
7415 TmpInst.addOperand(Inst.getOperand(2));
7416 TmpInst.addOperand(Inst.getOperand(1));
7417 }
7418 TmpInst.addOperand(Inst.getOperand(3));
7419 TmpInst.addOperand(Inst.getOperand(4));
7420 Inst = TmpInst;
7421 return true;
7422 }
7423 return false;
7424 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00007425 }
Jim Grosbach83ec8772011-11-10 23:42:14 +00007426 return false;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007427}
7428
Jim Grosbach47a0d522011-08-16 20:45:50 +00007429unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7430 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7431 // suffix depending on whether they're in an IT block or not.
Jim Grosbach194bd892011-08-16 22:20:01 +00007432 unsigned Opc = Inst.getOpcode();
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00007433 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach47a0d522011-08-16 20:45:50 +00007434 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7435 assert(MCID.hasOptionalDef() &&
7436 "optionally flag setting instruction missing optional def operand");
7437 assert(MCID.NumOperands == Inst.getNumOperands() &&
7438 "operand count mismatch!");
7439 // Find the optional-def operand (cc_out).
7440 unsigned OpNo;
7441 for (OpNo = 0;
7442 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7443 ++OpNo)
7444 ;
7445 // If we're parsing Thumb1, reject it completely.
7446 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7447 return Match_MnemonicFail;
7448 // If we're parsing Thumb2, which form is legal depends on whether we're
7449 // in an IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007450 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7451 !inITBlock())
Jim Grosbach47a0d522011-08-16 20:45:50 +00007452 return Match_RequiresITBlock;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007453 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7454 inITBlock())
7455 return Match_RequiresNotITBlock;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007456 }
Jim Grosbach194bd892011-08-16 22:20:01 +00007457 // Some high-register supporting Thumb1 encodings only allow both registers
7458 // to be from r0-r7 when in Thumb2.
7459 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7460 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7461 isARMLowRegister(Inst.getOperand(2).getReg()))
7462 return Match_RequiresThumb2;
7463 // Others only require ARMv6 or later.
Jim Grosbach4ec6e882011-08-19 20:46:54 +00007464 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbach194bd892011-08-16 22:20:01 +00007465 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7466 isARMLowRegister(Inst.getOperand(1).getReg()))
7467 return Match_RequiresV6;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007468 return Match_Success;
7469}
7470
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007471static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007472bool ARMAsmParser::
7473MatchAndEmitInstruction(SMLoc IDLoc,
7474 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7475 MCStreamer &Out) {
7476 MCInst Inst;
7477 unsigned ErrorInfo;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007478 unsigned MatchResult;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007479 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007480 switch (MatchResult) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007481 default: break;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007482 case Match_Success:
Jim Grosbach189610f2011-07-26 18:25:39 +00007483 // Context sensitive operand constraints aren't handled by the matcher,
7484 // so check them here.
Jim Grosbacha1109882011-09-02 23:22:08 +00007485 if (validateInstruction(Inst, Operands)) {
7486 // Still progress the IT block, otherwise one wrong condition causes
7487 // nasty cascading errors.
7488 forwardITPosition();
Jim Grosbach189610f2011-07-26 18:25:39 +00007489 return true;
Jim Grosbacha1109882011-09-02 23:22:08 +00007490 }
Jim Grosbach189610f2011-07-26 18:25:39 +00007491
Jim Grosbachf8fce712011-08-11 17:35:48 +00007492 // Some instructions need post-processing to, for example, tweak which
Jim Grosbach83ec8772011-11-10 23:42:14 +00007493 // encoding is selected. Loop on it while changes happen so the
7494 // individual transformations can chain off each other. E.g.,
7495 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7496 while (processInstruction(Inst, Operands))
7497 ;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007498
Jim Grosbacha1109882011-09-02 23:22:08 +00007499 // Only move forward at the very end so that everything in validate
7500 // and process gets a consistent answer about whether we're in an IT
7501 // block.
7502 forwardITPosition();
7503
Jim Grosbach74423e32012-01-25 19:52:01 +00007504 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7505 // doesn't actually encode.
7506 if (Inst.getOpcode() == ARM::ITasm)
7507 return false;
7508
Jim Grosbach42e6bd32012-01-26 23:20:15 +00007509 Inst.setLoc(IDLoc);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007510 Out.EmitInstruction(Inst);
7511 return false;
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007512 case Match_MissingFeature: {
7513 assert(ErrorInfo && "Unknown missing feature!");
7514 // Special case the error message for the very common case where only
7515 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7516 std::string Msg = "instruction requires:";
7517 unsigned Mask = 1;
7518 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7519 if (ErrorInfo & Mask) {
7520 Msg += " ";
7521 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7522 }
7523 Mask <<= 1;
7524 }
7525 return Error(IDLoc, Msg);
7526 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007527 case Match_InvalidOperand: {
7528 SMLoc ErrorLoc = IDLoc;
7529 if (ErrorInfo != ~0U) {
7530 if (ErrorInfo >= Operands.size())
7531 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00007532
Chris Lattnere73d4f82010-10-28 21:41:58 +00007533 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7534 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7535 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007536
Chris Lattnere73d4f82010-10-28 21:41:58 +00007537 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007538 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007539 case Match_MnemonicFail:
Benjamin Kramer362a05a2012-04-15 17:04:27 +00007540 return Error(IDLoc, "invalid instruction",
7541 ((ARMOperand*)Operands[0])->getLocRange());
Daniel Dunbarb4129152011-02-04 17:12:23 +00007542 case Match_ConversionFail:
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00007543 // The converter function will have already emitted a diagnostic.
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00007544 return true;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007545 case Match_RequiresNotITBlock:
7546 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach47a0d522011-08-16 20:45:50 +00007547 case Match_RequiresITBlock:
7548 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbach194bd892011-08-16 22:20:01 +00007549 case Match_RequiresV6:
7550 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7551 case Match_RequiresThumb2:
7552 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach70c9bf32012-06-22 23:56:48 +00007553 case Match_ImmRange0_15: {
7554 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7555 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7556 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7557 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007558 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007559
Eric Christopherc223e2b2010-10-29 09:26:59 +00007560 llvm_unreachable("Implement any new match types added!");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007561}
7562
Jim Grosbach1355cf12011-07-26 17:10:22 +00007563/// parseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007564bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7565 StringRef IDVal = DirectiveID.getIdentifier();
7566 if (IDVal == ".word")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007567 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007568 else if (IDVal == ".thumb")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007569 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach9a70df92011-12-07 18:04:19 +00007570 else if (IDVal == ".arm")
7571 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007572 else if (IDVal == ".thumb_func")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007573 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007574 else if (IDVal == ".code")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007575 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007576 else if (IDVal == ".syntax")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007577 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbacha39cda72011-12-14 02:16:11 +00007578 else if (IDVal == ".unreq")
7579 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kimd7c9e082011-12-20 17:38:12 +00007580 else if (IDVal == ".arch")
7581 return parseDirectiveArch(DirectiveID.getLoc());
7582 else if (IDVal == ".eabi_attribute")
7583 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007584 return true;
7585}
7586
Jim Grosbach1355cf12011-07-26 17:10:22 +00007587/// parseDirectiveWord
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007588/// ::= .word [ expression (, expression)* ]
Jim Grosbach1355cf12011-07-26 17:10:22 +00007589bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007590 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7591 for (;;) {
7592 const MCExpr *Value;
7593 if (getParser().ParseExpression(Value))
7594 return true;
7595
Chris Lattneraaec2052010-01-19 19:46:13 +00007596 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007597
7598 if (getLexer().is(AsmToken::EndOfStatement))
7599 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00007600
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007601 // FIXME: Improve diagnostic.
7602 if (getLexer().isNot(AsmToken::Comma))
7603 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007604 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007605 }
7606 }
7607
Sean Callananb9a25b72010-01-19 20:27:46 +00007608 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007609 return false;
7610}
7611
Jim Grosbach1355cf12011-07-26 17:10:22 +00007612/// parseDirectiveThumb
Kevin Enderby515d5092009-10-15 20:48:48 +00007613/// ::= .thumb
Jim Grosbach1355cf12011-07-26 17:10:22 +00007614bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby515d5092009-10-15 20:48:48 +00007615 if (getLexer().isNot(AsmToken::EndOfStatement))
7616 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007617 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007618
Jim Grosbach9a70df92011-12-07 18:04:19 +00007619 if (!isThumb())
7620 SwitchMode();
7621 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7622 return false;
7623}
7624
7625/// parseDirectiveARM
7626/// ::= .arm
7627bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7628 if (getLexer().isNot(AsmToken::EndOfStatement))
7629 return Error(L, "unexpected token in directive");
7630 Parser.Lex();
7631
7632 if (isThumb())
7633 SwitchMode();
7634 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby515d5092009-10-15 20:48:48 +00007635 return false;
7636}
7637
Jim Grosbach1355cf12011-07-26 17:10:22 +00007638/// parseDirectiveThumbFunc
Kevin Enderby515d5092009-10-15 20:48:48 +00007639/// ::= .thumbfunc symbol_name
Jim Grosbach1355cf12011-07-26 17:10:22 +00007640bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00007641 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7642 bool isMachO = MAI.hasSubsectionsViaSymbols();
7643 StringRef Name;
Jim Grosbachde4d8392011-12-21 22:30:16 +00007644 bool needFuncName = true;
Rafael Espindola64695402011-05-16 16:17:21 +00007645
Jim Grosbachde4d8392011-12-21 22:30:16 +00007646 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindola64695402011-05-16 16:17:21 +00007647 // ELF doesn't
7648 if (isMachO) {
7649 const AsmToken &Tok = Parser.getTok();
Jim Grosbachde4d8392011-12-21 22:30:16 +00007650 if (Tok.isNot(AsmToken::EndOfStatement)) {
7651 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7652 return Error(L, "unexpected token in .thumb_func directive");
7653 Name = Tok.getIdentifier();
7654 Parser.Lex(); // Consume the identifier token.
7655 needFuncName = false;
7656 }
Rafael Espindola64695402011-05-16 16:17:21 +00007657 }
7658
Jim Grosbachde4d8392011-12-21 22:30:16 +00007659 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby515d5092009-10-15 20:48:48 +00007660 return Error(L, "unexpected token in directive");
Jim Grosbachde4d8392011-12-21 22:30:16 +00007661
7662 // Eat the end of statement and any blank lines that follow.
7663 while (getLexer().is(AsmToken::EndOfStatement))
7664 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007665
Rafael Espindola64695402011-05-16 16:17:21 +00007666 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbachde4d8392011-12-21 22:30:16 +00007667 // We really should be checking the next symbol definition even if there's
7668 // stuff in between.
7669 if (needFuncName) {
Jim Grosbachd475f862011-11-10 20:48:53 +00007670 Name = Parser.getTok().getIdentifier();
Rafael Espindola64695402011-05-16 16:17:21 +00007671 }
7672
Jim Grosbach642fc9c2010-11-05 22:33:53 +00007673 // Mark symbol as a thumb symbol.
7674 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7675 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00007676 return false;
7677}
7678
Jim Grosbach1355cf12011-07-26 17:10:22 +00007679/// parseDirectiveSyntax
Kevin Enderby515d5092009-10-15 20:48:48 +00007680/// ::= .syntax unified | divided
Jim Grosbach1355cf12011-07-26 17:10:22 +00007681bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007682 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007683 if (Tok.isNot(AsmToken::Identifier))
7684 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00007685 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00007686 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00007687 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007688 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00007689 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00007690 else
7691 return Error(L, "unrecognized syntax mode in .syntax directive");
7692
7693 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007694 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007695 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007696
7697 // TODO tell the MC streamer the mode
7698 // getParser().getStreamer().Emit???();
7699 return false;
7700}
7701
Jim Grosbach1355cf12011-07-26 17:10:22 +00007702/// parseDirectiveCode
Kevin Enderby515d5092009-10-15 20:48:48 +00007703/// ::= .code 16 | 32
Jim Grosbach1355cf12011-07-26 17:10:22 +00007704bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007705 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007706 if (Tok.isNot(AsmToken::Integer))
7707 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00007708 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00007709 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00007710 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007711 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00007712 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007713 else
7714 return Error(L, "invalid operand to .code directive");
7715
7716 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007717 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007718 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007719
Evan Cheng32869202011-07-08 22:36:29 +00007720 if (Val == 16) {
Jim Grosbach98447da2011-09-06 18:46:23 +00007721 if (!isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007722 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007723 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng32869202011-07-08 22:36:29 +00007724 } else {
Jim Grosbach98447da2011-09-06 18:46:23 +00007725 if (isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007726 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007727 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Chengeb0caa12011-07-08 22:49:55 +00007728 }
Jim Grosbach2a301702010-11-05 22:40:53 +00007729
Kevin Enderby515d5092009-10-15 20:48:48 +00007730 return false;
7731}
7732
Jim Grosbacha39cda72011-12-14 02:16:11 +00007733/// parseDirectiveReq
7734/// ::= name .req registername
7735bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7736 Parser.Lex(); // Eat the '.req' token.
7737 unsigned Reg;
7738 SMLoc SRegLoc, ERegLoc;
7739 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7740 Parser.EatToEndOfStatement();
7741 return Error(SRegLoc, "register name expected");
7742 }
7743
7744 // Shouldn't be anything else.
7745 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7746 Parser.EatToEndOfStatement();
7747 return Error(Parser.getTok().getLoc(),
7748 "unexpected input in .req directive.");
7749 }
7750
7751 Parser.Lex(); // Consume the EndOfStatement
7752
7753 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7754 return Error(SRegLoc, "redefinition of '" + Name +
7755 "' does not match original.");
7756
7757 return false;
7758}
7759
7760/// parseDirectiveUneq
7761/// ::= .unreq registername
7762bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7763 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7764 Parser.EatToEndOfStatement();
7765 return Error(L, "unexpected input in .unreq directive.");
7766 }
7767 RegisterReqs.erase(Parser.getTok().getIdentifier());
7768 Parser.Lex(); // Eat the identifier.
7769 return false;
7770}
7771
Jason W Kimd7c9e082011-12-20 17:38:12 +00007772/// parseDirectiveArch
7773/// ::= .arch token
7774bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7775 return true;
7776}
7777
7778/// parseDirectiveEabiAttr
7779/// ::= .eabi_attribute int, int
7780bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7781 return true;
7782}
7783
Sean Callanan90b70972010-04-07 20:29:34 +00007784extern "C" void LLVMInitializeARMAsmLexer();
7785
Kevin Enderby9c41fa82009-10-30 22:55:57 +00007786/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007787extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng94b95502011-07-26 00:24:13 +00007788 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7789 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00007790 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007791}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007792
Chris Lattner0692ee62010-09-06 19:11:01 +00007793#define GET_REGISTER_MATCHER
Craig Topper8030e1a2012-04-25 06:56:34 +00007794#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner0692ee62010-09-06 19:11:01 +00007795#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007796#include "ARMGenAsmMatcher.inc"