blob: 6fe6356c93128734a97ed03d26dbf92015a1557a [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();
Richard Bartonb6918202012-06-27 09:36:19 +00003282 if (!Tok.is(AsmToken::Identifier))
3283 return MatchOperand_NoMatch;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003284 StringRef OptStr = Tok.getString();
3285
Richard Barton4acefe12012-06-27 09:48:23 +00003286 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003287 .Case("sy", ARM_MB::SY)
3288 .Case("st", ARM_MB::ST)
Jim Grosbach032434d2011-07-13 23:40:38 +00003289 .Case("sh", ARM_MB::ISH)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003290 .Case("ish", ARM_MB::ISH)
Jim Grosbach032434d2011-07-13 23:40:38 +00003291 .Case("shst", ARM_MB::ISHST)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003292 .Case("ishst", ARM_MB::ISHST)
3293 .Case("nsh", ARM_MB::NSH)
Jim Grosbach032434d2011-07-13 23:40:38 +00003294 .Case("un", ARM_MB::NSH)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003295 .Case("nshst", ARM_MB::NSHST)
Jim Grosbach032434d2011-07-13 23:40:38 +00003296 .Case("unst", ARM_MB::NSHST)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003297 .Case("osh", ARM_MB::OSH)
3298 .Case("oshst", ARM_MB::OSHST)
3299 .Default(~0U);
3300
3301 if (Opt == ~0U)
Jim Grosbachf922c472011-02-12 01:34:40 +00003302 return MatchOperand_NoMatch;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003303
3304 Parser.Lex(); // Eat identifier token.
3305 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00003306 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003307}
3308
Jim Grosbach43904292011-07-25 20:14:50 +00003309/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003310ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003311parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003312 SMLoc S = Parser.getTok().getLoc();
3313 const AsmToken &Tok = Parser.getTok();
Richard Bartona1c73672012-06-14 10:48:04 +00003314 if (!Tok.is(AsmToken::Identifier))
3315 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003316 StringRef IFlagsStr = Tok.getString();
3317
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003318 // An iflags string of "none" is interpreted to mean that none of the AIF
3319 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003320 unsigned IFlags = 0;
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003321 if (IFlagsStr != "none") {
3322 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3323 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3324 .Case("a", ARM_PROC::A)
3325 .Case("i", ARM_PROC::I)
3326 .Case("f", ARM_PROC::F)
3327 .Default(~0U);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003328
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003329 // If some specific iflag is already set, it means that some letter is
3330 // present more than once, this is not acceptable.
3331 if (Flag == ~0U || (IFlags & Flag))
3332 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003333
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003334 IFlags |= Flag;
3335 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003336 }
3337
3338 Parser.Lex(); // Eat identifier token.
3339 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3340 return MatchOperand_Success;
3341}
3342
Jim Grosbach43904292011-07-25 20:14:50 +00003343/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003344ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003345parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003346 SMLoc S = Parser.getTok().getLoc();
3347 const AsmToken &Tok = Parser.getTok();
3348 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3349 StringRef Mask = Tok.getString();
3350
James Molloyacad68d2011-09-28 14:21:38 +00003351 if (isMClass()) {
3352 // See ARMv6-M 10.1.1
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00003353 std::string Name = Mask.lower();
3354 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderby0fd4f3c2012-05-17 22:18:01 +00003355 // Note: in the documentation:
3356 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3357 // for MSR APSR_nzcvq.
3358 // but we do make it an alias here. This is so to get the "mask encoding"
3359 // bits correct on MSR APSR writes.
3360 //
3361 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3362 // should really only be allowed when writing a special register. Note
3363 // they get dropped in the MRS instruction reading a special register as
3364 // the SYSm field is only 8 bits.
3365 //
3366 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3367 // includes the DSP extension but that is not checked.
3368 .Case("apsr", 0x800)
3369 .Case("apsr_nzcvq", 0x800)
3370 .Case("apsr_g", 0x400)
3371 .Case("apsr_nzcvqg", 0xc00)
3372 .Case("iapsr", 0x801)
3373 .Case("iapsr_nzcvq", 0x801)
3374 .Case("iapsr_g", 0x401)
3375 .Case("iapsr_nzcvqg", 0xc01)
3376 .Case("eapsr", 0x802)
3377 .Case("eapsr_nzcvq", 0x802)
3378 .Case("eapsr_g", 0x402)
3379 .Case("eapsr_nzcvqg", 0xc02)
3380 .Case("xpsr", 0x803)
3381 .Case("xpsr_nzcvq", 0x803)
3382 .Case("xpsr_g", 0x403)
3383 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderbyf49a4092012-06-15 22:14:44 +00003384 .Case("ipsr", 0x805)
3385 .Case("epsr", 0x806)
3386 .Case("iepsr", 0x807)
3387 .Case("msp", 0x808)
3388 .Case("psp", 0x809)
3389 .Case("primask", 0x810)
3390 .Case("basepri", 0x811)
3391 .Case("basepri_max", 0x812)
3392 .Case("faultmask", 0x813)
3393 .Case("control", 0x814)
James Molloyacad68d2011-09-28 14:21:38 +00003394 .Default(~0U);
Jim Grosbach18c8d122011-12-22 17:17:10 +00003395
James Molloyacad68d2011-09-28 14:21:38 +00003396 if (FlagsVal == ~0U)
3397 return MatchOperand_NoMatch;
3398
Kevin Enderbyf49a4092012-06-15 22:14:44 +00003399 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloyacad68d2011-09-28 14:21:38 +00003400 // basepri, basepri_max and faultmask only valid for V7m.
3401 return MatchOperand_NoMatch;
Jim Grosbach18c8d122011-12-22 17:17:10 +00003402
James Molloyacad68d2011-09-28 14:21:38 +00003403 Parser.Lex(); // Eat identifier token.
3404 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3405 return MatchOperand_Success;
3406 }
3407
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003408 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3409 size_t Start = 0, Next = Mask.find('_');
3410 StringRef Flags = "";
Benjamin Kramer59085362011-11-06 20:37:06 +00003411 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003412 if (Next != StringRef::npos)
3413 Flags = Mask.slice(Next+1, Mask.size());
3414
3415 // FlagsVal contains the complete mask:
3416 // 3-0: Mask
3417 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3418 unsigned FlagsVal = 0;
3419
3420 if (SpecReg == "apsr") {
3421 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +00003422 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003423 .Case("g", 0x4) // same as CPSR_s
3424 .Case("nzcvqg", 0xc) // same as CPSR_fs
3425 .Default(~0U);
3426
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003427 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003428 if (!Flags.empty())
3429 return MatchOperand_NoMatch;
3430 else
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003431 FlagsVal = 8; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003432 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003433 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbachb657a902012-04-05 03:17:53 +00003434 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3435 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00003436 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003437 for (int i = 0, e = Flags.size(); i != e; ++i) {
3438 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3439 .Case("c", 1)
3440 .Case("x", 2)
3441 .Case("s", 4)
3442 .Case("f", 8)
3443 .Default(~0U);
3444
3445 // If some specific flag is already set, it means that some letter is
3446 // present more than once, this is not acceptable.
3447 if (FlagsVal == ~0U || (FlagsVal & Flag))
3448 return MatchOperand_NoMatch;
3449 FlagsVal |= Flag;
3450 }
3451 } else // No match for special register.
3452 return MatchOperand_NoMatch;
3453
Owen Anderson7784f1d2011-10-21 18:43:28 +00003454 // Special register without flags is NOT equivalent to "fc" flags.
3455 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3456 // two lines would enable gas compatibility at the expense of breaking
3457 // round-tripping.
3458 //
3459 // if (!FlagsVal)
3460 // FlagsVal = 0x9;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003461
3462 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3463 if (SpecReg == "spsr")
3464 FlagsVal |= 16;
3465
3466 Parser.Lex(); // Eat identifier token.
3467 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3468 return MatchOperand_Success;
3469}
3470
Jim Grosbachf6c05252011-07-21 17:23:04 +00003471ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3472parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3473 int Low, int High) {
3474 const AsmToken &Tok = Parser.getTok();
3475 if (Tok.isNot(AsmToken::Identifier)) {
3476 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3477 return MatchOperand_ParseFail;
3478 }
3479 StringRef ShiftName = Tok.getString();
Benjamin Kramer59085362011-11-06 20:37:06 +00003480 std::string LowerOp = Op.lower();
3481 std::string UpperOp = Op.upper();
Jim Grosbachf6c05252011-07-21 17:23:04 +00003482 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3483 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3484 return MatchOperand_ParseFail;
3485 }
3486 Parser.Lex(); // Eat shift type token.
3487
3488 // There must be a '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003489 if (Parser.getTok().isNot(AsmToken::Hash) &&
3490 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbachf6c05252011-07-21 17:23:04 +00003491 Error(Parser.getTok().getLoc(), "'#' expected");
3492 return MatchOperand_ParseFail;
3493 }
3494 Parser.Lex(); // Eat hash token.
3495
3496 const MCExpr *ShiftAmount;
3497 SMLoc Loc = Parser.getTok().getLoc();
3498 if (getParser().ParseExpression(ShiftAmount)) {
3499 Error(Loc, "illegal expression");
3500 return MatchOperand_ParseFail;
3501 }
3502 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3503 if (!CE) {
3504 Error(Loc, "constant expression expected");
3505 return MatchOperand_ParseFail;
3506 }
3507 int Val = CE->getValue();
3508 if (Val < Low || Val > High) {
3509 Error(Loc, "immediate value out of range");
3510 return MatchOperand_ParseFail;
3511 }
3512
3513 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3514
3515 return MatchOperand_Success;
3516}
3517
Jim Grosbachc27d4f92011-07-22 17:44:50 +00003518ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3519parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3520 const AsmToken &Tok = Parser.getTok();
3521 SMLoc S = Tok.getLoc();
3522 if (Tok.isNot(AsmToken::Identifier)) {
3523 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3524 return MatchOperand_ParseFail;
3525 }
3526 int Val = StringSwitch<int>(Tok.getString())
3527 .Case("be", 1)
3528 .Case("le", 0)
3529 .Default(-1);
3530 Parser.Lex(); // Eat the token.
3531
3532 if (Val == -1) {
3533 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3534 return MatchOperand_ParseFail;
3535 }
3536 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3537 getContext()),
3538 S, Parser.getTok().getLoc()));
3539 return MatchOperand_Success;
3540}
3541
Jim Grosbach580f4a92011-07-25 22:20:28 +00003542/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3543/// instructions. Legal values are:
3544/// lsl #n 'n' in [0,31]
3545/// asr #n 'n' in [1,32]
3546/// n == 32 encoded as n == 0.
3547ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3548parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3549 const AsmToken &Tok = Parser.getTok();
3550 SMLoc S = Tok.getLoc();
3551 if (Tok.isNot(AsmToken::Identifier)) {
3552 Error(S, "shift operator 'asr' or 'lsl' expected");
3553 return MatchOperand_ParseFail;
3554 }
3555 StringRef ShiftName = Tok.getString();
3556 bool isASR;
3557 if (ShiftName == "lsl" || ShiftName == "LSL")
3558 isASR = false;
3559 else if (ShiftName == "asr" || ShiftName == "ASR")
3560 isASR = true;
3561 else {
3562 Error(S, "shift operator 'asr' or 'lsl' expected");
3563 return MatchOperand_ParseFail;
3564 }
3565 Parser.Lex(); // Eat the operator.
3566
3567 // A '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003568 if (Parser.getTok().isNot(AsmToken::Hash) &&
3569 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach580f4a92011-07-25 22:20:28 +00003570 Error(Parser.getTok().getLoc(), "'#' expected");
3571 return MatchOperand_ParseFail;
3572 }
3573 Parser.Lex(); // Eat hash token.
3574
3575 const MCExpr *ShiftAmount;
3576 SMLoc E = Parser.getTok().getLoc();
3577 if (getParser().ParseExpression(ShiftAmount)) {
3578 Error(E, "malformed shift expression");
3579 return MatchOperand_ParseFail;
3580 }
3581 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3582 if (!CE) {
3583 Error(E, "shift amount must be an immediate");
3584 return MatchOperand_ParseFail;
3585 }
3586
3587 int64_t Val = CE->getValue();
3588 if (isASR) {
3589 // Shift amount must be in [1,32]
3590 if (Val < 1 || Val > 32) {
3591 Error(E, "'asr' shift amount must be in range [1,32]");
3592 return MatchOperand_ParseFail;
3593 }
Owen Anderson0afa0092011-09-26 21:06:22 +00003594 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3595 if (isThumb() && Val == 32) {
3596 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3597 return MatchOperand_ParseFail;
3598 }
Jim Grosbach580f4a92011-07-25 22:20:28 +00003599 if (Val == 32) Val = 0;
3600 } else {
3601 // Shift amount must be in [1,32]
3602 if (Val < 0 || Val > 31) {
3603 Error(E, "'lsr' shift amount must be in range [0,31]");
3604 return MatchOperand_ParseFail;
3605 }
3606 }
3607
3608 E = Parser.getTok().getLoc();
3609 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3610
3611 return MatchOperand_Success;
3612}
3613
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003614/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3615/// of instructions. Legal values are:
3616/// ror #n 'n' in {0, 8, 16, 24}
3617ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3618parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3619 const AsmToken &Tok = Parser.getTok();
3620 SMLoc S = Tok.getLoc();
Jim Grosbach326efe52011-09-19 20:29:33 +00003621 if (Tok.isNot(AsmToken::Identifier))
3622 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003623 StringRef ShiftName = Tok.getString();
Jim Grosbach326efe52011-09-19 20:29:33 +00003624 if (ShiftName != "ror" && ShiftName != "ROR")
3625 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003626 Parser.Lex(); // Eat the operator.
3627
3628 // A '#' and a rotate amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003629 if (Parser.getTok().isNot(AsmToken::Hash) &&
3630 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003631 Error(Parser.getTok().getLoc(), "'#' expected");
3632 return MatchOperand_ParseFail;
3633 }
3634 Parser.Lex(); // Eat hash token.
3635
3636 const MCExpr *ShiftAmount;
3637 SMLoc E = Parser.getTok().getLoc();
3638 if (getParser().ParseExpression(ShiftAmount)) {
3639 Error(E, "malformed rotate expression");
3640 return MatchOperand_ParseFail;
3641 }
3642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3643 if (!CE) {
3644 Error(E, "rotate amount must be an immediate");
3645 return MatchOperand_ParseFail;
3646 }
3647
3648 int64_t Val = CE->getValue();
3649 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3650 // normally, zero is represented in asm by omitting the rotate operand
3651 // entirely.
3652 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3653 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3654 return MatchOperand_ParseFail;
3655 }
3656
3657 E = Parser.getTok().getLoc();
3658 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3659
3660 return MatchOperand_Success;
3661}
3662
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003663ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3664parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3665 SMLoc S = Parser.getTok().getLoc();
3666 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003667 if (Parser.getTok().isNot(AsmToken::Hash) &&
3668 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003669 Error(Parser.getTok().getLoc(), "'#' expected");
3670 return MatchOperand_ParseFail;
3671 }
3672 Parser.Lex(); // Eat hash token.
3673
3674 const MCExpr *LSBExpr;
3675 SMLoc E = Parser.getTok().getLoc();
3676 if (getParser().ParseExpression(LSBExpr)) {
3677 Error(E, "malformed immediate expression");
3678 return MatchOperand_ParseFail;
3679 }
3680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3681 if (!CE) {
3682 Error(E, "'lsb' operand must be an immediate");
3683 return MatchOperand_ParseFail;
3684 }
3685
3686 int64_t LSB = CE->getValue();
3687 // The LSB must be in the range [0,31]
3688 if (LSB < 0 || LSB > 31) {
3689 Error(E, "'lsb' operand must be in the range [0,31]");
3690 return MatchOperand_ParseFail;
3691 }
3692 E = Parser.getTok().getLoc();
3693
3694 // Expect another immediate operand.
3695 if (Parser.getTok().isNot(AsmToken::Comma)) {
3696 Error(Parser.getTok().getLoc(), "too few operands");
3697 return MatchOperand_ParseFail;
3698 }
3699 Parser.Lex(); // Eat hash token.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003700 if (Parser.getTok().isNot(AsmToken::Hash) &&
3701 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003702 Error(Parser.getTok().getLoc(), "'#' expected");
3703 return MatchOperand_ParseFail;
3704 }
3705 Parser.Lex(); // Eat hash token.
3706
3707 const MCExpr *WidthExpr;
3708 if (getParser().ParseExpression(WidthExpr)) {
3709 Error(E, "malformed immediate expression");
3710 return MatchOperand_ParseFail;
3711 }
3712 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3713 if (!CE) {
3714 Error(E, "'width' operand must be an immediate");
3715 return MatchOperand_ParseFail;
3716 }
3717
3718 int64_t Width = CE->getValue();
3719 // The LSB must be in the range [1,32-lsb]
3720 if (Width < 1 || Width > 32 - LSB) {
3721 Error(E, "'width' operand must be in the range [1,32-lsb]");
3722 return MatchOperand_ParseFail;
3723 }
3724 E = Parser.getTok().getLoc();
3725
3726 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3727
3728 return MatchOperand_Success;
3729}
3730
Jim Grosbach7ce05792011-08-03 23:50:40 +00003731ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3732parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3733 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003734 // postidx_reg := '+' register {, shift}
3735 // | '-' register {, shift}
3736 // | register {, shift}
Jim Grosbach7ce05792011-08-03 23:50:40 +00003737
3738 // This method must return MatchOperand_NoMatch without consuming any tokens
3739 // in the case where there is no match, as other alternatives take other
3740 // parse methods.
3741 AsmToken Tok = Parser.getTok();
3742 SMLoc S = Tok.getLoc();
3743 bool haveEaten = false;
Jim Grosbach16578b52011-08-05 16:11:38 +00003744 bool isAdd = true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003745 int Reg = -1;
3746 if (Tok.is(AsmToken::Plus)) {
3747 Parser.Lex(); // Eat the '+' token.
3748 haveEaten = true;
3749 } else if (Tok.is(AsmToken::Minus)) {
3750 Parser.Lex(); // Eat the '-' token.
Jim Grosbach16578b52011-08-05 16:11:38 +00003751 isAdd = false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003752 haveEaten = true;
3753 }
3754 if (Parser.getTok().is(AsmToken::Identifier))
3755 Reg = tryParseRegister();
3756 if (Reg == -1) {
3757 if (!haveEaten)
3758 return MatchOperand_NoMatch;
3759 Error(Parser.getTok().getLoc(), "register expected");
3760 return MatchOperand_ParseFail;
3761 }
3762 SMLoc E = Parser.getTok().getLoc();
3763
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003764 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3765 unsigned ShiftImm = 0;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00003766 if (Parser.getTok().is(AsmToken::Comma)) {
3767 Parser.Lex(); // Eat the ','.
3768 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3769 return MatchOperand_ParseFail;
3770 }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003771
3772 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3773 ShiftImm, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003774
3775 return MatchOperand_Success;
3776}
3777
Jim Grosbach251bf252011-08-10 21:56:18 +00003778ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3779parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3780 // Check for a post-index addressing register operand. Specifically:
3781 // am3offset := '+' register
3782 // | '-' register
3783 // | register
3784 // | # imm
3785 // | # + imm
3786 // | # - imm
3787
3788 // This method must return MatchOperand_NoMatch without consuming any tokens
3789 // in the case where there is no match, as other alternatives take other
3790 // parse methods.
3791 AsmToken Tok = Parser.getTok();
3792 SMLoc S = Tok.getLoc();
3793
3794 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003795 if (Parser.getTok().is(AsmToken::Hash) ||
3796 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach251bf252011-08-10 21:56:18 +00003797 Parser.Lex(); // Eat the '#'.
3798 // Explicitly look for a '-', as we need to encode negative zero
3799 // differently.
3800 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3801 const MCExpr *Offset;
3802 if (getParser().ParseExpression(Offset))
3803 return MatchOperand_ParseFail;
3804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3805 if (!CE) {
3806 Error(S, "constant expression expected");
3807 return MatchOperand_ParseFail;
3808 }
3809 SMLoc E = Tok.getLoc();
3810 // Negative zero is encoded as the flag value INT32_MIN.
3811 int32_t Val = CE->getValue();
3812 if (isNegative && Val == 0)
3813 Val = INT32_MIN;
3814
3815 Operands.push_back(
3816 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3817
3818 return MatchOperand_Success;
3819 }
3820
3821
3822 bool haveEaten = false;
3823 bool isAdd = true;
3824 int Reg = -1;
3825 if (Tok.is(AsmToken::Plus)) {
3826 Parser.Lex(); // Eat the '+' token.
3827 haveEaten = true;
3828 } else if (Tok.is(AsmToken::Minus)) {
3829 Parser.Lex(); // Eat the '-' token.
3830 isAdd = false;
3831 haveEaten = true;
3832 }
3833 if (Parser.getTok().is(AsmToken::Identifier))
3834 Reg = tryParseRegister();
3835 if (Reg == -1) {
3836 if (!haveEaten)
3837 return MatchOperand_NoMatch;
3838 Error(Parser.getTok().getLoc(), "register expected");
3839 return MatchOperand_ParseFail;
3840 }
3841 SMLoc E = Parser.getTok().getLoc();
3842
3843 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3844 0, S, E));
3845
3846 return MatchOperand_Success;
3847}
3848
Jim Grosbacha77295d2011-09-08 22:07:06 +00003849/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3850/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3851/// when they refer multiple MIOperands inside a single one.
3852bool ARMAsmParser::
3853cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
3854 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3855 // Rt, Rt2
3856 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3857 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3858 // Create a writeback register dummy placeholder.
3859 Inst.addOperand(MCOperand::CreateReg(0));
3860 // addr
3861 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3862 // pred
3863 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3864 return true;
3865}
3866
3867/// cvtT2StrdPre - Convert parsed operands to MCInst.
3868/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3869/// when they refer multiple MIOperands inside a single one.
3870bool ARMAsmParser::
3871cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
3872 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3873 // Create a writeback register dummy placeholder.
3874 Inst.addOperand(MCOperand::CreateReg(0));
3875 // Rt, Rt2
3876 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3877 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3878 // addr
3879 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3880 // pred
3881 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3882 return true;
3883}
3884
Jim Grosbacheeec0252011-09-08 00:39:19 +00003885/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3886/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3887/// when they refer multiple MIOperands inside a single one.
3888bool ARMAsmParser::
3889cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3890 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3891 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3892
3893 // Create a writeback register dummy placeholder.
3894 Inst.addOperand(MCOperand::CreateImm(0));
3895
3896 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3897 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3898 return true;
3899}
3900
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003901/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3902/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3903/// when they refer multiple MIOperands inside a single one.
3904bool ARMAsmParser::
3905cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3906 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3907 // Create a writeback register dummy placeholder.
3908 Inst.addOperand(MCOperand::CreateImm(0));
3909 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3910 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3911 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3912 return true;
3913}
3914
Jim Grosbach1355cf12011-07-26 17:10:22 +00003915/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003916/// 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::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003919cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003920 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
Jim Grosbach7ce05792011-08-03 23:50:40 +00003926 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003927 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3928 return true;
3929}
3930
Owen Anderson9ab0f252011-08-26 20:43:14 +00003931/// cvtLdWriteBackRegAddrModeImm12 - 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::
3935cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3936 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3937 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3938
3939 // Create a writeback register dummy placeholder.
3940 Inst.addOperand(MCOperand::CreateImm(0));
3941
3942 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3943 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3944 return true;
3945}
3946
3947
Jim Grosbach548340c2011-08-11 19:22:40 +00003948/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3949/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3950/// when they refer multiple MIOperands inside a single one.
3951bool ARMAsmParser::
3952cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3953 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3954 // Create a writeback register dummy placeholder.
3955 Inst.addOperand(MCOperand::CreateImm(0));
3956 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3957 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3958 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3959 return true;
3960}
3961
Jim Grosbach1355cf12011-07-26 17:10:22 +00003962/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003963/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3964/// when they refer multiple MIOperands inside a single one.
3965bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003966cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003967 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3968 // Create a writeback register dummy placeholder.
3969 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach548340c2011-08-11 19:22:40 +00003970 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3971 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3972 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003973 return true;
3974}
3975
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00003976/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3977/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3978/// when they refer multiple MIOperands inside a single one.
3979bool ARMAsmParser::
3980cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3981 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3982 // Create a writeback register dummy placeholder.
3983 Inst.addOperand(MCOperand::CreateImm(0));
3984 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3985 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3986 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3987 return true;
3988}
3989
Jim Grosbach7ce05792011-08-03 23:50:40 +00003990/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
3991/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3992/// when they refer multiple MIOperands inside a single one.
3993bool ARMAsmParser::
3994cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3995 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3996 // Rt
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003997 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003998 // Create a writeback register dummy placeholder.
3999 Inst.addOperand(MCOperand::CreateImm(0));
4000 // addr
4001 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4002 // offset
4003 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4004 // pred
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004005 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4006 return true;
4007}
4008
Jim Grosbach7ce05792011-08-03 23:50:40 +00004009/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004010/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4011/// when they refer multiple MIOperands inside a single one.
4012bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004013cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
4014 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4015 // Rt
Owen Andersonaa3402e2011-07-28 17:18:57 +00004016 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004017 // Create a writeback register dummy placeholder.
4018 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004019 // addr
4020 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4021 // offset
4022 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4023 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004024 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4025 return true;
4026}
4027
Jim Grosbach7ce05792011-08-03 23:50:40 +00004028/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004029/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4030/// when they refer multiple MIOperands inside a single one.
4031bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004032cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
4033 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004034 // Create a writeback register dummy placeholder.
4035 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004036 // Rt
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004037 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004038 // addr
4039 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4040 // offset
4041 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4042 // pred
4043 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4044 return true;
4045}
4046
4047/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4048/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4049/// when they refer multiple MIOperands inside a single one.
4050bool ARMAsmParser::
4051cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
4052 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4053 // Create a writeback register dummy placeholder.
4054 Inst.addOperand(MCOperand::CreateImm(0));
4055 // Rt
4056 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4057 // addr
4058 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4059 // offset
4060 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4061 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004062 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4063 return true;
4064}
4065
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004066/// cvtLdrdPre - Convert parsed operands to MCInst.
4067/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4068/// when they refer multiple MIOperands inside a single one.
4069bool ARMAsmParser::
4070cvtLdrdPre(MCInst &Inst, unsigned Opcode,
4071 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4072 // Rt, Rt2
4073 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4074 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4075 // Create a writeback register dummy placeholder.
4076 Inst.addOperand(MCOperand::CreateImm(0));
4077 // addr
4078 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4079 // pred
4080 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4081 return true;
4082}
4083
Jim Grosbach14605d12011-08-11 20:28:23 +00004084/// cvtStrdPre - Convert parsed operands to MCInst.
4085/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4086/// when they refer multiple MIOperands inside a single one.
4087bool ARMAsmParser::
4088cvtStrdPre(MCInst &Inst, unsigned Opcode,
4089 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4090 // Create a writeback register dummy placeholder.
4091 Inst.addOperand(MCOperand::CreateImm(0));
4092 // Rt, Rt2
4093 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4094 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4095 // addr
4096 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4097 // pred
4098 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4099 return true;
4100}
4101
Jim Grosbach623a4542011-08-10 22:42:16 +00004102/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4103/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4104/// when they refer multiple MIOperands inside a single one.
4105bool ARMAsmParser::
4106cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
4107 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4108 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4109 // Create a writeback register dummy placeholder.
4110 Inst.addOperand(MCOperand::CreateImm(0));
4111 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4112 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4113 return true;
4114}
4115
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004116/// cvtThumbMultiple- Convert parsed operands to MCInst.
4117/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4118/// when they refer multiple MIOperands inside a single one.
4119bool ARMAsmParser::
4120cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
4121 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4122 // The second source operand must be the same register as the destination
4123 // operand.
4124 if (Operands.size() == 6 &&
Jim Grosbach7a010692011-08-19 22:30:46 +00004125 (((ARMOperand*)Operands[3])->getReg() !=
4126 ((ARMOperand*)Operands[5])->getReg()) &&
4127 (((ARMOperand*)Operands[3])->getReg() !=
4128 ((ARMOperand*)Operands[4])->getReg())) {
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004129 Error(Operands[3]->getStartLoc(),
Jim Grosbach7a010692011-08-19 22:30:46 +00004130 "destination register must match source register");
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004131 return false;
4132 }
4133 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4134 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach1b332862011-11-10 22:10:12 +00004135 // If we have a three-operand form, make sure to set Rn to be the operand
4136 // that isn't the same as Rd.
4137 unsigned RegOp = 4;
4138 if (Operands.size() == 6 &&
4139 ((ARMOperand*)Operands[4])->getReg() ==
4140 ((ARMOperand*)Operands[3])->getReg())
4141 RegOp = 5;
4142 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4143 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004144 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4145
4146 return true;
4147}
Jim Grosbach623a4542011-08-10 22:42:16 +00004148
Jim Grosbach12431322011-10-24 22:16:58 +00004149bool ARMAsmParser::
4150cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
4151 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4152 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004153 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004154 // Create a writeback register dummy placeholder.
4155 Inst.addOperand(MCOperand::CreateImm(0));
4156 // Vn
4157 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4158 // pred
4159 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4160 return true;
4161}
4162
4163bool ARMAsmParser::
4164cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
4165 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4166 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004167 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004168 // Create a writeback register dummy placeholder.
4169 Inst.addOperand(MCOperand::CreateImm(0));
4170 // Vn
4171 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4172 // Vm
4173 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4174 // pred
4175 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4176 return true;
4177}
4178
Jim Grosbach4334e032011-10-31 21:50:31 +00004179bool ARMAsmParser::
4180cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
4181 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4182 // Create a writeback register dummy placeholder.
4183 Inst.addOperand(MCOperand::CreateImm(0));
4184 // Vn
4185 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4186 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004187 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004188 // pred
4189 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4190 return true;
4191}
4192
4193bool ARMAsmParser::
4194cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
4195 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4196 // Create a writeback register dummy placeholder.
4197 Inst.addOperand(MCOperand::CreateImm(0));
4198 // Vn
4199 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4200 // Vm
4201 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4202 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004203 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004204 // pred
4205 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4206 return true;
4207}
4208
Bill Wendlinge7176102010-11-06 22:36:58 +00004209/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004210/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00004211bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004212parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +00004213 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00004214 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00004215 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00004216 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004217 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004218
Sean Callanan18b83232010-01-19 21:44:56 +00004219 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbach1355cf12011-07-26 17:10:22 +00004220 int BaseRegNum = tryParseRegister();
Jim Grosbach7ce05792011-08-03 23:50:40 +00004221 if (BaseRegNum == -1)
4222 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004223
Daniel Dunbar05710932011-01-18 05:34:17 +00004224 // The next token must either be a comma or a closing bracket.
4225 const AsmToken &Tok = Parser.getTok();
4226 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004227 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar05710932011-01-18 05:34:17 +00004228
Jim Grosbach7ce05792011-08-03 23:50:40 +00004229 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan76264762010-04-02 22:27:05 +00004230 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004231 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004232
Jim Grosbach7ce05792011-08-03 23:50:40 +00004233 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004234 0, 0, false, S, E));
Jim Grosbach03f44a02010-11-29 23:18:01 +00004235
Jim Grosbachfb12f352011-09-19 18:42:21 +00004236 // If there's a pre-indexing writeback marker, '!', just add it as a token
4237 // operand. It's rather odd, but syntactically valid.
4238 if (Parser.getTok().is(AsmToken::Exclaim)) {
4239 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4240 Parser.Lex(); // Eat the '!'.
4241 }
4242
Jim Grosbach7ce05792011-08-03 23:50:40 +00004243 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004244 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004245
Jim Grosbach7ce05792011-08-03 23:50:40 +00004246 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4247 Parser.Lex(); // Eat the comma.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004248
Jim Grosbach57dcb852011-10-11 17:29:55 +00004249 // If we have a ':', it's an alignment specifier.
4250 if (Parser.getTok().is(AsmToken::Colon)) {
4251 Parser.Lex(); // Eat the ':'.
4252 E = Parser.getTok().getLoc();
4253
4254 const MCExpr *Expr;
4255 if (getParser().ParseExpression(Expr))
4256 return true;
4257
4258 // The expression has to be a constant. Memory references with relocations
4259 // don't come through here, as they use the <label> forms of the relevant
4260 // instructions.
4261 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4262 if (!CE)
4263 return Error (E, "constant expression expected");
4264
4265 unsigned Align = 0;
4266 switch (CE->getValue()) {
4267 default:
Jim Grosbacheeaf1c12011-12-19 18:31:43 +00004268 return Error(E,
4269 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4270 case 16: Align = 2; break;
4271 case 32: Align = 4; break;
Jim Grosbach57dcb852011-10-11 17:29:55 +00004272 case 64: Align = 8; break;
4273 case 128: Align = 16; break;
4274 case 256: Align = 32; break;
4275 }
4276
4277 // Now we should have the closing ']'
4278 E = Parser.getTok().getLoc();
4279 if (Parser.getTok().isNot(AsmToken::RBrac))
4280 return Error(E, "']' expected");
4281 Parser.Lex(); // Eat right bracket token.
4282
4283 // Don't worry about range checking the value here. That's handled by
4284 // the is*() predicates.
4285 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4286 ARM_AM::no_shift, 0, Align,
4287 false, S, E));
4288
4289 // If there's a pre-indexing writeback marker, '!', just add it as a token
4290 // operand.
4291 if (Parser.getTok().is(AsmToken::Exclaim)) {
4292 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4293 Parser.Lex(); // Eat the '!'.
4294 }
4295
4296 return false;
4297 }
4298
4299 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004300 // offset. Be friendly and also accept a plain integer (without a leading
4301 // hash) for gas compatibility.
4302 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004303 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004304 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004305 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004306 Parser.Lex(); // Eat the '#'.
Jim Grosbach7ce05792011-08-03 23:50:40 +00004307 E = Parser.getTok().getLoc();
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004308
Owen Anderson0da10cf2011-08-29 19:36:44 +00004309 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004310 const MCExpr *Offset;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004311 if (getParser().ParseExpression(Offset))
4312 return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004313
4314 // The expression has to be a constant. Memory references with relocations
4315 // don't come through here, as they use the <label> forms of the relevant
4316 // instructions.
4317 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4318 if (!CE)
4319 return Error (E, "constant expression expected");
4320
Owen Anderson0da10cf2011-08-29 19:36:44 +00004321 // If the constant was #-0, represent it as INT32_MIN.
4322 int32_t Val = CE->getValue();
4323 if (isNegative && Val == 0)
4324 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4325
Jim Grosbach7ce05792011-08-03 23:50:40 +00004326 // Now we should have the closing ']'
4327 E = Parser.getTok().getLoc();
4328 if (Parser.getTok().isNot(AsmToken::RBrac))
4329 return Error(E, "']' expected");
4330 Parser.Lex(); // Eat right bracket token.
4331
4332 // Don't worry about range checking the value here. That's handled by
4333 // the is*() predicates.
4334 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004335 ARM_AM::no_shift, 0, 0,
4336 false, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004337
4338 // If there's a pre-indexing writeback marker, '!', just add it as a token
4339 // operand.
4340 if (Parser.getTok().is(AsmToken::Exclaim)) {
4341 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4342 Parser.Lex(); // Eat the '!'.
4343 }
4344
4345 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004346 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004347
4348 // The register offset is optionally preceded by a '+' or '-'
4349 bool isNegative = false;
4350 if (Parser.getTok().is(AsmToken::Minus)) {
4351 isNegative = true;
4352 Parser.Lex(); // Eat the '-'.
4353 } else if (Parser.getTok().is(AsmToken::Plus)) {
4354 // Nothing to do.
4355 Parser.Lex(); // Eat the '+'.
4356 }
4357
4358 E = Parser.getTok().getLoc();
4359 int OffsetRegNum = tryParseRegister();
4360 if (OffsetRegNum == -1)
4361 return Error(E, "register expected");
4362
4363 // If there's a shift operator, handle it.
4364 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004365 unsigned ShiftImm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004366 if (Parser.getTok().is(AsmToken::Comma)) {
4367 Parser.Lex(); // Eat the ','.
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004368 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004369 return true;
4370 }
4371
4372 // Now we should have the closing ']'
4373 E = Parser.getTok().getLoc();
4374 if (Parser.getTok().isNot(AsmToken::RBrac))
4375 return Error(E, "']' expected");
4376 Parser.Lex(); // Eat right bracket token.
4377
4378 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004379 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004380 S, E));
4381
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00004382 // If there's a pre-indexing writeback marker, '!', just add it as a token
4383 // operand.
4384 if (Parser.getTok().is(AsmToken::Exclaim)) {
4385 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4386 Parser.Lex(); // Eat the '!'.
4387 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004388
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004389 return false;
4390}
4391
Jim Grosbach7ce05792011-08-03 23:50:40 +00004392/// parseMemRegOffsetShift - one of these two:
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004393/// ( lsl | lsr | asr | ror ) , # shift_amount
4394/// rrx
Jim Grosbach7ce05792011-08-03 23:50:40 +00004395/// return true if it parses a shift otherwise it returns false.
4396bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4397 unsigned &Amount) {
4398 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan18b83232010-01-19 21:44:56 +00004399 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004400 if (Tok.isNot(AsmToken::Identifier))
4401 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00004402 StringRef ShiftName = Tok.getString();
Jim Grosbachaf4edea2011-12-07 23:40:58 +00004403 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4404 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson00828302011-03-18 22:50:18 +00004405 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004406 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00004407 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004408 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00004409 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004410 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00004411 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004412 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00004413 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004414 else
Jim Grosbach7ce05792011-08-03 23:50:40 +00004415 return Error(Loc, "illegal shift operator");
Sean Callananb9a25b72010-01-19 20:27:46 +00004416 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004417
Jim Grosbach7ce05792011-08-03 23:50:40 +00004418 // rrx stands alone.
4419 Amount = 0;
4420 if (St != ARM_AM::rrx) {
4421 Loc = Parser.getTok().getLoc();
4422 // A '#' and a shift amount.
4423 const AsmToken &HashTok = Parser.getTok();
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004424 if (HashTok.isNot(AsmToken::Hash) &&
4425 HashTok.isNot(AsmToken::Dollar))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004426 return Error(HashTok.getLoc(), "'#' expected");
4427 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004428
Jim Grosbach7ce05792011-08-03 23:50:40 +00004429 const MCExpr *Expr;
4430 if (getParser().ParseExpression(Expr))
4431 return true;
4432 // Range check the immediate.
4433 // lsl, ror: 0 <= imm <= 31
4434 // lsr, asr: 0 <= imm <= 32
4435 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4436 if (!CE)
4437 return Error(Loc, "shift amount must be an immediate");
4438 int64_t Imm = CE->getValue();
4439 if (Imm < 0 ||
4440 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4441 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4442 return Error(Loc, "immediate shift value out of range");
4443 Amount = Imm;
4444 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004445
4446 return false;
4447}
4448
Jim Grosbach9d390362011-10-03 23:38:36 +00004449/// parseFPImm - A floating point immediate expression operand.
4450ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4451parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004452 // Anything that can accept a floating point constant as an operand
4453 // needs to go through here, as the regular ParseExpression is
4454 // integer only.
4455 //
4456 // This routine still creates a generic Immediate operand, containing
4457 // a bitcast of the 64-bit floating point value. The various operands
4458 // that accept floats can check whether the value is valid for them
4459 // via the standard is*() predicates.
4460
Jim Grosbach9d390362011-10-03 23:38:36 +00004461 SMLoc S = Parser.getTok().getLoc();
4462
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004463 if (Parser.getTok().isNot(AsmToken::Hash) &&
4464 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbach9d390362011-10-03 23:38:36 +00004465 return MatchOperand_NoMatch;
Jim Grosbach0e387b22011-10-17 22:26:03 +00004466
4467 // Disambiguate the VMOV forms that can accept an FP immediate.
4468 // vmov.f32 <sreg>, #imm
4469 // vmov.f64 <dreg>, #imm
4470 // vmov.f32 <dreg>, #imm @ vector f32x2
4471 // vmov.f32 <qreg>, #imm @ vector f32x4
4472 //
4473 // There are also the NEON VMOV instructions which expect an
4474 // integer constant. Make sure we don't try to parse an FPImm
4475 // for these:
4476 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4477 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4478 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4479 TyOp->getToken() != ".f64"))
4480 return MatchOperand_NoMatch;
4481
Jim Grosbach9d390362011-10-03 23:38:36 +00004482 Parser.Lex(); // Eat the '#'.
4483
4484 // Handle negation, as that still comes through as a separate token.
4485 bool isNegative = false;
4486 if (Parser.getTok().is(AsmToken::Minus)) {
4487 isNegative = true;
4488 Parser.Lex();
4489 }
4490 const AsmToken &Tok = Parser.getTok();
Jim Grosbachae69f702012-01-19 02:47:30 +00004491 SMLoc Loc = Tok.getLoc();
Jim Grosbach9d390362011-10-03 23:38:36 +00004492 if (Tok.is(AsmToken::Real)) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004493 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbach9d390362011-10-03 23:38:36 +00004494 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4495 // If we had a '-' in front, toggle the sign bit.
Jim Grosbach51222d12012-01-20 18:09:51 +00004496 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbach9d390362011-10-03 23:38:36 +00004497 Parser.Lex(); // Eat the token.
Jim Grosbach51222d12012-01-20 18:09:51 +00004498 Operands.push_back(ARMOperand::CreateImm(
4499 MCConstantExpr::Create(IntVal, getContext()),
4500 S, Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004501 return MatchOperand_Success;
4502 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004503 // Also handle plain integers. Instructions which allow floating point
4504 // immediates also allow a raw encoded 8-bit value.
Jim Grosbach9d390362011-10-03 23:38:36 +00004505 if (Tok.is(AsmToken::Integer)) {
4506 int64_t Val = Tok.getIntVal();
4507 Parser.Lex(); // Eat the token.
4508 if (Val > 255 || Val < 0) {
Jim Grosbachae69f702012-01-19 02:47:30 +00004509 Error(Loc, "encoded floating point value out of range");
Jim Grosbach9d390362011-10-03 23:38:36 +00004510 return MatchOperand_ParseFail;
4511 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004512 double RealVal = ARM_AM::getFPImmFloat(Val);
4513 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4514 Operands.push_back(ARMOperand::CreateImm(
4515 MCConstantExpr::Create(Val, getContext()), S,
4516 Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004517 return MatchOperand_Success;
4518 }
4519
Jim Grosbachae69f702012-01-19 02:47:30 +00004520 Error(Loc, "invalid floating point immediate");
Jim Grosbach9d390362011-10-03 23:38:36 +00004521 return MatchOperand_ParseFail;
4522}
Jim Grosbach51222d12012-01-20 18:09:51 +00004523
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004524/// Parse a arm instruction operand. For now this parses the operand regardless
4525/// of the mnemonic.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004526bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004527 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00004528 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004529
4530 // Check if the current operand has a custom associated parser, if so, try to
4531 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00004532 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4533 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004534 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00004535 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4536 // there was a match, but an error occurred, in which case, just return that
4537 // the operand parsing failed.
4538 if (ResTy == MatchOperand_ParseFail)
4539 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004540
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004541 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00004542 default:
4543 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00004544 return true;
Jim Grosbach19906722011-07-13 18:49:30 +00004545 case AsmToken::Identifier: {
Jim Grosbach1355cf12011-07-26 17:10:22 +00004546 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling50d0f582010-11-18 23:43:05 +00004547 return false;
Jim Grosbach0d87ec22011-07-26 20:41:24 +00004548 int Res = tryParseShiftRegister(Operands);
Jim Grosbach19906722011-07-13 18:49:30 +00004549 if (Res == 0) // success
Owen Anderson00828302011-03-18 22:50:18 +00004550 return false;
Jim Grosbach19906722011-07-13 18:49:30 +00004551 else if (Res == -1) // irrecoverable error
4552 return true;
Jim Grosbach3cbe43f2011-12-20 22:26:38 +00004553 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004554 if (Mnemonic == "vmrs" &&
4555 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004556 S = Parser.getTok().getLoc();
4557 Parser.Lex();
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004558 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004559 return false;
4560 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00004561
4562 // Fall though for the Identifier case that is not a register or a
4563 // special name.
Jim Grosbach19906722011-07-13 18:49:30 +00004564 }
Jim Grosbach758a5192011-10-26 21:14:08 +00004565 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderby67b212e2011-01-13 20:32:36 +00004566 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach6284afc2011-11-01 22:38:31 +00004567 case AsmToken::String: // quoted label names.
Kevin Enderby67b212e2011-01-13 20:32:36 +00004568 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00004569 // This was not a register so parse other operands that start with an
4570 // identifier (like labels) as expressions and create them as immediates.
4571 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00004572 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00004573 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004574 return true;
Sean Callanan76264762010-04-02 22:27:05 +00004575 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004576 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4577 return false;
4578 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004579 case AsmToken::LBrac:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004580 return parseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00004581 case AsmToken::LCurly:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004582 return parseRegisterList(Operands);
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004583 case AsmToken::Dollar:
Owen Anderson63553c72011-08-29 17:17:09 +00004584 case AsmToken::Hash: {
Kevin Enderby079469f2009-10-13 23:33:38 +00004585 // #42 -> immediate.
Sean Callanan76264762010-04-02 22:27:05 +00004586 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004587 Parser.Lex();
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004588
4589 if (Parser.getTok().isNot(AsmToken::Colon)) {
4590 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4591 const MCExpr *ImmVal;
4592 if (getParser().ParseExpression(ImmVal))
4593 return true;
4594 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4595 if (CE) {
4596 int32_t Val = CE->getValue();
4597 if (isNegative && Val == 0)
4598 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4599 }
4600 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4601 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4602 return false;
Owen Anderson63553c72011-08-29 17:17:09 +00004603 }
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004604 // w/ a ':' after the '#', it's just like a plain ':'.
4605 // FALLTHROUGH
Owen Anderson63553c72011-08-29 17:17:09 +00004606 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004607 case AsmToken::Colon: {
4608 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00004609 // FIXME: Check it's an expression prefix,
4610 // e.g. (FOO - :lower16:BAR) isn't legal.
4611 ARMMCExpr::VariantKind RefKind;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004612 if (parsePrefix(RefKind))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004613 return true;
4614
Evan Cheng75972122011-01-13 07:58:56 +00004615 const MCExpr *SubExprVal;
4616 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004617 return true;
4618
Evan Cheng75972122011-01-13 07:58:56 +00004619 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4620 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00004621 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00004622 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00004623 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004624 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004625 }
4626}
4627
Jim Grosbach1355cf12011-07-26 17:10:22 +00004628// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng75972122011-01-13 07:58:56 +00004629// :lower16: and :upper16:.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004630bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng75972122011-01-13 07:58:56 +00004631 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004632
4633 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00004634 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00004635 Parser.Lex(); // Eat ':'
4636
4637 if (getLexer().isNot(AsmToken::Identifier)) {
4638 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4639 return true;
4640 }
4641
4642 StringRef IDVal = Parser.getTok().getIdentifier();
4643 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00004644 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004645 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00004646 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004647 } else {
4648 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4649 return true;
4650 }
4651 Parser.Lex();
4652
4653 if (getLexer().isNot(AsmToken::Colon)) {
4654 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4655 return true;
4656 }
4657 Parser.Lex(); // Eat the last ':'
4658 return false;
4659}
4660
Daniel Dunbar352e1482011-01-11 15:59:50 +00004661/// \brief Given a mnemonic, split out possible predication code and carry
4662/// setting letters to form a canonical mnemonic and flags.
4663//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004664// FIXME: Would be nice to autogen this.
Jim Grosbach89df9962011-08-26 21:43:41 +00004665// FIXME: This is a bit of a maze of special cases.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004666StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5f160572011-07-19 20:10:31 +00004667 unsigned &PredicationCode,
4668 bool &CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004669 unsigned &ProcessorIMod,
4670 StringRef &ITMask) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004671 PredicationCode = ARMCC::AL;
4672 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004673 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004674
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004675 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00004676 //
4677 // FIXME: Would be nice to autogen this.
Jim Grosbach5f160572011-07-19 20:10:31 +00004678 if ((Mnemonic == "movs" && isThumb()) ||
4679 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4680 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4681 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4682 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4683 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4684 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbach68490192011-12-19 19:43:50 +00004685 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4686 Mnemonic == "fmuls")
Daniel Dunbar352e1482011-01-11 15:59:50 +00004687 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00004688
Jim Grosbach3f00e312011-07-11 17:09:57 +00004689 // First, split out any predication code. Ignore mnemonics we know aren't
4690 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbachab40f4b2011-07-20 18:20:31 +00004691 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach71725a02011-07-27 21:58:11 +00004692 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach04d55f12011-08-22 23:55:58 +00004693 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbach2f25d9b2011-09-01 18:22:13 +00004694 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbach3f00e312011-07-11 17:09:57 +00004695 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4696 .Case("eq", ARMCC::EQ)
4697 .Case("ne", ARMCC::NE)
4698 .Case("hs", ARMCC::HS)
4699 .Case("cs", ARMCC::HS)
4700 .Case("lo", ARMCC::LO)
4701 .Case("cc", ARMCC::LO)
4702 .Case("mi", ARMCC::MI)
4703 .Case("pl", ARMCC::PL)
4704 .Case("vs", ARMCC::VS)
4705 .Case("vc", ARMCC::VC)
4706 .Case("hi", ARMCC::HI)
4707 .Case("ls", ARMCC::LS)
4708 .Case("ge", ARMCC::GE)
4709 .Case("lt", ARMCC::LT)
4710 .Case("gt", ARMCC::GT)
4711 .Case("le", ARMCC::LE)
4712 .Case("al", ARMCC::AL)
4713 .Default(~0U);
4714 if (CC != ~0U) {
4715 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4716 PredicationCode = CC;
4717 }
Bill Wendling52925b62010-10-29 23:50:21 +00004718 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004719
Daniel Dunbar352e1482011-01-11 15:59:50 +00004720 // Next, determine if we have a carry setting bit. We explicitly ignore all
4721 // the instructions we know end in 's'.
4722 if (Mnemonic.endswith("s") &&
Jim Grosbach00f5d982011-08-17 22:49:09 +00004723 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5f160572011-07-19 20:10:31 +00004724 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4725 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4726 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach67ca1ad2011-12-08 00:49:29 +00004727 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach48171e72011-12-10 00:01:02 +00004728 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach9c397892011-12-19 19:02:41 +00004729 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbach6357cae2012-03-15 20:48:18 +00004730 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004731 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbache1cf5902011-07-29 20:26:09 +00004732 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004733 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4734 CarrySetting = true;
4735 }
4736
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004737 // The "cps" instruction can have a interrupt mode operand which is glued into
4738 // the mnemonic. Check if this is the case, split it and parse the imod op
4739 if (Mnemonic.startswith("cps")) {
4740 // Split out any imod code.
4741 unsigned IMod =
4742 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4743 .Case("ie", ARM_PROC::IE)
4744 .Case("id", ARM_PROC::ID)
4745 .Default(~0U);
4746 if (IMod != ~0U) {
4747 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4748 ProcessorIMod = IMod;
4749 }
4750 }
4751
Jim Grosbach89df9962011-08-26 21:43:41 +00004752 // The "it" instruction has the condition mask on the end of the mnemonic.
4753 if (Mnemonic.startswith("it")) {
4754 ITMask = Mnemonic.slice(2, Mnemonic.size());
4755 Mnemonic = Mnemonic.slice(0, 2);
4756 }
4757
Daniel Dunbar352e1482011-01-11 15:59:50 +00004758 return Mnemonic;
4759}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004760
4761/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4762/// inclusion of carry set or predication code operands.
4763//
4764// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004765void ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00004766getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004767 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004768 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4769 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004770 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004771 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004772 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004773 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004774 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004775 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004776 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004777 Mnemonic == "mla" || Mnemonic == "smlal" ||
4778 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004779 CanAcceptCarrySet = true;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004780 } else
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004781 CanAcceptCarrySet = false;
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004782
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004783 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4784 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4785 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4786 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbachad2dad92011-09-06 20:27:04 +00004787 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4788 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach0780b632011-08-19 23:24:36 +00004789 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach2bd01182011-10-11 21:55:36 +00004790 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4791 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4792 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbach4af54a42011-08-26 22:21:51 +00004793 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4794 !isThumb()) ||
Jim Grosbach1ad60c22011-09-10 00:15:36 +00004795 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004796 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004797 } else
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004798 CanAcceptPredicationCode = true;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004799
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004800 if (isThumb()) {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004801 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00004802 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004803 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004804 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004805}
4806
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004807bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4808 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004809 // FIXME: This is all horribly hacky. We really need a better way to deal
4810 // with optional operands like this in the matcher table.
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004811
4812 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4813 // another does not. Specifically, the MOVW instruction does not. So we
4814 // special case it here and remove the defaulted (non-setting) cc_out
4815 // operand if that's the instruction we're trying to match.
4816 //
4817 // We do this as post-processing of the explicit operands rather than just
4818 // conditionally adding the cc_out in the first place because we need
4819 // to check the type of the parsed immediate operand.
Owen Anderson8adf6202011-09-14 22:46:14 +00004820 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004821 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4822 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4823 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4824 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004825
4826 // Register-register 'add' for thumb does not have a cc_out operand
4827 // when there are only two register operands.
4828 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4829 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4830 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4831 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4832 return true;
Jim Grosbach72f39f82011-08-24 21:22:15 +00004833 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004834 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4835 // have to check the immediate range here since Thumb2 has a variant
4836 // that can handle a different range and has a cc_out operand.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004837 if (((isThumb() && Mnemonic == "add") ||
4838 (isThumbTwo() && Mnemonic == "sub")) &&
4839 Operands.size() == 6 &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004840 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4841 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4842 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004843 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004844 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004845 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004846 return true;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004847 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4848 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004849 // selecting via the generic "add" mnemonic, so to know that we
4850 // should remove the cc_out operand, we have to explicitly check that
4851 // it's not one of the other variants. Ugh.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004852 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4853 Operands.size() == 6 &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004854 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4855 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4856 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4857 // Nest conditions rather than one big 'if' statement for readability.
4858 //
4859 // If either register is a high reg, it's either one of the SP
4860 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach12a88632012-01-21 00:07:56 +00004861 // check against T3. If the second register is the PC, this is an
4862 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004863 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4864 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach12a88632012-01-21 00:07:56 +00004865 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004866 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4867 return false;
4868 // If both registers are low, we're in an IT block, and the immediate is
4869 // in range, we should use encoding T1 instead, which has a cc_out.
4870 if (inITBlock() &&
Jim Grosbach64944f42011-09-14 21:00:40 +00004871 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004872 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4873 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4874 return false;
4875
4876 // Otherwise, we use encoding T4, which does not have a cc_out
4877 // operand.
4878 return true;
4879 }
4880
Jim Grosbach64944f42011-09-14 21:00:40 +00004881 // The thumb2 multiply instruction doesn't have a CCOut register, so
4882 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4883 // use the 16-bit encoding or not.
4884 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4885 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4886 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4887 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4888 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4889 // If the registers aren't low regs, the destination reg isn't the
4890 // same as one of the source regs, or the cc_out operand is zero
4891 // outside of an IT block, we have to use the 32-bit encoding, so
4892 // remove the cc_out operand.
4893 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4894 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach1de0bd12011-11-15 19:29:45 +00004895 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach64944f42011-09-14 21:00:40 +00004896 !inITBlock() ||
4897 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4898 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4899 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4900 static_cast<ARMOperand*>(Operands[4])->getReg())))
4901 return true;
4902
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004903 // Also check the 'mul' syntax variant that doesn't specify an explicit
4904 // destination register.
4905 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4906 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4907 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4908 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4909 // If the registers aren't low regs or the cc_out operand is zero
4910 // outside of an IT block, we have to use the 32-bit encoding, so
4911 // remove the cc_out operand.
4912 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4913 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4914 !inITBlock()))
4915 return true;
4916
Jim Grosbach64944f42011-09-14 21:00:40 +00004917
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004918
Jim Grosbachf69c8042011-08-24 21:42:27 +00004919 // Register-register 'add/sub' for thumb does not have a cc_out operand
4920 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4921 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4922 // right, this will result in better diagnostics (which operand is off)
4923 // anyway.
4924 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4925 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004926 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4927 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004928 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4929 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4930 (Operands.size() == 6 &&
4931 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004932 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004933
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004934 return false;
4935}
4936
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004937static bool isDataTypeToken(StringRef Tok) {
4938 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4939 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4940 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4941 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4942 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4943 Tok == ".f" || Tok == ".d";
4944}
4945
4946// FIXME: This bit should probably be handled via an explicit match class
4947// in the .td files that matches the suffix instead of having it be
4948// a literal string token the way it is now.
4949static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4950 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4951}
4952
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004953static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004954/// Parse an arm instruction mnemonic followed by its operands.
4955bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4956 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004957 // Apply mnemonic aliases before doing anything else, as the destination
4958 // mnemnonic may include suffices and we want to handle them normally.
4959 // The generic tblgen'erated code does this later, at the start of
4960 // MatchInstructionImpl(), but that's too late for aliases that include
4961 // any sort of suffix.
4962 unsigned AvailableFeatures = getAvailableFeatures();
4963 applyMnemonicAliases(Name, AvailableFeatures);
4964
Jim Grosbacha39cda72011-12-14 02:16:11 +00004965 // First check for the ARM-specific .req directive.
4966 if (Parser.getTok().is(AsmToken::Identifier) &&
4967 Parser.getTok().getIdentifier() == ".req") {
4968 parseDirectiveReq(Name, NameLoc);
4969 // We always return 'error' for this, as we're done with this
4970 // statement and don't need to match the 'instruction."
4971 return true;
4972 }
4973
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004974 // Create the leading tokens for the mnemonic, split by '.' characters.
4975 size_t Start = 0, Next = Name.find('.');
Jim Grosbachffa32252011-07-19 19:13:28 +00004976 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004977
Daniel Dunbar352e1482011-01-11 15:59:50 +00004978 // Split out the predication code and carry setting flag from the mnemonic.
4979 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004980 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004981 bool CarrySetting;
Jim Grosbach89df9962011-08-26 21:43:41 +00004982 StringRef ITMask;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004983 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004984 ProcessorIMod, ITMask);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004985
Jim Grosbach0c49ac02011-08-25 17:23:55 +00004986 // In Thumb1, only the branch (B) instruction can be predicated.
4987 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4988 Parser.EatToEndOfStatement();
4989 return Error(NameLoc, "conditional execution not supported in Thumb1");
4990 }
4991
Jim Grosbachffa32252011-07-19 19:13:28 +00004992 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4993
Jim Grosbach89df9962011-08-26 21:43:41 +00004994 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4995 // is the mask as it will be for the IT encoding if the conditional
4996 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4997 // where the conditional bit0 is zero, the instruction post-processing
4998 // will adjust the mask accordingly.
4999 if (Mnemonic == "it") {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005000 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5001 if (ITMask.size() > 3) {
5002 Parser.EatToEndOfStatement();
5003 return Error(Loc, "too many conditions on IT instruction");
5004 }
Jim Grosbach89df9962011-08-26 21:43:41 +00005005 unsigned Mask = 8;
5006 for (unsigned i = ITMask.size(); i != 0; --i) {
5007 char pos = ITMask[i - 1];
5008 if (pos != 't' && pos != 'e') {
5009 Parser.EatToEndOfStatement();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005010 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach89df9962011-08-26 21:43:41 +00005011 }
5012 Mask >>= 1;
5013 if (ITMask[i - 1] == 't')
5014 Mask |= 8;
5015 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005016 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach89df9962011-08-26 21:43:41 +00005017 }
5018
Jim Grosbachffa32252011-07-19 19:13:28 +00005019 // FIXME: This is all a pretty gross hack. We should automatically handle
5020 // optional operands like this via tblgen.
Bill Wendling9717fa92010-11-21 10:56:05 +00005021
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005022 // Next, add the CCOut and ConditionCode operands, if needed.
5023 //
5024 // For mnemonics which can ever incorporate a carry setting bit or predication
5025 // code, our matching model involves us always generating CCOut and
5026 // ConditionCode operands to match the mnemonic "as written" and then we let
5027 // the matcher deal with finding the right instruction or generating an
5028 // appropriate error.
5029 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbach1355cf12011-07-26 17:10:22 +00005030 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005031
Jim Grosbach33c16a22011-07-14 22:04:21 +00005032 // If we had a carry-set on an instruction that can't do that, issue an
5033 // error.
5034 if (!CanAcceptCarrySet && CarrySetting) {
5035 Parser.EatToEndOfStatement();
Jim Grosbachffa32252011-07-19 19:13:28 +00005036 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach33c16a22011-07-14 22:04:21 +00005037 "' can not set flags, but 's' suffix specified");
5038 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +00005039 // If we had a predication code on an instruction that can't do that, issue an
5040 // error.
5041 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5042 Parser.EatToEndOfStatement();
5043 return Error(NameLoc, "instruction '" + Mnemonic +
5044 "' is not predicable, but condition code specified");
5045 }
Jim Grosbach33c16a22011-07-14 22:04:21 +00005046
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005047 // Add the carry setting operand, if necessary.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005048 if (CanAcceptCarrySet) {
5049 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005050 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005051 Loc));
5052 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005053
5054 // Add the predication code operand, if necessary.
5055 if (CanAcceptPredicationCode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005056 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5057 CarrySetting);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005058 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005059 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00005060 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005061
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005062 // Add the processor imod operand, if necessary.
5063 if (ProcessorIMod) {
5064 Operands.push_back(ARMOperand::CreateImm(
5065 MCConstantExpr::Create(ProcessorIMod, getContext()),
5066 NameLoc, NameLoc));
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005067 }
5068
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005069 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00005070 while (Next != StringRef::npos) {
5071 Start = Next;
5072 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005073 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005074
Jim Grosbach7aef99b2011-11-11 23:08:10 +00005075 // Some NEON instructions have an optional datatype suffix that is
5076 // completely ignored. Check for that.
5077 if (isDataTypeToken(ExtraToken) &&
5078 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5079 continue;
5080
Jim Grosbach81d2e392011-09-07 16:06:04 +00005081 if (ExtraToken != ".n") {
5082 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5083 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5084 }
Daniel Dunbar5747b132010-08-11 06:37:16 +00005085 }
5086
5087 // Read the remaining operands.
5088 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005089 // Read the first operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005090 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005091 Parser.EatToEndOfStatement();
5092 return true;
5093 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005094
5095 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00005096 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005097
5098 // Parse and remember the operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005099 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005100 Parser.EatToEndOfStatement();
5101 return true;
5102 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005103 }
5104 }
Jim Grosbach16c74252010-10-29 14:46:02 +00005105
Chris Lattnercbf8a982010-09-11 16:18:25 +00005106 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbach186ffac2011-10-07 18:27:04 +00005107 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00005108 Parser.EatToEndOfStatement();
Jim Grosbach186ffac2011-10-07 18:27:04 +00005109 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00005110 }
Bill Wendling146018f2010-11-06 21:42:12 +00005111
Chris Lattner34e53142010-09-08 05:10:46 +00005112 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbachffa32252011-07-19 19:13:28 +00005113
Jim Grosbachd54b4e62011-08-16 21:12:37 +00005114 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5115 // do and don't have a cc_out optional-def operand. With some spot-checks
5116 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach20ed2e72011-09-01 00:28:52 +00005117 // parse and adjust accordingly before actually matching. We shouldn't ever
5118 // try to remove a cc_out operand that was explicitly set on the the
5119 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5120 // table driven matcher doesn't fit well with the ARM instruction set.
5121 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbachffa32252011-07-19 19:13:28 +00005122 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5123 Operands.erase(Operands.begin() + 1);
5124 delete Op;
5125 }
5126
Jim Grosbachcf121c32011-07-28 21:57:55 +00005127 // ARM mode 'blx' need special handling, as the register operand version
5128 // is predicable, but the label operand version is not. So, we can't rely
5129 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach21ff17c2011-10-07 23:24:09 +00005130 // a k_CondCode operand in the list. If we're trying to match the label
5131 // version, remove the k_CondCode operand here.
Jim Grosbachcf121c32011-07-28 21:57:55 +00005132 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5133 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5134 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5135 Operands.erase(Operands.begin() + 1);
5136 delete Op;
5137 }
Jim Grosbach857e1a72011-08-11 23:51:13 +00005138
5139 // The vector-compare-to-zero instructions have a literal token "#0" at
5140 // the end that comes to here as an immediate operand. Convert it to a
5141 // token to play nicely with the matcher.
5142 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5143 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5144 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5145 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5146 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5147 if (CE && CE->getValue() == 0) {
5148 Operands.erase(Operands.begin() + 5);
5149 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5150 delete Op;
5151 }
5152 }
Jim Grosbach68259142011-10-03 22:30:24 +00005153 // VCMP{E} does the same thing, but with a different operand count.
5154 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5155 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5156 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5157 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5158 if (CE && CE->getValue() == 0) {
5159 Operands.erase(Operands.begin() + 4);
5160 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5161 delete Op;
5162 }
5163 }
Jim Grosbach934755a2011-08-22 23:47:13 +00005164 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach55b02f22011-12-13 20:50:38 +00005165 // end. Convert it to a token here. Take care not to convert those
5166 // that should hit the Thumb2 encoding.
Jim Grosbach934755a2011-08-22 23:47:13 +00005167 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach55b02f22011-12-13 20:50:38 +00005168 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5169 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbach934755a2011-08-22 23:47:13 +00005170 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5171 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5172 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach55b02f22011-12-13 20:50:38 +00005173 if (CE && CE->getValue() == 0 &&
5174 (isThumbOne() ||
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005175 // The cc_out operand matches the IT block.
5176 ((inITBlock() != CarrySetting) &&
5177 // Neither register operand is a high register.
Jim Grosbach55b02f22011-12-13 20:50:38 +00005178 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005179 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbach934755a2011-08-22 23:47:13 +00005180 Operands.erase(Operands.begin() + 5);
5181 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5182 delete Op;
5183 }
5184 }
5185
Chris Lattner98986712010-01-14 22:21:20 +00005186 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00005187}
5188
Jim Grosbach189610f2011-07-26 18:25:39 +00005189// Validate context-sensitive operand constraints.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005190
5191// return 'true' if register list contains non-low GPR registers,
5192// 'false' otherwise. If Reg is in the register list or is HiReg, set
5193// 'containsReg' to true.
5194static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5195 unsigned HiReg, bool &containsReg) {
5196 containsReg = false;
5197 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5198 unsigned OpReg = Inst.getOperand(i).getReg();
5199 if (OpReg == Reg)
5200 containsReg = true;
5201 // Anything other than a low register isn't legal here.
5202 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5203 return true;
5204 }
5205 return false;
5206}
5207
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005208// Check if the specified regisgter is in the register list of the inst,
5209// starting at the indicated operand number.
5210static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5211 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5212 unsigned OpReg = Inst.getOperand(i).getReg();
5213 if (OpReg == Reg)
5214 return true;
5215 }
5216 return false;
5217}
5218
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005219// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5220// the ARMInsts array) instead. Getting that here requires awkward
5221// API changes, though. Better way?
5222namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005223extern const MCInstrDesc ARMInsts[];
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005224}
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005225static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005226 return ARMInsts[Opcode];
5227}
5228
Jim Grosbach189610f2011-07-26 18:25:39 +00005229// FIXME: We would really like to be able to tablegen'erate this.
5230bool ARMAsmParser::
5231validateInstruction(MCInst &Inst,
5232 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005233 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005234 SMLoc Loc = Operands[0]->getStartLoc();
5235 // Check the IT block state first.
Jim Grosbach74423e32012-01-25 19:52:01 +00005236 // NOTE: BKPT instruction has the interesting property of being
5237 // allowed in IT blocks, but not being predicable. It just always
Owen Andersonb6b7f512011-09-13 17:59:19 +00005238 // executes.
Jim Grosbach74423e32012-01-25 19:52:01 +00005239 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5240 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005241 unsigned bit = 1;
5242 if (ITState.FirstCond)
5243 ITState.FirstCond = false;
5244 else
Jim Grosbacha1109882011-09-02 23:22:08 +00005245 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005246 // The instruction must be predicable.
5247 if (!MCID.isPredicable())
5248 return Error(Loc, "instructions in IT block must be predicable");
5249 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5250 unsigned ITCond = bit ? ITState.Cond :
5251 ARMCC::getOppositeCondition(ITState.Cond);
5252 if (Cond != ITCond) {
5253 // Find the condition code Operand to get its SMLoc information.
5254 SMLoc CondLoc;
5255 for (unsigned i = 1; i < Operands.size(); ++i)
5256 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5257 CondLoc = Operands[i]->getStartLoc();
5258 return Error(CondLoc, "incorrect condition in IT block; got '" +
5259 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5260 "', but expected '" +
5261 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5262 }
Jim Grosbachc9a9b442011-08-31 18:29:05 +00005263 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005264 } else if (isThumbTwo() && MCID.isPredicable() &&
5265 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson51f6a7a2011-09-09 21:48:23 +00005266 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5267 Inst.getOpcode() != ARM::t2B)
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005268 return Error(Loc, "predicated instructions must be in IT block");
5269
Jim Grosbach189610f2011-07-26 18:25:39 +00005270 switch (Inst.getOpcode()) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00005271 case ARM::LDRD:
5272 case ARM::LDRD_PRE:
5273 case ARM::LDRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005274 case ARM::LDREXD: {
5275 // Rt2 must be Rt + 1.
5276 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5277 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5278 if (Rt2 != Rt + 1)
5279 return Error(Operands[3]->getStartLoc(),
5280 "destination operands must be sequential");
5281 return false;
5282 }
Jim Grosbach14605d12011-08-11 20:28:23 +00005283 case ARM::STRD: {
5284 // Rt2 must be Rt + 1.
5285 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5286 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5287 if (Rt2 != Rt + 1)
5288 return Error(Operands[3]->getStartLoc(),
5289 "source operands must be sequential");
5290 return false;
5291 }
Jim Grosbach53642c52011-08-10 20:49:18 +00005292 case ARM::STRD_PRE:
5293 case ARM::STRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005294 case ARM::STREXD: {
5295 // Rt2 must be Rt + 1.
5296 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5297 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(2).getReg());
5298 if (Rt2 != Rt + 1)
Jim Grosbach14605d12011-08-11 20:28:23 +00005299 return Error(Operands[3]->getStartLoc(),
Jim Grosbach189610f2011-07-26 18:25:39 +00005300 "source operands must be sequential");
5301 return false;
5302 }
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005303 case ARM::SBFX:
5304 case ARM::UBFX: {
5305 // width must be in range [1, 32-lsb]
5306 unsigned lsb = Inst.getOperand(2).getImm();
5307 unsigned widthm1 = Inst.getOperand(3).getImm();
5308 if (widthm1 >= 32 - lsb)
5309 return Error(Operands[5]->getStartLoc(),
5310 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach00c9a512011-08-16 21:42:31 +00005311 return false;
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005312 }
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005313 case ARM::tLDMIA: {
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005314 // If we're parsing Thumb2, the .w variant is available and handles
5315 // most cases that are normally illegal for a Thumb1 LDM
5316 // instruction. We'll make the transformation in processInstruction()
5317 // if necessary.
5318 //
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005319 // Thumb LDM instructions are writeback iff the base register is not
5320 // in the register list.
5321 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005322 bool hasWritebackToken =
5323 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5324 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbachaa875f82011-08-23 18:13:04 +00005325 bool listContainsBase;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005326 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005327 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5328 "registers must be in range r0-r7");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005329 // If we should have writeback, then there should be a '!' token.
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005330 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005331 return Error(Operands[2]->getStartLoc(),
5332 "writeback operator '!' expected");
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005333 // If we should not have writeback, there must not be a '!'. This is
5334 // true even for the 32-bit wide encodings.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005335 if (listContainsBase && hasWritebackToken)
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005336 return Error(Operands[3]->getStartLoc(),
5337 "writeback operator '!' not allowed when base register "
5338 "in register list");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005339
5340 break;
5341 }
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005342 case ARM::t2LDMIA_UPD: {
5343 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5344 return Error(Operands[4]->getStartLoc(),
5345 "writeback operator '!' not allowed when base register "
5346 "in register list");
5347 break;
5348 }
Jim Grosbach54026372011-11-10 23:17:11 +00005349 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5350 // so only issue a diagnostic for thumb1. The instructions will be
5351 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005352 case ARM::tPOP: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005353 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005354 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5355 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005356 return Error(Operands[2]->getStartLoc(),
5357 "registers must be in range r0-r7 or pc");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005358 break;
5359 }
5360 case ARM::tPUSH: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005361 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005362 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5363 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005364 return Error(Operands[2]->getStartLoc(),
5365 "registers must be in range r0-r7 or lr");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005366 break;
5367 }
Jim Grosbach1e84f192011-08-23 18:15:37 +00005368 case ARM::tSTMIA_UPD: {
5369 bool listContainsBase;
Jim Grosbach8213c962011-09-16 20:50:13 +00005370 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach1e84f192011-08-23 18:15:37 +00005371 return Error(Operands[4]->getStartLoc(),
5372 "registers must be in range r0-r7");
5373 break;
5374 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00005375 case ARM::tADDrSP: {
5376 // If the non-SP source operand and the destination operand are not the
5377 // same, we need thumb2 (for the wide encoding), or we have an error.
5378 if (!isThumbTwo() &&
5379 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5380 return Error(Operands[4]->getStartLoc(),
5381 "source register must be the same as destination");
5382 }
5383 break;
5384 }
Jim Grosbach189610f2011-07-26 18:25:39 +00005385 }
5386
5387 return false;
5388}
5389
Jim Grosbachd7433e22012-01-23 23:45:44 +00005390static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach84defb52011-12-02 22:34:51 +00005391 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005392 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005393 // VST1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005394 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5395 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5396 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5397 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5398 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5399 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5400 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5401 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5402 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005403
5404 // VST2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005405 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5406 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5407 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5408 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5409 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005410
Jim Grosbach7945ead2012-01-24 00:43:12 +00005411 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5412 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5413 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5414 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5415 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005416
Jim Grosbach7945ead2012-01-24 00:43:12 +00005417 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5418 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5419 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5420 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5421 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005422
Jim Grosbach4adb1822012-01-24 00:07:41 +00005423 // VST3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005424 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5425 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5426 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5427 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5428 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5429 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5430 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5431 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5432 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5433 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5434 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5435 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5436 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5437 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5438 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbach4adb1822012-01-24 00:07:41 +00005439
Jim Grosbachd7433e22012-01-23 23:45:44 +00005440 // VST3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005441 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5442 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5443 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5444 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5445 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5446 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5447 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5448 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5449 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5450 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5451 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5452 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5453 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5454 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5455 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5456 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5457 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5458 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbach539aab72012-01-24 00:58:13 +00005459
Jim Grosbach88a54de2012-01-24 18:53:13 +00005460 // VST4LN
5461 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5462 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5463 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5464 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5465 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5466 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5467 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5468 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5469 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5470 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5471 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5472 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5473 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5474 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5475 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5476
Jim Grosbach539aab72012-01-24 00:58:13 +00005477 // VST4
5478 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5479 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5480 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5481 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5482 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5483 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5484 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5485 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5486 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5487 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5488 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5489 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5490 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5491 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5492 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5493 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5494 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5495 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbach84defb52011-12-02 22:34:51 +00005496 }
5497}
5498
Jim Grosbachd7433e22012-01-23 23:45:44 +00005499static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00005500 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005501 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005502 // VLD1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005503 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5504 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5505 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5506 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5507 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5508 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5509 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5510 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5511 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005512
5513 // VLD2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005514 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5515 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5516 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5517 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5518 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5519 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5520 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5521 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5522 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5523 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5524 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5525 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5526 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5527 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5528 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbach3a678af2012-01-23 21:53:26 +00005529
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00005530 // VLD3DUP
5531 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5532 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5533 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5534 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5535 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5536 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5537 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5538 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5539 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5540 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5541 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5542 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5543 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5544 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5545 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5546 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5547 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5548 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5549
Jim Grosbach3a678af2012-01-23 21:53:26 +00005550 // VLD3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005551 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5552 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5553 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5554 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5555 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5556 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5557 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5558 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5559 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5560 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5561 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5562 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5563 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5564 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5565 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachc387fc62012-01-23 23:20:46 +00005566
5567 // VLD3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005568 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5569 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5570 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5571 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5572 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5573 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5574 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5575 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5576 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5577 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5578 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5579 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5580 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5581 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5582 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5583 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5584 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5585 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005586
Jim Grosbache983a132012-01-24 18:37:25 +00005587 // VLD4LN
5588 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5589 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5590 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5591 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5592 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5593 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5594 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5595 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5596 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5597 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5598 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5599 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5600 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5601 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5602 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5603
Jim Grosbacha57a36a2012-01-25 00:01:08 +00005604 // VLD4DUP
5605 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5606 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5607 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5608 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5609 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5610 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5611 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5612 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5613 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5614 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5615 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5616 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5617 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5618 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5619 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5620 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5621 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5622 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5623
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005624 // VLD4
5625 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5626 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5627 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5628 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5629 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5630 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5631 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5632 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5633 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5634 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5635 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5636 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5637 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5638 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5639 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5640 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5641 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5642 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach7636bf62011-12-02 00:35:16 +00005643 }
5644}
5645
Jim Grosbach83ec8772011-11-10 23:42:14 +00005646bool ARMAsmParser::
Jim Grosbachf8fce712011-08-11 17:35:48 +00005647processInstruction(MCInst &Inst,
5648 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5649 switch (Inst.getOpcode()) {
Jim Grosbach0b4c6732012-01-18 22:46:46 +00005650 // Aliases for alternate PC+imm syntax of LDR instructions.
5651 case ARM::t2LDRpcrel:
5652 Inst.setOpcode(ARM::t2LDRpci);
5653 return true;
5654 case ARM::t2LDRBpcrel:
5655 Inst.setOpcode(ARM::t2LDRBpci);
5656 return true;
5657 case ARM::t2LDRHpcrel:
5658 Inst.setOpcode(ARM::t2LDRHpci);
5659 return true;
5660 case ARM::t2LDRSBpcrel:
5661 Inst.setOpcode(ARM::t2LDRSBpci);
5662 return true;
5663 case ARM::t2LDRSHpcrel:
5664 Inst.setOpcode(ARM::t2LDRSHpci);
5665 return true;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005666 // Handle NEON VST complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005667 case ARM::VST1LNdWB_register_Asm_8:
5668 case ARM::VST1LNdWB_register_Asm_16:
5669 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005670 MCInst TmpInst;
5671 // Shuffle the operands around so the lane index operand is in the
5672 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005673 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005674 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005675 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5676 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5677 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5678 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5679 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5680 TmpInst.addOperand(Inst.getOperand(1)); // lane
5681 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5682 TmpInst.addOperand(Inst.getOperand(6));
5683 Inst = TmpInst;
5684 return true;
5685 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005686
Jim Grosbach8b31f952012-01-23 19:39:08 +00005687 case ARM::VST2LNdWB_register_Asm_8:
5688 case ARM::VST2LNdWB_register_Asm_16:
5689 case ARM::VST2LNdWB_register_Asm_32:
5690 case ARM::VST2LNqWB_register_Asm_16:
5691 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005692 MCInst TmpInst;
5693 // Shuffle the operands around so the lane index operand is in the
5694 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005695 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005696 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005697 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5698 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5699 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5700 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5701 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5703 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005704 TmpInst.addOperand(Inst.getOperand(1)); // lane
5705 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5706 TmpInst.addOperand(Inst.getOperand(6));
5707 Inst = TmpInst;
5708 return true;
5709 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005710
5711 case ARM::VST3LNdWB_register_Asm_8:
5712 case ARM::VST3LNdWB_register_Asm_16:
5713 case ARM::VST3LNdWB_register_Asm_32:
5714 case ARM::VST3LNqWB_register_Asm_16:
5715 case ARM::VST3LNqWB_register_Asm_32: {
5716 MCInst TmpInst;
5717 // Shuffle the operands around so the lane index operand is in the
5718 // right place.
5719 unsigned Spacing;
5720 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5721 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5722 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5723 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5724 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5725 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5727 Spacing));
5728 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5729 Spacing * 2));
5730 TmpInst.addOperand(Inst.getOperand(1)); // lane
5731 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5732 TmpInst.addOperand(Inst.getOperand(6));
5733 Inst = TmpInst;
5734 return true;
5735 }
5736
Jim Grosbach88a54de2012-01-24 18:53:13 +00005737 case ARM::VST4LNdWB_register_Asm_8:
5738 case ARM::VST4LNdWB_register_Asm_16:
5739 case ARM::VST4LNdWB_register_Asm_32:
5740 case ARM::VST4LNqWB_register_Asm_16:
5741 case ARM::VST4LNqWB_register_Asm_32: {
5742 MCInst TmpInst;
5743 // Shuffle the operands around so the lane index operand is in the
5744 // right place.
5745 unsigned Spacing;
5746 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5747 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5748 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5749 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5750 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5751 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5752 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5753 Spacing));
5754 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5755 Spacing * 2));
5756 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5757 Spacing * 3));
5758 TmpInst.addOperand(Inst.getOperand(1)); // lane
5759 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5760 TmpInst.addOperand(Inst.getOperand(6));
5761 Inst = TmpInst;
5762 return true;
5763 }
5764
Jim Grosbach8b31f952012-01-23 19:39:08 +00005765 case ARM::VST1LNdWB_fixed_Asm_8:
5766 case ARM::VST1LNdWB_fixed_Asm_16:
5767 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005768 MCInst TmpInst;
5769 // Shuffle the operands around so the lane index operand is in the
5770 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005771 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005772 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005773 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5774 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5775 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5776 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5777 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5778 TmpInst.addOperand(Inst.getOperand(1)); // lane
5779 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5780 TmpInst.addOperand(Inst.getOperand(5));
5781 Inst = TmpInst;
5782 return true;
5783 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005784
Jim Grosbach8b31f952012-01-23 19:39:08 +00005785 case ARM::VST2LNdWB_fixed_Asm_8:
5786 case ARM::VST2LNdWB_fixed_Asm_16:
5787 case ARM::VST2LNdWB_fixed_Asm_32:
5788 case ARM::VST2LNqWB_fixed_Asm_16:
5789 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005790 MCInst TmpInst;
5791 // Shuffle the operands around so the lane index operand is in the
5792 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005793 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005794 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005795 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5796 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5797 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5798 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5799 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005800 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5801 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005802 TmpInst.addOperand(Inst.getOperand(1)); // lane
5803 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5804 TmpInst.addOperand(Inst.getOperand(5));
5805 Inst = TmpInst;
5806 return true;
5807 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005808
5809 case ARM::VST3LNdWB_fixed_Asm_8:
5810 case ARM::VST3LNdWB_fixed_Asm_16:
5811 case ARM::VST3LNdWB_fixed_Asm_32:
5812 case ARM::VST3LNqWB_fixed_Asm_16:
5813 case ARM::VST3LNqWB_fixed_Asm_32: {
5814 MCInst TmpInst;
5815 // Shuffle the operands around so the lane index operand is in the
5816 // right place.
5817 unsigned Spacing;
5818 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5819 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5820 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5821 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5822 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5823 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5824 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5825 Spacing));
5826 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5827 Spacing * 2));
5828 TmpInst.addOperand(Inst.getOperand(1)); // lane
5829 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5830 TmpInst.addOperand(Inst.getOperand(5));
5831 Inst = TmpInst;
5832 return true;
5833 }
5834
Jim Grosbach88a54de2012-01-24 18:53:13 +00005835 case ARM::VST4LNdWB_fixed_Asm_8:
5836 case ARM::VST4LNdWB_fixed_Asm_16:
5837 case ARM::VST4LNdWB_fixed_Asm_32:
5838 case ARM::VST4LNqWB_fixed_Asm_16:
5839 case ARM::VST4LNqWB_fixed_Asm_32: {
5840 MCInst TmpInst;
5841 // Shuffle the operands around so the lane index operand is in the
5842 // right place.
5843 unsigned Spacing;
5844 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5845 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5846 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5847 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5848 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5849 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5850 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5851 Spacing));
5852 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5853 Spacing * 2));
5854 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5855 Spacing * 3));
5856 TmpInst.addOperand(Inst.getOperand(1)); // lane
5857 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5858 TmpInst.addOperand(Inst.getOperand(5));
5859 Inst = TmpInst;
5860 return true;
5861 }
5862
Jim Grosbach8b31f952012-01-23 19:39:08 +00005863 case ARM::VST1LNdAsm_8:
5864 case ARM::VST1LNdAsm_16:
5865 case ARM::VST1LNdAsm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005866 MCInst TmpInst;
5867 // Shuffle the operands around so the lane index operand is in the
5868 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005869 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005870 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005871 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5872 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5873 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5874 TmpInst.addOperand(Inst.getOperand(1)); // lane
5875 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5876 TmpInst.addOperand(Inst.getOperand(5));
5877 Inst = TmpInst;
5878 return true;
5879 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005880
Jim Grosbach8b31f952012-01-23 19:39:08 +00005881 case ARM::VST2LNdAsm_8:
5882 case ARM::VST2LNdAsm_16:
5883 case ARM::VST2LNdAsm_32:
5884 case ARM::VST2LNqAsm_16:
5885 case ARM::VST2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005886 MCInst TmpInst;
5887 // Shuffle the operands around so the lane index operand is in the
5888 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005889 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005890 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005891 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5892 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5893 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005894 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5895 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005896 TmpInst.addOperand(Inst.getOperand(1)); // lane
5897 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5898 TmpInst.addOperand(Inst.getOperand(5));
5899 Inst = TmpInst;
5900 return true;
5901 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005902
5903 case ARM::VST3LNdAsm_8:
5904 case ARM::VST3LNdAsm_16:
5905 case ARM::VST3LNdAsm_32:
5906 case ARM::VST3LNqAsm_16:
5907 case ARM::VST3LNqAsm_32: {
5908 MCInst TmpInst;
5909 // Shuffle the operands around so the lane index operand is in the
5910 // right place.
5911 unsigned Spacing;
5912 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5913 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5914 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5915 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5916 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5917 Spacing));
5918 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5919 Spacing * 2));
5920 TmpInst.addOperand(Inst.getOperand(1)); // lane
5921 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5922 TmpInst.addOperand(Inst.getOperand(5));
5923 Inst = TmpInst;
5924 return true;
5925 }
5926
Jim Grosbach88a54de2012-01-24 18:53:13 +00005927 case ARM::VST4LNdAsm_8:
5928 case ARM::VST4LNdAsm_16:
5929 case ARM::VST4LNdAsm_32:
5930 case ARM::VST4LNqAsm_16:
5931 case ARM::VST4LNqAsm_32: {
5932 MCInst TmpInst;
5933 // Shuffle the operands around so the lane index operand is in the
5934 // right place.
5935 unsigned Spacing;
5936 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5937 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5938 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5939 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5940 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5941 Spacing));
5942 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5943 Spacing * 2));
5944 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5945 Spacing * 3));
5946 TmpInst.addOperand(Inst.getOperand(1)); // lane
5947 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5948 TmpInst.addOperand(Inst.getOperand(5));
5949 Inst = TmpInst;
5950 return true;
5951 }
5952
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005953 // Handle NEON VLD complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005954 case ARM::VLD1LNdWB_register_Asm_8:
5955 case ARM::VLD1LNdWB_register_Asm_16:
5956 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005957 MCInst TmpInst;
5958 // Shuffle the operands around so the lane index operand is in the
5959 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005960 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005961 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005962 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5963 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5964 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5965 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5966 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5967 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5968 TmpInst.addOperand(Inst.getOperand(1)); // lane
5969 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5970 TmpInst.addOperand(Inst.getOperand(6));
5971 Inst = TmpInst;
5972 return true;
5973 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005974
Jim Grosbach8b31f952012-01-23 19:39:08 +00005975 case ARM::VLD2LNdWB_register_Asm_8:
5976 case ARM::VLD2LNdWB_register_Asm_16:
5977 case ARM::VLD2LNdWB_register_Asm_32:
5978 case ARM::VLD2LNqWB_register_Asm_16:
5979 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005980 MCInst TmpInst;
5981 // Shuffle the operands around so the lane index operand is in the
5982 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005983 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005984 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005985 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005986 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5987 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005988 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5989 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5990 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5991 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5992 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005993 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5994 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005995 TmpInst.addOperand(Inst.getOperand(1)); // lane
5996 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5997 TmpInst.addOperand(Inst.getOperand(6));
5998 Inst = TmpInst;
5999 return true;
6000 }
6001
Jim Grosbach3a678af2012-01-23 21:53:26 +00006002 case ARM::VLD3LNdWB_register_Asm_8:
6003 case ARM::VLD3LNdWB_register_Asm_16:
6004 case ARM::VLD3LNdWB_register_Asm_32:
6005 case ARM::VLD3LNqWB_register_Asm_16:
6006 case ARM::VLD3LNqWB_register_Asm_32: {
6007 MCInst TmpInst;
6008 // Shuffle the operands around so the lane index operand is in the
6009 // right place.
6010 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006011 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006012 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6013 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6014 Spacing));
6015 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006016 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006017 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6018 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6019 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6020 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6021 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6022 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6023 Spacing));
6024 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006025 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006026 TmpInst.addOperand(Inst.getOperand(1)); // lane
6027 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6028 TmpInst.addOperand(Inst.getOperand(6));
6029 Inst = TmpInst;
6030 return true;
6031 }
6032
Jim Grosbache983a132012-01-24 18:37:25 +00006033 case ARM::VLD4LNdWB_register_Asm_8:
6034 case ARM::VLD4LNdWB_register_Asm_16:
6035 case ARM::VLD4LNdWB_register_Asm_32:
6036 case ARM::VLD4LNqWB_register_Asm_16:
6037 case ARM::VLD4LNqWB_register_Asm_32: {
6038 MCInst TmpInst;
6039 // Shuffle the operands around so the lane index operand is in the
6040 // right place.
6041 unsigned Spacing;
6042 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6043 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6045 Spacing));
6046 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6047 Spacing * 2));
6048 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6049 Spacing * 3));
6050 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6051 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6052 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6053 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6054 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6055 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6056 Spacing));
6057 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6058 Spacing * 2));
6059 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6060 Spacing * 3));
6061 TmpInst.addOperand(Inst.getOperand(1)); // lane
6062 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6063 TmpInst.addOperand(Inst.getOperand(6));
6064 Inst = TmpInst;
6065 return true;
6066 }
6067
Jim Grosbach8b31f952012-01-23 19:39:08 +00006068 case ARM::VLD1LNdWB_fixed_Asm_8:
6069 case ARM::VLD1LNdWB_fixed_Asm_16:
6070 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00006071 MCInst TmpInst;
6072 // Shuffle the operands around so the lane index operand is in the
6073 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006074 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006075 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00006076 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6077 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6078 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6079 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6080 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6081 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6082 TmpInst.addOperand(Inst.getOperand(1)); // lane
6083 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6084 TmpInst.addOperand(Inst.getOperand(5));
6085 Inst = TmpInst;
6086 return true;
6087 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006088
Jim Grosbach8b31f952012-01-23 19:39:08 +00006089 case ARM::VLD2LNdWB_fixed_Asm_8:
6090 case ARM::VLD2LNdWB_fixed_Asm_16:
6091 case ARM::VLD2LNdWB_fixed_Asm_32:
6092 case ARM::VLD2LNqWB_fixed_Asm_16:
6093 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006094 MCInst TmpInst;
6095 // Shuffle the operands around so the lane index operand is in the
6096 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006097 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006098 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006099 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006100 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6101 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006102 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6103 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6104 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6105 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6106 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006107 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6108 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006109 TmpInst.addOperand(Inst.getOperand(1)); // lane
6110 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6111 TmpInst.addOperand(Inst.getOperand(5));
6112 Inst = TmpInst;
6113 return true;
6114 }
6115
Jim Grosbach3a678af2012-01-23 21:53:26 +00006116 case ARM::VLD3LNdWB_fixed_Asm_8:
6117 case ARM::VLD3LNdWB_fixed_Asm_16:
6118 case ARM::VLD3LNdWB_fixed_Asm_32:
6119 case ARM::VLD3LNqWB_fixed_Asm_16:
6120 case ARM::VLD3LNqWB_fixed_Asm_32: {
6121 MCInst TmpInst;
6122 // Shuffle the operands around so the lane index operand is in the
6123 // right place.
6124 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006125 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006126 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6127 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6128 Spacing));
6129 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006130 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006131 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6132 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6133 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6134 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6135 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6136 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6137 Spacing));
6138 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006139 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006140 TmpInst.addOperand(Inst.getOperand(1)); // lane
6141 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6142 TmpInst.addOperand(Inst.getOperand(5));
6143 Inst = TmpInst;
6144 return true;
6145 }
6146
Jim Grosbache983a132012-01-24 18:37:25 +00006147 case ARM::VLD4LNdWB_fixed_Asm_8:
6148 case ARM::VLD4LNdWB_fixed_Asm_16:
6149 case ARM::VLD4LNdWB_fixed_Asm_32:
6150 case ARM::VLD4LNqWB_fixed_Asm_16:
6151 case ARM::VLD4LNqWB_fixed_Asm_32: {
6152 MCInst TmpInst;
6153 // Shuffle the operands around so the lane index operand is in the
6154 // right place.
6155 unsigned Spacing;
6156 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6157 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6158 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6159 Spacing));
6160 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6161 Spacing * 2));
6162 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6163 Spacing * 3));
6164 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6165 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6166 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6167 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6168 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6169 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6170 Spacing));
6171 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6172 Spacing * 2));
6173 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6174 Spacing * 3));
6175 TmpInst.addOperand(Inst.getOperand(1)); // lane
6176 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6177 TmpInst.addOperand(Inst.getOperand(5));
6178 Inst = TmpInst;
6179 return true;
6180 }
6181
Jim Grosbach8b31f952012-01-23 19:39:08 +00006182 case ARM::VLD1LNdAsm_8:
6183 case ARM::VLD1LNdAsm_16:
6184 case ARM::VLD1LNdAsm_32: {
Jim Grosbach7636bf62011-12-02 00:35:16 +00006185 MCInst TmpInst;
6186 // Shuffle the operands around so the lane index operand is in the
6187 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006188 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006189 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach7636bf62011-12-02 00:35:16 +00006190 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6191 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6192 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6193 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6194 TmpInst.addOperand(Inst.getOperand(1)); // lane
6195 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6196 TmpInst.addOperand(Inst.getOperand(5));
6197 Inst = TmpInst;
6198 return true;
6199 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006200
Jim Grosbach8b31f952012-01-23 19:39:08 +00006201 case ARM::VLD2LNdAsm_8:
6202 case ARM::VLD2LNdAsm_16:
6203 case ARM::VLD2LNdAsm_32:
6204 case ARM::VLD2LNqAsm_16:
6205 case ARM::VLD2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006206 MCInst TmpInst;
6207 // Shuffle the operands around so the lane index operand is in the
6208 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006209 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006210 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006211 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006212 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6213 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006214 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6215 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6216 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006217 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6218 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006219 TmpInst.addOperand(Inst.getOperand(1)); // lane
6220 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6221 TmpInst.addOperand(Inst.getOperand(5));
6222 Inst = TmpInst;
6223 return true;
6224 }
Jim Grosbach3a678af2012-01-23 21:53:26 +00006225
6226 case ARM::VLD3LNdAsm_8:
6227 case ARM::VLD3LNdAsm_16:
6228 case ARM::VLD3LNdAsm_32:
6229 case ARM::VLD3LNqAsm_16:
6230 case ARM::VLD3LNqAsm_32: {
6231 MCInst TmpInst;
6232 // Shuffle the operands around so the lane index operand is in the
6233 // right place.
6234 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006235 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006236 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6237 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6238 Spacing));
6239 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006240 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006241 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6242 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6243 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6244 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6245 Spacing));
6246 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006247 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006248 TmpInst.addOperand(Inst.getOperand(1)); // lane
6249 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6250 TmpInst.addOperand(Inst.getOperand(5));
6251 Inst = TmpInst;
6252 return true;
6253 }
6254
Jim Grosbache983a132012-01-24 18:37:25 +00006255 case ARM::VLD4LNdAsm_8:
6256 case ARM::VLD4LNdAsm_16:
6257 case ARM::VLD4LNdAsm_32:
6258 case ARM::VLD4LNqAsm_16:
6259 case ARM::VLD4LNqAsm_32: {
6260 MCInst TmpInst;
6261 // Shuffle the operands around so the lane index operand is in the
6262 // right place.
6263 unsigned Spacing;
6264 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6265 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6266 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6267 Spacing));
6268 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6269 Spacing * 2));
6270 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6271 Spacing * 3));
6272 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6273 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6274 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6275 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6276 Spacing));
6277 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6278 Spacing * 2));
6279 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6280 Spacing * 3));
6281 TmpInst.addOperand(Inst.getOperand(1)); // lane
6282 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6283 TmpInst.addOperand(Inst.getOperand(5));
6284 Inst = TmpInst;
6285 return true;
6286 }
6287
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00006288 // VLD3DUP single 3-element structure to all lanes instructions.
6289 case ARM::VLD3DUPdAsm_8:
6290 case ARM::VLD3DUPdAsm_16:
6291 case ARM::VLD3DUPdAsm_32:
6292 case ARM::VLD3DUPqAsm_8:
6293 case ARM::VLD3DUPqAsm_16:
6294 case ARM::VLD3DUPqAsm_32: {
6295 MCInst TmpInst;
6296 unsigned Spacing;
6297 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6298 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6299 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6300 Spacing));
6301 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 Spacing * 2));
6303 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6304 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6305 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6306 TmpInst.addOperand(Inst.getOperand(4));
6307 Inst = TmpInst;
6308 return true;
6309 }
6310
6311 case ARM::VLD3DUPdWB_fixed_Asm_8:
6312 case ARM::VLD3DUPdWB_fixed_Asm_16:
6313 case ARM::VLD3DUPdWB_fixed_Asm_32:
6314 case ARM::VLD3DUPqWB_fixed_Asm_8:
6315 case ARM::VLD3DUPqWB_fixed_Asm_16:
6316 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6317 MCInst TmpInst;
6318 unsigned Spacing;
6319 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6320 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6321 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6322 Spacing));
6323 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6324 Spacing * 2));
6325 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6326 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6327 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6328 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6329 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6330 TmpInst.addOperand(Inst.getOperand(4));
6331 Inst = TmpInst;
6332 return true;
6333 }
6334
6335 case ARM::VLD3DUPdWB_register_Asm_8:
6336 case ARM::VLD3DUPdWB_register_Asm_16:
6337 case ARM::VLD3DUPdWB_register_Asm_32:
6338 case ARM::VLD3DUPqWB_register_Asm_8:
6339 case ARM::VLD3DUPqWB_register_Asm_16:
6340 case ARM::VLD3DUPqWB_register_Asm_32: {
6341 MCInst TmpInst;
6342 unsigned Spacing;
6343 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6344 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6346 Spacing));
6347 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6348 Spacing * 2));
6349 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6350 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6351 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6352 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6353 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6354 TmpInst.addOperand(Inst.getOperand(5));
6355 Inst = TmpInst;
6356 return true;
6357 }
6358
Jim Grosbachc387fc62012-01-23 23:20:46 +00006359 // VLD3 multiple 3-element structure instructions.
6360 case ARM::VLD3dAsm_8:
6361 case ARM::VLD3dAsm_16:
6362 case ARM::VLD3dAsm_32:
6363 case ARM::VLD3qAsm_8:
6364 case ARM::VLD3qAsm_16:
6365 case ARM::VLD3qAsm_32: {
6366 MCInst TmpInst;
6367 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006368 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006369 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6370 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6371 Spacing));
6372 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6373 Spacing * 2));
6374 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6375 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6376 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6377 TmpInst.addOperand(Inst.getOperand(4));
6378 Inst = TmpInst;
6379 return true;
6380 }
6381
6382 case ARM::VLD3dWB_fixed_Asm_8:
6383 case ARM::VLD3dWB_fixed_Asm_16:
6384 case ARM::VLD3dWB_fixed_Asm_32:
6385 case ARM::VLD3qWB_fixed_Asm_8:
6386 case ARM::VLD3qWB_fixed_Asm_16:
6387 case ARM::VLD3qWB_fixed_Asm_32: {
6388 MCInst TmpInst;
6389 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006390 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006391 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6392 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6393 Spacing));
6394 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6395 Spacing * 2));
6396 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6397 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6398 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6399 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6400 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6401 TmpInst.addOperand(Inst.getOperand(4));
6402 Inst = TmpInst;
6403 return true;
6404 }
6405
6406 case ARM::VLD3dWB_register_Asm_8:
6407 case ARM::VLD3dWB_register_Asm_16:
6408 case ARM::VLD3dWB_register_Asm_32:
6409 case ARM::VLD3qWB_register_Asm_8:
6410 case ARM::VLD3qWB_register_Asm_16:
6411 case ARM::VLD3qWB_register_Asm_32: {
6412 MCInst TmpInst;
6413 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006414 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006415 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6416 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6417 Spacing));
6418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6419 Spacing * 2));
6420 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6421 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6422 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6423 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6424 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6425 TmpInst.addOperand(Inst.getOperand(5));
6426 Inst = TmpInst;
6427 return true;
6428 }
6429
Jim Grosbacha57a36a2012-01-25 00:01:08 +00006430 // VLD4DUP single 3-element structure to all lanes instructions.
6431 case ARM::VLD4DUPdAsm_8:
6432 case ARM::VLD4DUPdAsm_16:
6433 case ARM::VLD4DUPdAsm_32:
6434 case ARM::VLD4DUPqAsm_8:
6435 case ARM::VLD4DUPqAsm_16:
6436 case ARM::VLD4DUPqAsm_32: {
6437 MCInst TmpInst;
6438 unsigned Spacing;
6439 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6440 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6441 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6442 Spacing));
6443 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6444 Spacing * 2));
6445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6446 Spacing * 3));
6447 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6448 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6449 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6450 TmpInst.addOperand(Inst.getOperand(4));
6451 Inst = TmpInst;
6452 return true;
6453 }
6454
6455 case ARM::VLD4DUPdWB_fixed_Asm_8:
6456 case ARM::VLD4DUPdWB_fixed_Asm_16:
6457 case ARM::VLD4DUPdWB_fixed_Asm_32:
6458 case ARM::VLD4DUPqWB_fixed_Asm_8:
6459 case ARM::VLD4DUPqWB_fixed_Asm_16:
6460 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6461 MCInst TmpInst;
6462 unsigned Spacing;
6463 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6464 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6465 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6466 Spacing));
6467 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6468 Spacing * 2));
6469 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6470 Spacing * 3));
6471 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6472 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6473 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6474 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6475 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6476 TmpInst.addOperand(Inst.getOperand(4));
6477 Inst = TmpInst;
6478 return true;
6479 }
6480
6481 case ARM::VLD4DUPdWB_register_Asm_8:
6482 case ARM::VLD4DUPdWB_register_Asm_16:
6483 case ARM::VLD4DUPdWB_register_Asm_32:
6484 case ARM::VLD4DUPqWB_register_Asm_8:
6485 case ARM::VLD4DUPqWB_register_Asm_16:
6486 case ARM::VLD4DUPqWB_register_Asm_32: {
6487 MCInst TmpInst;
6488 unsigned Spacing;
6489 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6490 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6491 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6492 Spacing));
6493 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6494 Spacing * 2));
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6496 Spacing * 3));
6497 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6498 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6499 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6500 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6501 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6502 TmpInst.addOperand(Inst.getOperand(5));
6503 Inst = TmpInst;
6504 return true;
6505 }
6506
6507 // VLD4 multiple 4-element structure instructions.
Jim Grosbach8abe7e32012-01-24 00:43:17 +00006508 case ARM::VLD4dAsm_8:
6509 case ARM::VLD4dAsm_16:
6510 case ARM::VLD4dAsm_32:
6511 case ARM::VLD4qAsm_8:
6512 case ARM::VLD4qAsm_16:
6513 case ARM::VLD4qAsm_32: {
6514 MCInst TmpInst;
6515 unsigned Spacing;
6516 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6517 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6518 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6519 Spacing));
6520 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6521 Spacing * 2));
6522 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6523 Spacing * 3));
6524 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6525 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6526 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6527 TmpInst.addOperand(Inst.getOperand(4));
6528 Inst = TmpInst;
6529 return true;
6530 }
6531
6532 case ARM::VLD4dWB_fixed_Asm_8:
6533 case ARM::VLD4dWB_fixed_Asm_16:
6534 case ARM::VLD4dWB_fixed_Asm_32:
6535 case ARM::VLD4qWB_fixed_Asm_8:
6536 case ARM::VLD4qWB_fixed_Asm_16:
6537 case ARM::VLD4qWB_fixed_Asm_32: {
6538 MCInst TmpInst;
6539 unsigned Spacing;
6540 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6541 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6542 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6543 Spacing));
6544 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6545 Spacing * 2));
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6547 Spacing * 3));
6548 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6549 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6550 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6551 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6552 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6553 TmpInst.addOperand(Inst.getOperand(4));
6554 Inst = TmpInst;
6555 return true;
6556 }
6557
6558 case ARM::VLD4dWB_register_Asm_8:
6559 case ARM::VLD4dWB_register_Asm_16:
6560 case ARM::VLD4dWB_register_Asm_32:
6561 case ARM::VLD4qWB_register_Asm_8:
6562 case ARM::VLD4qWB_register_Asm_16:
6563 case ARM::VLD4qWB_register_Asm_32: {
6564 MCInst TmpInst;
6565 unsigned Spacing;
6566 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6567 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6568 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6569 Spacing));
6570 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6571 Spacing * 2));
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6573 Spacing * 3));
6574 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6575 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6576 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6577 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6578 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6579 TmpInst.addOperand(Inst.getOperand(5));
6580 Inst = TmpInst;
6581 return true;
6582 }
6583
Jim Grosbachd7433e22012-01-23 23:45:44 +00006584 // VST3 multiple 3-element structure instructions.
6585 case ARM::VST3dAsm_8:
6586 case ARM::VST3dAsm_16:
6587 case ARM::VST3dAsm_32:
6588 case ARM::VST3qAsm_8:
6589 case ARM::VST3qAsm_16:
6590 case ARM::VST3qAsm_32: {
6591 MCInst TmpInst;
6592 unsigned Spacing;
6593 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6594 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6595 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6596 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6598 Spacing));
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6600 Spacing * 2));
6601 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6602 TmpInst.addOperand(Inst.getOperand(4));
6603 Inst = TmpInst;
6604 return true;
6605 }
6606
6607 case ARM::VST3dWB_fixed_Asm_8:
6608 case ARM::VST3dWB_fixed_Asm_16:
6609 case ARM::VST3dWB_fixed_Asm_32:
6610 case ARM::VST3qWB_fixed_Asm_8:
6611 case ARM::VST3qWB_fixed_Asm_16:
6612 case ARM::VST3qWB_fixed_Asm_32: {
6613 MCInst TmpInst;
6614 unsigned Spacing;
6615 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6616 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6617 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6618 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6619 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6620 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6622 Spacing));
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6624 Spacing * 2));
6625 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6626 TmpInst.addOperand(Inst.getOperand(4));
6627 Inst = TmpInst;
6628 return true;
6629 }
6630
6631 case ARM::VST3dWB_register_Asm_8:
6632 case ARM::VST3dWB_register_Asm_16:
6633 case ARM::VST3dWB_register_Asm_32:
6634 case ARM::VST3qWB_register_Asm_8:
6635 case ARM::VST3qWB_register_Asm_16:
6636 case ARM::VST3qWB_register_Asm_32: {
6637 MCInst TmpInst;
6638 unsigned Spacing;
6639 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6640 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6641 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6642 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6643 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6644 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6645 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6646 Spacing));
6647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6648 Spacing * 2));
6649 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6650 TmpInst.addOperand(Inst.getOperand(5));
6651 Inst = TmpInst;
6652 return true;
6653 }
6654
Jim Grosbach539aab72012-01-24 00:58:13 +00006655 // VST4 multiple 3-element structure instructions.
6656 case ARM::VST4dAsm_8:
6657 case ARM::VST4dAsm_16:
6658 case ARM::VST4dAsm_32:
6659 case ARM::VST4qAsm_8:
6660 case ARM::VST4qAsm_16:
6661 case ARM::VST4qAsm_32: {
6662 MCInst TmpInst;
6663 unsigned Spacing;
6664 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6665 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6666 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6667 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6668 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6669 Spacing));
6670 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6671 Spacing * 2));
6672 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6673 Spacing * 3));
6674 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6675 TmpInst.addOperand(Inst.getOperand(4));
6676 Inst = TmpInst;
6677 return true;
6678 }
6679
6680 case ARM::VST4dWB_fixed_Asm_8:
6681 case ARM::VST4dWB_fixed_Asm_16:
6682 case ARM::VST4dWB_fixed_Asm_32:
6683 case ARM::VST4qWB_fixed_Asm_8:
6684 case ARM::VST4qWB_fixed_Asm_16:
6685 case ARM::VST4qWB_fixed_Asm_32: {
6686 MCInst TmpInst;
6687 unsigned Spacing;
6688 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6689 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6690 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6691 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6692 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6693 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6694 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6695 Spacing));
6696 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6697 Spacing * 2));
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6699 Spacing * 3));
6700 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6701 TmpInst.addOperand(Inst.getOperand(4));
6702 Inst = TmpInst;
6703 return true;
6704 }
6705
6706 case ARM::VST4dWB_register_Asm_8:
6707 case ARM::VST4dWB_register_Asm_16:
6708 case ARM::VST4dWB_register_Asm_32:
6709 case ARM::VST4qWB_register_Asm_8:
6710 case ARM::VST4qWB_register_Asm_16:
6711 case ARM::VST4qWB_register_Asm_32: {
6712 MCInst TmpInst;
6713 unsigned Spacing;
6714 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6715 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6716 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6717 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6718 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6719 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6720 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6721 Spacing));
6722 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6723 Spacing * 2));
6724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 Spacing * 3));
6726 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6727 TmpInst.addOperand(Inst.getOperand(5));
6728 Inst = TmpInst;
6729 return true;
6730 }
6731
Jim Grosbacha5378eb2012-04-11 00:15:16 +00006732 // Handle encoding choice for the shift-immediate instructions.
6733 case ARM::t2LSLri:
6734 case ARM::t2LSRri:
6735 case ARM::t2ASRri: {
6736 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6737 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6738 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6739 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6740 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6741 unsigned NewOpc;
6742 switch (Inst.getOpcode()) {
6743 default: llvm_unreachable("unexpected opcode");
6744 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6745 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6746 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6747 }
6748 // The Thumb1 operands aren't in the same order. Awesome, eh?
6749 MCInst TmpInst;
6750 TmpInst.setOpcode(NewOpc);
6751 TmpInst.addOperand(Inst.getOperand(0));
6752 TmpInst.addOperand(Inst.getOperand(5));
6753 TmpInst.addOperand(Inst.getOperand(1));
6754 TmpInst.addOperand(Inst.getOperand(2));
6755 TmpInst.addOperand(Inst.getOperand(3));
6756 TmpInst.addOperand(Inst.getOperand(4));
6757 Inst = TmpInst;
6758 return true;
6759 }
6760 return false;
6761 }
6762
Jim Grosbach863d2af2011-12-13 22:45:11 +00006763 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00006764 case ARM::t2MOVsr:
6765 case ARM::t2MOVSsr: {
6766 // Which instruction to expand to depends on the CCOut operand and
6767 // whether we're in an IT block if the register operands are low
6768 // registers.
6769 bool isNarrow = false;
6770 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6771 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6772 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6773 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6774 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6775 isNarrow = true;
6776 MCInst TmpInst;
6777 unsigned newOpc;
6778 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6779 default: llvm_unreachable("unexpected opcode!");
6780 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6781 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6782 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6783 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6784 }
6785 TmpInst.setOpcode(newOpc);
6786 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6787 if (isNarrow)
6788 TmpInst.addOperand(MCOperand::CreateReg(
6789 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6790 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6791 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6792 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6793 TmpInst.addOperand(Inst.getOperand(5));
6794 if (!isNarrow)
6795 TmpInst.addOperand(MCOperand::CreateReg(
6796 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6797 Inst = TmpInst;
6798 return true;
6799 }
Jim Grosbach863d2af2011-12-13 22:45:11 +00006800 case ARM::t2MOVsi:
6801 case ARM::t2MOVSsi: {
6802 // Which instruction to expand to depends on the CCOut operand and
6803 // whether we're in an IT block if the register operands are low
6804 // registers.
6805 bool isNarrow = false;
6806 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6807 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6808 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6809 isNarrow = true;
6810 MCInst TmpInst;
6811 unsigned newOpc;
6812 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6813 default: llvm_unreachable("unexpected opcode!");
6814 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6815 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6816 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6817 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach520dc782011-12-21 21:04:19 +00006818 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006819 }
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006820 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6821 if (Amount == 32) Amount = 0;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006822 TmpInst.setOpcode(newOpc);
6823 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6824 if (isNarrow)
6825 TmpInst.addOperand(MCOperand::CreateReg(
6826 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6827 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach520dc782011-12-21 21:04:19 +00006828 if (newOpc != ARM::t2RRX)
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006829 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach863d2af2011-12-13 22:45:11 +00006830 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6831 TmpInst.addOperand(Inst.getOperand(4));
6832 if (!isNarrow)
6833 TmpInst.addOperand(MCOperand::CreateReg(
6834 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6835 Inst = TmpInst;
6836 return true;
6837 }
6838 // Handle the ARM mode MOV complex aliases.
Jim Grosbach23f22072011-11-16 18:31:45 +00006839 case ARM::ASRr:
6840 case ARM::LSRr:
6841 case ARM::LSLr:
6842 case ARM::RORr: {
6843 ARM_AM::ShiftOpc ShiftTy;
6844 switch(Inst.getOpcode()) {
6845 default: llvm_unreachable("unexpected opcode!");
6846 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6847 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6848 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6849 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6850 }
Jim Grosbach23f22072011-11-16 18:31:45 +00006851 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6852 MCInst TmpInst;
6853 TmpInst.setOpcode(ARM::MOVsr);
6854 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6855 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6856 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6857 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6858 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6859 TmpInst.addOperand(Inst.getOperand(4));
6860 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6861 Inst = TmpInst;
6862 return true;
6863 }
Jim Grosbachee10ff82011-11-10 19:18:01 +00006864 case ARM::ASRi:
6865 case ARM::LSRi:
6866 case ARM::LSLi:
6867 case ARM::RORi: {
6868 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006869 switch(Inst.getOpcode()) {
6870 default: llvm_unreachable("unexpected opcode!");
6871 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6872 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6873 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6874 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6875 }
6876 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach48b368b2011-11-16 19:05:59 +00006877 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachee10ff82011-11-10 19:18:01 +00006878 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonb56e4112012-04-25 18:00:18 +00006879 // A shift by 32 should be encoded as 0 when permitted
6880 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6881 Amt = 0;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006882 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006883 MCInst TmpInst;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006884 TmpInst.setOpcode(Opc);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006885 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6886 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachee10ff82011-11-10 19:18:01 +00006887 if (Opc == ARM::MOVsi)
6888 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach71810ab2011-11-10 16:44:55 +00006889 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6890 TmpInst.addOperand(Inst.getOperand(4));
6891 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6892 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006893 return true;
Jim Grosbach71810ab2011-11-10 16:44:55 +00006894 }
Jim Grosbach48b368b2011-11-16 19:05:59 +00006895 case ARM::RRXi: {
6896 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6897 MCInst TmpInst;
6898 TmpInst.setOpcode(ARM::MOVsi);
6899 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6900 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6901 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6902 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6903 TmpInst.addOperand(Inst.getOperand(3));
6904 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6905 Inst = TmpInst;
6906 return true;
6907 }
Jim Grosbach0352b462011-11-10 23:58:34 +00006908 case ARM::t2LDMIA_UPD: {
6909 // If this is a load of a single register, then we should use
6910 // a post-indexed LDR instruction instead, per the ARM ARM.
6911 if (Inst.getNumOperands() != 5)
6912 return false;
6913 MCInst TmpInst;
6914 TmpInst.setOpcode(ARM::t2LDR_POST);
6915 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6916 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6917 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6918 TmpInst.addOperand(MCOperand::CreateImm(4));
6919 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6920 TmpInst.addOperand(Inst.getOperand(3));
6921 Inst = TmpInst;
6922 return true;
6923 }
6924 case ARM::t2STMDB_UPD: {
6925 // If this is a store of a single register, then we should use
6926 // a pre-indexed STR instruction instead, per the ARM ARM.
6927 if (Inst.getNumOperands() != 5)
6928 return false;
6929 MCInst TmpInst;
6930 TmpInst.setOpcode(ARM::t2STR_PRE);
6931 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6932 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6933 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6934 TmpInst.addOperand(MCOperand::CreateImm(-4));
6935 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6936 TmpInst.addOperand(Inst.getOperand(3));
6937 Inst = TmpInst;
6938 return true;
6939 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00006940 case ARM::LDMIA_UPD:
6941 // If this is a load of a single register via a 'pop', then we should use
6942 // a post-indexed LDR instruction instead, per the ARM ARM.
6943 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6944 Inst.getNumOperands() == 5) {
6945 MCInst TmpInst;
6946 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6947 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6948 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6949 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6950 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6951 TmpInst.addOperand(MCOperand::CreateImm(4));
6952 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6953 TmpInst.addOperand(Inst.getOperand(3));
6954 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006955 return true;
Jim Grosbachf8fce712011-08-11 17:35:48 +00006956 }
6957 break;
Jim Grosbachf6713912011-08-11 18:07:11 +00006958 case ARM::STMDB_UPD:
6959 // If this is a store of a single register via a 'push', then we should use
6960 // a pre-indexed STR instruction instead, per the ARM ARM.
6961 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6962 Inst.getNumOperands() == 5) {
6963 MCInst TmpInst;
6964 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6965 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6966 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6967 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6968 TmpInst.addOperand(MCOperand::CreateImm(-4));
6969 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6970 TmpInst.addOperand(Inst.getOperand(3));
6971 Inst = TmpInst;
6972 }
6973 break;
Jim Grosbachda847862011-12-05 21:06:26 +00006974 case ARM::t2ADDri12:
6975 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6976 // mnemonic was used (not "addw"), encoding T3 is preferred.
6977 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6978 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6979 break;
6980 Inst.setOpcode(ARM::t2ADDri);
6981 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6982 break;
6983 case ARM::t2SUBri12:
6984 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6985 // mnemonic was used (not "subw"), encoding T3 is preferred.
6986 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6987 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6988 break;
6989 Inst.setOpcode(ARM::t2SUBri);
6990 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6991 break;
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006992 case ARM::tADDi8:
Jim Grosbach0f3abd82011-08-31 17:07:33 +00006993 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6994 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6995 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6996 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00006997 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006998 Inst.setOpcode(ARM::tADDi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006999 return true;
7000 }
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007001 break;
Jim Grosbachf67e8552011-09-16 22:58:42 +00007002 case ARM::tSUBi8:
7003 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7004 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7005 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7006 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007007 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachf67e8552011-09-16 22:58:42 +00007008 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007009 return true;
7010 }
Jim Grosbachf67e8552011-09-16 22:58:42 +00007011 break;
Jim Grosbach2d30d942012-03-30 17:20:40 +00007012 case ARM::t2ADDri:
7013 case ARM::t2SUBri: {
7014 // If the destination and first source operand are the same, and
7015 // the flags are compatible with the current IT status, use encoding T2
7016 // instead of T3. For compatibility with the system 'as'. Make sure the
7017 // wide encoding wasn't explicit.
7018 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach8f1148b2012-03-30 18:39:43 +00007019 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbach2d30d942012-03-30 17:20:40 +00007020 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7021 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7022 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7023 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7024 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7025 break;
7026 MCInst TmpInst;
7027 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7028 ARM::tADDi8 : ARM::tSUBi8);
7029 TmpInst.addOperand(Inst.getOperand(0));
7030 TmpInst.addOperand(Inst.getOperand(5));
7031 TmpInst.addOperand(Inst.getOperand(0));
7032 TmpInst.addOperand(Inst.getOperand(2));
7033 TmpInst.addOperand(Inst.getOperand(3));
7034 TmpInst.addOperand(Inst.getOperand(4));
7035 Inst = TmpInst;
7036 return true;
7037 }
Jim Grosbach927b9df2011-12-05 22:16:39 +00007038 case ARM::t2ADDrr: {
7039 // If the destination and first source operand are the same, and
7040 // there's no setting of the flags, use encoding T2 instead of T3.
7041 // Note that this is only for ADD, not SUB. This mirrors the system
7042 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7043 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7044 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbach713c7022011-12-05 22:27:04 +00007045 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7046 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbach927b9df2011-12-05 22:16:39 +00007047 break;
7048 MCInst TmpInst;
7049 TmpInst.setOpcode(ARM::tADDhirr);
7050 TmpInst.addOperand(Inst.getOperand(0));
7051 TmpInst.addOperand(Inst.getOperand(0));
7052 TmpInst.addOperand(Inst.getOperand(2));
7053 TmpInst.addOperand(Inst.getOperand(3));
7054 TmpInst.addOperand(Inst.getOperand(4));
7055 Inst = TmpInst;
7056 return true;
7057 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00007058 case ARM::tADDrSP: {
7059 // If the non-SP source operand and the destination operand are not the
7060 // same, we need to use the 32-bit encoding if it's available.
7061 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7062 Inst.setOpcode(ARM::t2ADDrr);
7063 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7064 return true;
7065 }
7066 break;
7067 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007068 case ARM::tB:
7069 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007070 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007071 Inst.setOpcode(ARM::tBcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007072 return true;
7073 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007074 break;
7075 case ARM::t2B:
7076 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007077 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007078 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007079 return true;
7080 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007081 break;
Jim Grosbachc0755102011-08-31 21:17:31 +00007082 case ARM::t2Bcc:
Jim Grosbacha1109882011-09-02 23:22:08 +00007083 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007084 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbachc0755102011-08-31 21:17:31 +00007085 Inst.setOpcode(ARM::t2B);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007086 return true;
7087 }
Jim Grosbachc0755102011-08-31 21:17:31 +00007088 break;
Jim Grosbach395b4532011-08-17 22:57:40 +00007089 case ARM::tBcc:
7090 // If the conditional is AL, we really want tB.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007091 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbach395b4532011-08-17 22:57:40 +00007092 Inst.setOpcode(ARM::tB);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007093 return true;
7094 }
Jim Grosbach3ce23d32011-08-18 16:08:39 +00007095 break;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007096 case ARM::tLDMIA: {
7097 // If the register list contains any high registers, or if the writeback
7098 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7099 // instead if we're in Thumb2. Otherwise, this should have generated
7100 // an error in validateInstruction().
7101 unsigned Rn = Inst.getOperand(0).getReg();
7102 bool hasWritebackToken =
7103 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7104 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7105 bool listContainsBase;
7106 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7107 (!listContainsBase && !hasWritebackToken) ||
7108 (listContainsBase && hasWritebackToken)) {
7109 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7110 assert (isThumbTwo());
7111 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7112 // If we're switching to the updating version, we need to insert
7113 // the writeback tied operand.
7114 if (hasWritebackToken)
7115 Inst.insert(Inst.begin(),
7116 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007117 return true;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007118 }
7119 break;
7120 }
Jim Grosbach8213c962011-09-16 20:50:13 +00007121 case ARM::tSTMIA_UPD: {
7122 // If the register list contains any high registers, we need to use
7123 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7124 // should have generated an error in validateInstruction().
7125 unsigned Rn = Inst.getOperand(0).getReg();
7126 bool listContainsBase;
7127 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7128 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7129 assert (isThumbTwo());
7130 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007131 return true;
Jim Grosbach8213c962011-09-16 20:50:13 +00007132 }
7133 break;
7134 }
Jim Grosbach54026372011-11-10 23:17:11 +00007135 case ARM::tPOP: {
7136 bool listContainsBase;
7137 // If the register list contains any high registers, we need to use
7138 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7139 // should have generated an error in validateInstruction().
7140 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007141 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007142 assert (isThumbTwo());
7143 Inst.setOpcode(ARM::t2LDMIA_UPD);
7144 // Add the base register and writeback operands.
7145 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7146 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007147 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007148 }
7149 case ARM::tPUSH: {
7150 bool listContainsBase;
7151 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007152 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007153 assert (isThumbTwo());
7154 Inst.setOpcode(ARM::t2STMDB_UPD);
7155 // Add the base register and writeback operands.
7156 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7157 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007158 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007159 }
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007160 case ARM::t2MOVi: {
7161 // If we can use the 16-bit encoding and the user didn't explicitly
7162 // request the 32-bit variant, transform it here.
7163 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbachc0164f82012-03-30 16:31:31 +00007164 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbachc2d31642011-09-14 19:12:11 +00007165 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7166 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7167 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007168 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7169 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7170 // The operands aren't in the same order for tMOVi8...
7171 MCInst TmpInst;
7172 TmpInst.setOpcode(ARM::tMOVi8);
7173 TmpInst.addOperand(Inst.getOperand(0));
7174 TmpInst.addOperand(Inst.getOperand(4));
7175 TmpInst.addOperand(Inst.getOperand(1));
7176 TmpInst.addOperand(Inst.getOperand(2));
7177 TmpInst.addOperand(Inst.getOperand(3));
7178 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007179 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007180 }
7181 break;
7182 }
7183 case ARM::t2MOVr: {
7184 // If we can use the 16-bit encoding and the user didn't explicitly
7185 // request the 32-bit variant, transform it here.
7186 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7187 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7188 Inst.getOperand(2).getImm() == ARMCC::AL &&
7189 Inst.getOperand(4).getReg() == ARM::CPSR &&
7190 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7191 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7192 // The operands aren't the same for tMOV[S]r... (no cc_out)
7193 MCInst TmpInst;
7194 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7195 TmpInst.addOperand(Inst.getOperand(0));
7196 TmpInst.addOperand(Inst.getOperand(1));
7197 TmpInst.addOperand(Inst.getOperand(2));
7198 TmpInst.addOperand(Inst.getOperand(3));
7199 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007200 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007201 }
7202 break;
7203 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007204 case ARM::t2SXTH:
Jim Grosbach50f1c372011-09-20 00:46:54 +00007205 case ARM::t2SXTB:
7206 case ARM::t2UXTH:
7207 case ARM::t2UXTB: {
Jim Grosbach326efe52011-09-19 20:29:33 +00007208 // If we can use the 16-bit encoding and the user didn't explicitly
7209 // request the 32-bit variant, transform it here.
7210 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7211 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7212 Inst.getOperand(2).getImm() == 0 &&
7213 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7214 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbach50f1c372011-09-20 00:46:54 +00007215 unsigned NewOpc;
7216 switch (Inst.getOpcode()) {
7217 default: llvm_unreachable("Illegal opcode!");
7218 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7219 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7220 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7221 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7222 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007223 // The operands aren't the same for thumb1 (no rotate operand).
7224 MCInst TmpInst;
7225 TmpInst.setOpcode(NewOpc);
7226 TmpInst.addOperand(Inst.getOperand(0));
7227 TmpInst.addOperand(Inst.getOperand(1));
7228 TmpInst.addOperand(Inst.getOperand(3));
7229 TmpInst.addOperand(Inst.getOperand(4));
7230 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007231 return true;
Jim Grosbach326efe52011-09-19 20:29:33 +00007232 }
7233 break;
7234 }
Jim Grosbach04b5d932011-12-20 00:59:38 +00007235 case ARM::MOVsi: {
7236 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonb56e4112012-04-25 18:00:18 +00007237 // rrx shifts and asr/lsr of #32 is encoded as 0
7238 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7239 return false;
Jim Grosbach04b5d932011-12-20 00:59:38 +00007240 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7241 // Shifting by zero is accepted as a vanilla 'MOVr'
7242 MCInst TmpInst;
7243 TmpInst.setOpcode(ARM::MOVr);
7244 TmpInst.addOperand(Inst.getOperand(0));
7245 TmpInst.addOperand(Inst.getOperand(1));
7246 TmpInst.addOperand(Inst.getOperand(3));
7247 TmpInst.addOperand(Inst.getOperand(4));
7248 TmpInst.addOperand(Inst.getOperand(5));
7249 Inst = TmpInst;
7250 return true;
7251 }
7252 return false;
7253 }
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007254 case ARM::ANDrsi:
7255 case ARM::ORRrsi:
7256 case ARM::EORrsi:
7257 case ARM::BICrsi:
7258 case ARM::SUBrsi:
7259 case ARM::ADDrsi: {
7260 unsigned newOpc;
7261 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7262 if (SOpc == ARM_AM::rrx) return false;
7263 switch (Inst.getOpcode()) {
Craig Topperbc219812012-02-07 02:50:20 +00007264 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007265 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7266 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7267 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7268 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7269 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7270 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7271 }
7272 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton8ed97ef2012-07-09 16:31:14 +00007273 // The exception is for right shifts, where 0 == 32
7274 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7275 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007276 MCInst TmpInst;
7277 TmpInst.setOpcode(newOpc);
7278 TmpInst.addOperand(Inst.getOperand(0));
7279 TmpInst.addOperand(Inst.getOperand(1));
7280 TmpInst.addOperand(Inst.getOperand(2));
7281 TmpInst.addOperand(Inst.getOperand(4));
7282 TmpInst.addOperand(Inst.getOperand(5));
7283 TmpInst.addOperand(Inst.getOperand(6));
7284 Inst = TmpInst;
7285 return true;
7286 }
7287 return false;
7288 }
Jim Grosbach74423e32012-01-25 19:52:01 +00007289 case ARM::ITasm:
Jim Grosbach89df9962011-08-26 21:43:41 +00007290 case ARM::t2IT: {
7291 // The mask bits for all but the first condition are represented as
7292 // the low bit of the condition code value implies 't'. We currently
7293 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Barton4d2f0772012-04-27 08:42:59 +00007294 // of the condition code is zero.
Jim Grosbach89df9962011-08-26 21:43:41 +00007295 MCOperand &MO = Inst.getOperand(1);
7296 unsigned Mask = MO.getImm();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007297 unsigned OrigMask = Mask;
7298 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach89df9962011-08-26 21:43:41 +00007299 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach89df9962011-08-26 21:43:41 +00007300 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7301 for (unsigned i = 3; i != TZ; --i)
7302 Mask ^= 1 << i;
Richard Barton4d2f0772012-04-27 08:42:59 +00007303 }
Jim Grosbach89df9962011-08-26 21:43:41 +00007304 MO.setImm(Mask);
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007305
7306 // Set up the IT block state according to the IT instruction we just
7307 // matched.
7308 assert(!inITBlock() && "nested IT blocks?!");
7309 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7310 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7311 ITState.CurPosition = 0;
7312 ITState.FirstCond = true;
Jim Grosbach89df9962011-08-26 21:43:41 +00007313 break;
7314 }
Richard Barton2b6652f2012-07-09 16:12:24 +00007315 case ARM::t2LSLrr:
7316 case ARM::t2LSRrr:
7317 case ARM::t2ASRrr:
7318 case ARM::t2SBCrr:
7319 case ARM::t2RORrr:
7320 case ARM::t2BICrr:
7321 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007322 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007323 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7324 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7325 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton874b8632012-07-09 18:30:56 +00007326 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7327 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007328 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7329 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7330 unsigned NewOpc;
7331 switch (Inst.getOpcode()) {
7332 default: llvm_unreachable("unexpected opcode");
7333 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7334 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7335 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7336 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7337 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7338 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7339 }
7340 MCInst TmpInst;
7341 TmpInst.setOpcode(NewOpc);
7342 TmpInst.addOperand(Inst.getOperand(0));
7343 TmpInst.addOperand(Inst.getOperand(5));
7344 TmpInst.addOperand(Inst.getOperand(1));
7345 TmpInst.addOperand(Inst.getOperand(2));
7346 TmpInst.addOperand(Inst.getOperand(3));
7347 TmpInst.addOperand(Inst.getOperand(4));
7348 Inst = TmpInst;
7349 return true;
7350 }
7351 return false;
7352 }
7353 case ARM::t2ANDrr:
7354 case ARM::t2EORrr:
7355 case ARM::t2ADCrr:
7356 case ARM::t2ORRrr:
7357 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007358 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007359 // These instructions are special in that they are commutable, so shorter encodings
7360 // are available more often.
7361 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7362 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7363 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7364 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton874b8632012-07-09 18:30:56 +00007365 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7366 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007367 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7368 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7369 unsigned NewOpc;
7370 switch (Inst.getOpcode()) {
7371 default: llvm_unreachable("unexpected opcode");
7372 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7373 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7374 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7375 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7376 }
7377 MCInst TmpInst;
7378 TmpInst.setOpcode(NewOpc);
7379 TmpInst.addOperand(Inst.getOperand(0));
7380 TmpInst.addOperand(Inst.getOperand(5));
7381 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7382 TmpInst.addOperand(Inst.getOperand(1));
7383 TmpInst.addOperand(Inst.getOperand(2));
7384 } else {
7385 TmpInst.addOperand(Inst.getOperand(2));
7386 TmpInst.addOperand(Inst.getOperand(1));
7387 }
7388 TmpInst.addOperand(Inst.getOperand(3));
7389 TmpInst.addOperand(Inst.getOperand(4));
7390 Inst = TmpInst;
7391 return true;
7392 }
7393 return false;
7394 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00007395 }
Jim Grosbach83ec8772011-11-10 23:42:14 +00007396 return false;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007397}
7398
Jim Grosbach47a0d522011-08-16 20:45:50 +00007399unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7400 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7401 // suffix depending on whether they're in an IT block or not.
Jim Grosbach194bd892011-08-16 22:20:01 +00007402 unsigned Opc = Inst.getOpcode();
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00007403 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach47a0d522011-08-16 20:45:50 +00007404 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7405 assert(MCID.hasOptionalDef() &&
7406 "optionally flag setting instruction missing optional def operand");
7407 assert(MCID.NumOperands == Inst.getNumOperands() &&
7408 "operand count mismatch!");
7409 // Find the optional-def operand (cc_out).
7410 unsigned OpNo;
7411 for (OpNo = 0;
7412 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7413 ++OpNo)
7414 ;
7415 // If we're parsing Thumb1, reject it completely.
7416 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7417 return Match_MnemonicFail;
7418 // If we're parsing Thumb2, which form is legal depends on whether we're
7419 // in an IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007420 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7421 !inITBlock())
Jim Grosbach47a0d522011-08-16 20:45:50 +00007422 return Match_RequiresITBlock;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007423 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7424 inITBlock())
7425 return Match_RequiresNotITBlock;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007426 }
Jim Grosbach194bd892011-08-16 22:20:01 +00007427 // Some high-register supporting Thumb1 encodings only allow both registers
7428 // to be from r0-r7 when in Thumb2.
7429 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7430 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7431 isARMLowRegister(Inst.getOperand(2).getReg()))
7432 return Match_RequiresThumb2;
7433 // Others only require ARMv6 or later.
Jim Grosbach4ec6e882011-08-19 20:46:54 +00007434 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbach194bd892011-08-16 22:20:01 +00007435 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7436 isARMLowRegister(Inst.getOperand(1).getReg()))
7437 return Match_RequiresV6;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007438 return Match_Success;
7439}
7440
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007441static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007442bool ARMAsmParser::
7443MatchAndEmitInstruction(SMLoc IDLoc,
7444 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7445 MCStreamer &Out) {
7446 MCInst Inst;
7447 unsigned ErrorInfo;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007448 unsigned MatchResult;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007449 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007450 switch (MatchResult) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007451 default: break;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007452 case Match_Success:
Jim Grosbach189610f2011-07-26 18:25:39 +00007453 // Context sensitive operand constraints aren't handled by the matcher,
7454 // so check them here.
Jim Grosbacha1109882011-09-02 23:22:08 +00007455 if (validateInstruction(Inst, Operands)) {
7456 // Still progress the IT block, otherwise one wrong condition causes
7457 // nasty cascading errors.
7458 forwardITPosition();
Jim Grosbach189610f2011-07-26 18:25:39 +00007459 return true;
Jim Grosbacha1109882011-09-02 23:22:08 +00007460 }
Jim Grosbach189610f2011-07-26 18:25:39 +00007461
Jim Grosbachf8fce712011-08-11 17:35:48 +00007462 // Some instructions need post-processing to, for example, tweak which
Jim Grosbach83ec8772011-11-10 23:42:14 +00007463 // encoding is selected. Loop on it while changes happen so the
7464 // individual transformations can chain off each other. E.g.,
7465 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7466 while (processInstruction(Inst, Operands))
7467 ;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007468
Jim Grosbacha1109882011-09-02 23:22:08 +00007469 // Only move forward at the very end so that everything in validate
7470 // and process gets a consistent answer about whether we're in an IT
7471 // block.
7472 forwardITPosition();
7473
Jim Grosbach74423e32012-01-25 19:52:01 +00007474 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7475 // doesn't actually encode.
7476 if (Inst.getOpcode() == ARM::ITasm)
7477 return false;
7478
Jim Grosbach42e6bd32012-01-26 23:20:15 +00007479 Inst.setLoc(IDLoc);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007480 Out.EmitInstruction(Inst);
7481 return false;
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007482 case Match_MissingFeature: {
7483 assert(ErrorInfo && "Unknown missing feature!");
7484 // Special case the error message for the very common case where only
7485 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7486 std::string Msg = "instruction requires:";
7487 unsigned Mask = 1;
7488 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7489 if (ErrorInfo & Mask) {
7490 Msg += " ";
7491 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7492 }
7493 Mask <<= 1;
7494 }
7495 return Error(IDLoc, Msg);
7496 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007497 case Match_InvalidOperand: {
7498 SMLoc ErrorLoc = IDLoc;
7499 if (ErrorInfo != ~0U) {
7500 if (ErrorInfo >= Operands.size())
7501 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00007502
Chris Lattnere73d4f82010-10-28 21:41:58 +00007503 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7504 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7505 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007506
Chris Lattnere73d4f82010-10-28 21:41:58 +00007507 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007508 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007509 case Match_MnemonicFail:
Benjamin Kramer362a05a2012-04-15 17:04:27 +00007510 return Error(IDLoc, "invalid instruction",
7511 ((ARMOperand*)Operands[0])->getLocRange());
Daniel Dunbarb4129152011-02-04 17:12:23 +00007512 case Match_ConversionFail:
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00007513 // The converter function will have already emitted a diagnostic.
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00007514 return true;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007515 case Match_RequiresNotITBlock:
7516 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach47a0d522011-08-16 20:45:50 +00007517 case Match_RequiresITBlock:
7518 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbach194bd892011-08-16 22:20:01 +00007519 case Match_RequiresV6:
7520 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7521 case Match_RequiresThumb2:
7522 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach70c9bf32012-06-22 23:56:48 +00007523 case Match_ImmRange0_15: {
7524 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7525 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7526 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7527 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007528 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007529
Eric Christopherc223e2b2010-10-29 09:26:59 +00007530 llvm_unreachable("Implement any new match types added!");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007531}
7532
Jim Grosbach1355cf12011-07-26 17:10:22 +00007533/// parseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007534bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7535 StringRef IDVal = DirectiveID.getIdentifier();
7536 if (IDVal == ".word")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007537 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007538 else if (IDVal == ".thumb")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007539 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach9a70df92011-12-07 18:04:19 +00007540 else if (IDVal == ".arm")
7541 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007542 else if (IDVal == ".thumb_func")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007543 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007544 else if (IDVal == ".code")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007545 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007546 else if (IDVal == ".syntax")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007547 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbacha39cda72011-12-14 02:16:11 +00007548 else if (IDVal == ".unreq")
7549 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kimd7c9e082011-12-20 17:38:12 +00007550 else if (IDVal == ".arch")
7551 return parseDirectiveArch(DirectiveID.getLoc());
7552 else if (IDVal == ".eabi_attribute")
7553 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007554 return true;
7555}
7556
Jim Grosbach1355cf12011-07-26 17:10:22 +00007557/// parseDirectiveWord
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007558/// ::= .word [ expression (, expression)* ]
Jim Grosbach1355cf12011-07-26 17:10:22 +00007559bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007560 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7561 for (;;) {
7562 const MCExpr *Value;
7563 if (getParser().ParseExpression(Value))
7564 return true;
7565
Chris Lattneraaec2052010-01-19 19:46:13 +00007566 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007567
7568 if (getLexer().is(AsmToken::EndOfStatement))
7569 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00007570
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007571 // FIXME: Improve diagnostic.
7572 if (getLexer().isNot(AsmToken::Comma))
7573 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007574 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007575 }
7576 }
7577
Sean Callananb9a25b72010-01-19 20:27:46 +00007578 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007579 return false;
7580}
7581
Jim Grosbach1355cf12011-07-26 17:10:22 +00007582/// parseDirectiveThumb
Kevin Enderby515d5092009-10-15 20:48:48 +00007583/// ::= .thumb
Jim Grosbach1355cf12011-07-26 17:10:22 +00007584bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby515d5092009-10-15 20:48:48 +00007585 if (getLexer().isNot(AsmToken::EndOfStatement))
7586 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007587 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007588
Jim Grosbach9a70df92011-12-07 18:04:19 +00007589 if (!isThumb())
7590 SwitchMode();
7591 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7592 return false;
7593}
7594
7595/// parseDirectiveARM
7596/// ::= .arm
7597bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7598 if (getLexer().isNot(AsmToken::EndOfStatement))
7599 return Error(L, "unexpected token in directive");
7600 Parser.Lex();
7601
7602 if (isThumb())
7603 SwitchMode();
7604 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby515d5092009-10-15 20:48:48 +00007605 return false;
7606}
7607
Jim Grosbach1355cf12011-07-26 17:10:22 +00007608/// parseDirectiveThumbFunc
Kevin Enderby515d5092009-10-15 20:48:48 +00007609/// ::= .thumbfunc symbol_name
Jim Grosbach1355cf12011-07-26 17:10:22 +00007610bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00007611 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7612 bool isMachO = MAI.hasSubsectionsViaSymbols();
7613 StringRef Name;
Jim Grosbachde4d8392011-12-21 22:30:16 +00007614 bool needFuncName = true;
Rafael Espindola64695402011-05-16 16:17:21 +00007615
Jim Grosbachde4d8392011-12-21 22:30:16 +00007616 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindola64695402011-05-16 16:17:21 +00007617 // ELF doesn't
7618 if (isMachO) {
7619 const AsmToken &Tok = Parser.getTok();
Jim Grosbachde4d8392011-12-21 22:30:16 +00007620 if (Tok.isNot(AsmToken::EndOfStatement)) {
7621 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7622 return Error(L, "unexpected token in .thumb_func directive");
7623 Name = Tok.getIdentifier();
7624 Parser.Lex(); // Consume the identifier token.
7625 needFuncName = false;
7626 }
Rafael Espindola64695402011-05-16 16:17:21 +00007627 }
7628
Jim Grosbachde4d8392011-12-21 22:30:16 +00007629 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby515d5092009-10-15 20:48:48 +00007630 return Error(L, "unexpected token in directive");
Jim Grosbachde4d8392011-12-21 22:30:16 +00007631
7632 // Eat the end of statement and any blank lines that follow.
7633 while (getLexer().is(AsmToken::EndOfStatement))
7634 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007635
Rafael Espindola64695402011-05-16 16:17:21 +00007636 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbachde4d8392011-12-21 22:30:16 +00007637 // We really should be checking the next symbol definition even if there's
7638 // stuff in between.
7639 if (needFuncName) {
Jim Grosbachd475f862011-11-10 20:48:53 +00007640 Name = Parser.getTok().getIdentifier();
Rafael Espindola64695402011-05-16 16:17:21 +00007641 }
7642
Jim Grosbach642fc9c2010-11-05 22:33:53 +00007643 // Mark symbol as a thumb symbol.
7644 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7645 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00007646 return false;
7647}
7648
Jim Grosbach1355cf12011-07-26 17:10:22 +00007649/// parseDirectiveSyntax
Kevin Enderby515d5092009-10-15 20:48:48 +00007650/// ::= .syntax unified | divided
Jim Grosbach1355cf12011-07-26 17:10:22 +00007651bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007652 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007653 if (Tok.isNot(AsmToken::Identifier))
7654 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00007655 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00007656 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00007657 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007658 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00007659 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00007660 else
7661 return Error(L, "unrecognized syntax mode in .syntax directive");
7662
7663 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007664 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007665 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007666
7667 // TODO tell the MC streamer the mode
7668 // getParser().getStreamer().Emit???();
7669 return false;
7670}
7671
Jim Grosbach1355cf12011-07-26 17:10:22 +00007672/// parseDirectiveCode
Kevin Enderby515d5092009-10-15 20:48:48 +00007673/// ::= .code 16 | 32
Jim Grosbach1355cf12011-07-26 17:10:22 +00007674bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007675 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007676 if (Tok.isNot(AsmToken::Integer))
7677 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00007678 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00007679 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00007680 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007681 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00007682 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007683 else
7684 return Error(L, "invalid operand to .code directive");
7685
7686 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007687 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007688 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007689
Evan Cheng32869202011-07-08 22:36:29 +00007690 if (Val == 16) {
Jim Grosbach98447da2011-09-06 18:46:23 +00007691 if (!isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007692 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007693 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng32869202011-07-08 22:36:29 +00007694 } else {
Jim Grosbach98447da2011-09-06 18:46:23 +00007695 if (isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007696 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007697 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Chengeb0caa12011-07-08 22:49:55 +00007698 }
Jim Grosbach2a301702010-11-05 22:40:53 +00007699
Kevin Enderby515d5092009-10-15 20:48:48 +00007700 return false;
7701}
7702
Jim Grosbacha39cda72011-12-14 02:16:11 +00007703/// parseDirectiveReq
7704/// ::= name .req registername
7705bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7706 Parser.Lex(); // Eat the '.req' token.
7707 unsigned Reg;
7708 SMLoc SRegLoc, ERegLoc;
7709 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7710 Parser.EatToEndOfStatement();
7711 return Error(SRegLoc, "register name expected");
7712 }
7713
7714 // Shouldn't be anything else.
7715 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7716 Parser.EatToEndOfStatement();
7717 return Error(Parser.getTok().getLoc(),
7718 "unexpected input in .req directive.");
7719 }
7720
7721 Parser.Lex(); // Consume the EndOfStatement
7722
7723 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7724 return Error(SRegLoc, "redefinition of '" + Name +
7725 "' does not match original.");
7726
7727 return false;
7728}
7729
7730/// parseDirectiveUneq
7731/// ::= .unreq registername
7732bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7733 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7734 Parser.EatToEndOfStatement();
7735 return Error(L, "unexpected input in .unreq directive.");
7736 }
7737 RegisterReqs.erase(Parser.getTok().getIdentifier());
7738 Parser.Lex(); // Eat the identifier.
7739 return false;
7740}
7741
Jason W Kimd7c9e082011-12-20 17:38:12 +00007742/// parseDirectiveArch
7743/// ::= .arch token
7744bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7745 return true;
7746}
7747
7748/// parseDirectiveEabiAttr
7749/// ::= .eabi_attribute int, int
7750bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7751 return true;
7752}
7753
Sean Callanan90b70972010-04-07 20:29:34 +00007754extern "C" void LLVMInitializeARMAsmLexer();
7755
Kevin Enderby9c41fa82009-10-30 22:55:57 +00007756/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007757extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng94b95502011-07-26 00:24:13 +00007758 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7759 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00007760 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007761}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007762
Chris Lattner0692ee62010-09-06 19:11:01 +00007763#define GET_REGISTER_MATCHER
Craig Topper8030e1a2012-04-25 06:56:34 +00007764#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner0692ee62010-09-06 19:11:01 +00007765#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007766#include "ARMGenAsmMatcher.inc"