blob: fe11bec93fc95eca3acb2d62bc84463c40edf715 [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
Chad Rosier756d2cc2012-08-31 22:12:31 +0000184 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
185 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
186 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbacheeec0252011-09-08 00:39:19 +0000187 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000188 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachee2c2a42011-09-16 21:55:56 +0000189 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000190 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000191 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000192 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson9ab0f252011-08-26 20:43:14 +0000193 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000194 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbach548340c2011-08-11 19:22:40 +0000195 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000196 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000197 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000198 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbach7b8f46c2011-08-11 21:17:22 +0000199 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000200 void cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +0000201 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000202 void cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +0000203 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000204 void cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +0000205 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000206 void cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +0000207 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000208 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
209 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
210 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbach623a4542011-08-10 22:42:16 +0000211 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000212 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach88ae2bc2011-08-19 22:07:46 +0000213 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000214 void cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach12431322011-10-24 22:16:58 +0000215 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000216 void cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach12431322011-10-24 22:16:58 +0000217 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000218 void cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach4334e032011-10-31 21:50:31 +0000219 const SmallVectorImpl<MCParsedAsmOperand*> &);
Chad Rosier756d2cc2012-08-31 22:12:31 +0000220 void cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach4334e032011-10-31 21:50:31 +0000221 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach189610f2011-07-26 18:25:39 +0000222 bool validateInstruction(MCInst &Inst,
223 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach83ec8772011-11-10 23:42:14 +0000224 bool processInstruction(MCInst &Inst,
Jim Grosbachf8fce712011-08-11 17:35:48 +0000225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachd54b4e62011-08-16 21:12:37 +0000226 bool shouldOmitCCOutOperand(StringRef Mnemonic,
227 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach189610f2011-07-26 18:25:39 +0000228
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000229public:
Jim Grosbach47a0d522011-08-16 20:45:50 +0000230 enum ARMMatchResultTy {
Jim Grosbach194bd892011-08-16 22:20:01 +0000231 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000232 Match_RequiresNotITBlock,
Jim Grosbach194bd892011-08-16 22:20:01 +0000233 Match_RequiresV6,
Jim Grosbach70c9bf32012-06-22 23:56:48 +0000234 Match_RequiresThumb2,
235#define GET_OPERAND_DIAGNOSTIC_TYPES
236#include "ARMGenAsmMatcher.inc"
237
Jim Grosbach47a0d522011-08-16 20:45:50 +0000238 };
239
Evan Chengffc0e732011-07-09 05:47:46 +0000240 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Evan Cheng94b95502011-07-26 00:24:13 +0000241 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
Evan Chengebdeeab2011-07-08 01:53:10 +0000242 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng32869202011-07-08 22:36:29 +0000243
Jim Grosbach28f08c92012-03-05 19:33:30 +0000244 // Cache the MCRegisterInfo.
245 MRI = &getContext().getRegisterInfo();
246
Evan Chengebdeeab2011-07-08 01:53:10 +0000247 // Initialize the set of available features.
Evan Chengffc0e732011-07-09 05:47:46 +0000248 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000249
250 // Not in an ITBlock to start with.
251 ITState.CurPosition = ~0U;
Evan Chengebdeeab2011-07-08 01:53:10 +0000252 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000253
Jim Grosbach1355cf12011-07-26 17:10:22 +0000254 // Implementation of the MCTargetAsmParser interface:
255 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
256 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Jim Grosbach189610f2011-07-26 18:25:39 +0000257 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000258 bool ParseDirective(AsmToken DirectiveID);
259
Jim Grosbach47a0d522011-08-16 20:45:50 +0000260 unsigned checkTargetMatchPredicate(MCInst &Inst);
261
Jim Grosbach1355cf12011-07-26 17:10:22 +0000262 bool MatchAndEmitInstruction(SMLoc IDLoc,
263 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
264 MCStreamer &Out);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000265};
Jim Grosbach16c74252010-10-29 14:46:02 +0000266} // end anonymous namespace
267
Chris Lattner3a697562010-10-28 17:20:03 +0000268namespace {
269
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000270/// ARMOperand - Instances of this class represent a parsed ARM machine
271/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000272class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000273 enum KindTy {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000274 k_CondCode,
275 k_CCOut,
276 k_ITCondMask,
277 k_CoprocNum,
278 k_CoprocReg,
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000279 k_CoprocOption,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000280 k_Immediate,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000281 k_MemBarrierOpt,
282 k_Memory,
283 k_PostIndexRegister,
284 k_MSRMask,
285 k_ProcIFlags,
Jim Grosbach460a9052011-10-07 23:56:00 +0000286 k_VectorIndex,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000287 k_Register,
288 k_RegisterList,
289 k_DPRRegisterList,
290 k_SPRRegisterList,
Jim Grosbach862019c2011-10-18 23:02:30 +0000291 k_VectorList,
Jim Grosbach98b05a52011-11-30 01:09:44 +0000292 k_VectorListAllLanes,
Jim Grosbach7636bf62011-12-02 00:35:16 +0000293 k_VectorListIndexed,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000294 k_ShiftedRegister,
295 k_ShiftedImmediate,
296 k_ShifterImmediate,
297 k_RotateImmediate,
298 k_BitfieldDescriptor,
299 k_Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000300 } Kind;
301
Sean Callanan76264762010-04-02 22:27:05 +0000302 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000303 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000304
305 union {
306 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000307 ARMCC::CondCodes Val;
308 } CC;
309
310 struct {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000311 unsigned Val;
312 } Cop;
313
314 struct {
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000315 unsigned Val;
316 } CoprocOption;
317
318 struct {
Jim Grosbach89df9962011-08-26 21:43:41 +0000319 unsigned Mask:4;
320 } ITMask;
321
322 struct {
323 ARM_MB::MemBOpt Val;
324 } MBOpt;
325
326 struct {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000327 ARM_PROC::IFlags Val;
328 } IFlags;
329
330 struct {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000331 unsigned Val;
332 } MMask;
333
334 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000335 const char *Data;
336 unsigned Length;
337 } Tok;
338
339 struct {
340 unsigned RegNum;
341 } Reg;
342
Jim Grosbach862019c2011-10-18 23:02:30 +0000343 // A vector register list is a sequential list of 1 to 4 registers.
344 struct {
345 unsigned RegNum;
346 unsigned Count;
Jim Grosbach7636bf62011-12-02 00:35:16 +0000347 unsigned LaneIndex;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +0000348 bool isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +0000349 } VectorList;
350
Bill Wendling8155e5b2010-11-06 22:19:43 +0000351 struct {
Jim Grosbach460a9052011-10-07 23:56:00 +0000352 unsigned Val;
353 } VectorIndex;
354
355 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000356 const MCExpr *Val;
357 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000358
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000359 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000360 struct {
361 unsigned BaseRegNum;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000362 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
363 // was specified.
364 const MCConstantExpr *OffsetImm; // Offset immediate value
365 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
366 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbach57dcb852011-10-11 17:29:55 +0000367 unsigned ShiftImm; // shift for OffsetReg.
368 unsigned Alignment; // 0 = no alignment specified
Jim Grosbacheeaf1c12011-12-19 18:31:43 +0000369 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbach7ce05792011-08-03 23:50:40 +0000370 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbache53c87b2011-10-11 15:59:20 +0000371 } Memory;
Owen Anderson00828302011-03-18 22:50:18 +0000372
373 struct {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000374 unsigned RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000375 bool isAdd;
376 ARM_AM::ShiftOpc ShiftTy;
377 unsigned ShiftImm;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000378 } PostIdxReg;
379
380 struct {
Jim Grosbach580f4a92011-07-25 22:20:28 +0000381 bool isASR;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000382 unsigned Imm;
Jim Grosbach580f4a92011-07-25 22:20:28 +0000383 } ShifterImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000384 struct {
385 ARM_AM::ShiftOpc ShiftTy;
386 unsigned SrcReg;
387 unsigned ShiftReg;
388 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000389 } RegShiftedReg;
Owen Anderson92a20222011-07-21 18:54:16 +0000390 struct {
391 ARM_AM::ShiftOpc ShiftTy;
392 unsigned SrcReg;
393 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000394 } RegShiftedImm;
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000395 struct {
396 unsigned Imm;
397 } RotImm;
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000398 struct {
399 unsigned LSB;
400 unsigned Width;
401 } Bitfield;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000402 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000403
Bill Wendling146018f2010-11-06 21:42:12 +0000404 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
405public:
Sean Callanan76264762010-04-02 22:27:05 +0000406 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
407 Kind = o.Kind;
408 StartLoc = o.StartLoc;
409 EndLoc = o.EndLoc;
410 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000411 case k_CondCode:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000412 CC = o.CC;
413 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000414 case k_ITCondMask:
Jim Grosbach89df9962011-08-26 21:43:41 +0000415 ITMask = o.ITMask;
416 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000417 case k_Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000418 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000419 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000420 case k_CCOut:
421 case k_Register:
Sean Callanan76264762010-04-02 22:27:05 +0000422 Reg = o.Reg;
423 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000424 case k_RegisterList:
425 case k_DPRRegisterList:
426 case k_SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000427 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000428 break;
Jim Grosbach862019c2011-10-18 23:02:30 +0000429 case k_VectorList:
Jim Grosbach98b05a52011-11-30 01:09:44 +0000430 case k_VectorListAllLanes:
Jim Grosbach7636bf62011-12-02 00:35:16 +0000431 case k_VectorListIndexed:
Jim Grosbach862019c2011-10-18 23:02:30 +0000432 VectorList = o.VectorList;
433 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000434 case k_CoprocNum:
435 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000436 Cop = o.Cop;
437 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000438 case k_CoprocOption:
439 CoprocOption = o.CoprocOption;
440 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000441 case k_Immediate:
Sean Callanan76264762010-04-02 22:27:05 +0000442 Imm = o.Imm;
443 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000444 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000445 MBOpt = o.MBOpt;
446 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000447 case k_Memory:
Jim Grosbache53c87b2011-10-11 15:59:20 +0000448 Memory = o.Memory;
Sean Callanan76264762010-04-02 22:27:05 +0000449 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000450 case k_PostIndexRegister:
Jim Grosbach7ce05792011-08-03 23:50:40 +0000451 PostIdxReg = o.PostIdxReg;
452 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000453 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000454 MMask = o.MMask;
455 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000456 case k_ProcIFlags:
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000457 IFlags = o.IFlags;
Owen Anderson00828302011-03-18 22:50:18 +0000458 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000459 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +0000460 ShifterImm = o.ShifterImm;
Owen Anderson00828302011-03-18 22:50:18 +0000461 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000462 case k_ShiftedRegister:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000463 RegShiftedReg = o.RegShiftedReg;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000464 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000465 case k_ShiftedImmediate:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000466 RegShiftedImm = o.RegShiftedImm;
Owen Anderson92a20222011-07-21 18:54:16 +0000467 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000468 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000469 RotImm = o.RotImm;
470 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000471 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000472 Bitfield = o.Bitfield;
473 break;
Jim Grosbach460a9052011-10-07 23:56:00 +0000474 case k_VectorIndex:
475 VectorIndex = o.VectorIndex;
476 break;
Sean Callanan76264762010-04-02 22:27:05 +0000477 }
478 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000479
Sean Callanan76264762010-04-02 22:27:05 +0000480 /// getStartLoc - Get the location of the first token of this operand.
481 SMLoc getStartLoc() const { return StartLoc; }
482 /// getEndLoc - Get the location of the last token of this operand.
483 SMLoc getEndLoc() const { return EndLoc; }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000484
Benjamin Kramer362a05a2012-04-15 17:04:27 +0000485 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
486
Daniel Dunbar8462b302010-08-11 06:36:53 +0000487 ARMCC::CondCodes getCondCode() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000488 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000489 return CC.Val;
490 }
491
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000492 unsigned getCoproc() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000493 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000494 return Cop.Val;
495 }
496
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000497 StringRef getToken() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000498 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000499 return StringRef(Tok.Data, Tok.Length);
500 }
501
502 unsigned getReg() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000503 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000504 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000505 }
506
Bill Wendling5fa22a12010-11-09 23:28:44 +0000507 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000508 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
509 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000510 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000511 }
512
Kevin Enderbycfe07242009-10-13 22:19:02 +0000513 const MCExpr *getImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000514 assert(isImm() && "Invalid access!");
Kevin Enderbycfe07242009-10-13 22:19:02 +0000515 return Imm.Val;
516 }
517
Jim Grosbach460a9052011-10-07 23:56:00 +0000518 unsigned getVectorIndex() const {
519 assert(Kind == k_VectorIndex && "Invalid access!");
520 return VectorIndex.Val;
521 }
522
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000523 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000524 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000525 return MBOpt.Val;
526 }
527
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000528 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000529 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000530 return IFlags.Val;
531 }
532
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000533 unsigned getMSRMask() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000534 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000535 return MMask.Val;
536 }
537
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000538 bool isCoprocNum() const { return Kind == k_CoprocNum; }
539 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000540 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000541 bool isCondCode() const { return Kind == k_CondCode; }
542 bool isCCOut() const { return Kind == k_CCOut; }
543 bool isITMask() const { return Kind == k_ITCondMask; }
544 bool isITCondCode() const { return Kind == k_CondCode; }
545 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbach51222d12012-01-20 18:09:51 +0000546 bool isFPImm() const {
547 if (!isImm()) return false;
548 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
549 if (!CE) return false;
550 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
551 return Val != -1;
552 }
Jim Grosbach4050bc42011-12-22 22:19:05 +0000553 bool isFBits16() const {
554 if (!isImm()) return false;
555 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
556 if (!CE) return false;
557 int64_t Value = CE->getValue();
558 return Value >= 0 && Value <= 16;
559 }
560 bool isFBits32() const {
561 if (!isImm()) return false;
562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
563 if (!CE) return false;
564 int64_t Value = CE->getValue();
565 return Value >= 1 && Value <= 32;
566 }
Jim Grosbacha77295d2011-09-08 22:07:06 +0000567 bool isImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000568 if (!isImm()) return false;
Jim Grosbacha77295d2011-09-08 22:07:06 +0000569 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
570 if (!CE) return false;
571 int64_t Value = CE->getValue();
572 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
573 }
Jim Grosbach72f39f82011-08-24 21:22:15 +0000574 bool isImm0_1020s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000575 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000576 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
577 if (!CE) return false;
578 int64_t Value = CE->getValue();
579 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
580 }
581 bool isImm0_508s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000582 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000583 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
584 if (!CE) return false;
585 int64_t Value = CE->getValue();
586 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
587 }
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000588 bool isImm0_508s4Neg() const {
589 if (!isImm()) return false;
590 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
591 if (!CE) return false;
592 int64_t Value = -CE->getValue();
593 // explicitly exclude zero. we want that to use the normal 0_508 version.
594 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
595 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000596 bool isImm0_255() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000597 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
599 if (!CE) return false;
600 int64_t Value = CE->getValue();
601 return Value >= 0 && Value < 256;
602 }
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000603 bool isImm0_4095() const {
604 if (!isImm()) return false;
605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
606 if (!CE) return false;
607 int64_t Value = CE->getValue();
608 return Value >= 0 && Value < 4096;
609 }
610 bool isImm0_4095Neg() const {
611 if (!isImm()) return false;
612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
613 if (!CE) return false;
614 int64_t Value = -CE->getValue();
615 return Value > 0 && Value < 4096;
616 }
Jim Grosbach587f5062011-12-02 23:34:39 +0000617 bool isImm0_1() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000618 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
620 if (!CE) return false;
621 int64_t Value = CE->getValue();
622 return Value >= 0 && Value < 2;
623 }
624 bool isImm0_3() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000625 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000626 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
627 if (!CE) return false;
628 int64_t Value = CE->getValue();
629 return Value >= 0 && Value < 4;
630 }
Jim Grosbach83ab0702011-07-13 22:01:08 +0000631 bool isImm0_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000632 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
634 if (!CE) return false;
635 int64_t Value = CE->getValue();
636 return Value >= 0 && Value < 8;
637 }
638 bool isImm0_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000639 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
641 if (!CE) return false;
642 int64_t Value = CE->getValue();
643 return Value >= 0 && Value < 16;
644 }
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000645 bool isImm0_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000646 if (!isImm()) return false;
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
648 if (!CE) return false;
649 int64_t Value = CE->getValue();
650 return Value >= 0 && Value < 32;
651 }
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000652 bool isImm0_63() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000653 if (!isImm()) return false;
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
655 if (!CE) return false;
656 int64_t Value = CE->getValue();
657 return Value >= 0 && Value < 64;
658 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000659 bool isImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000660 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
662 if (!CE) return false;
663 int64_t Value = CE->getValue();
664 return Value == 8;
665 }
666 bool isImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000667 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
669 if (!CE) return false;
670 int64_t Value = CE->getValue();
671 return Value == 16;
672 }
673 bool isImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000674 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
676 if (!CE) return false;
677 int64_t Value = CE->getValue();
678 return Value == 32;
679 }
Jim Grosbach6b044c22011-12-08 22:06:06 +0000680 bool isShrImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000681 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
683 if (!CE) return false;
684 int64_t Value = CE->getValue();
685 return Value > 0 && Value <= 8;
686 }
687 bool isShrImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000688 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000689 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
690 if (!CE) return false;
691 int64_t Value = CE->getValue();
692 return Value > 0 && Value <= 16;
693 }
694 bool isShrImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000695 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
697 if (!CE) return false;
698 int64_t Value = CE->getValue();
699 return Value > 0 && Value <= 32;
700 }
701 bool isShrImm64() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000702 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
704 if (!CE) return false;
705 int64_t Value = CE->getValue();
706 return Value > 0 && Value <= 64;
707 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000708 bool isImm1_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000709 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
711 if (!CE) return false;
712 int64_t Value = CE->getValue();
713 return Value > 0 && Value < 8;
714 }
715 bool isImm1_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000716 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
718 if (!CE) return false;
719 int64_t Value = CE->getValue();
720 return Value > 0 && Value < 16;
721 }
722 bool isImm1_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000723 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000724 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
725 if (!CE) return false;
726 int64_t Value = CE->getValue();
727 return Value > 0 && Value < 32;
728 }
Jim Grosbachf4943352011-07-25 23:09:14 +0000729 bool isImm1_16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000730 if (!isImm()) return false;
Jim Grosbachf4943352011-07-25 23:09:14 +0000731 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
732 if (!CE) return false;
733 int64_t Value = CE->getValue();
734 return Value > 0 && Value < 17;
735 }
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000736 bool isImm1_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000737 if (!isImm()) return false;
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
739 if (!CE) return false;
740 int64_t Value = CE->getValue();
741 return Value > 0 && Value < 33;
742 }
Jim Grosbachee10ff82011-11-10 19:18:01 +0000743 bool isImm0_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000744 if (!isImm()) return false;
Jim Grosbachee10ff82011-11-10 19:18:01 +0000745 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
746 if (!CE) return false;
747 int64_t Value = CE->getValue();
748 return Value >= 0 && Value < 33;
749 }
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000750 bool isImm0_65535() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000751 if (!isImm()) return false;
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000752 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
753 if (!CE) return false;
754 int64_t Value = CE->getValue();
755 return Value >= 0 && Value < 65536;
756 }
Jim Grosbachffa32252011-07-19 19:13:28 +0000757 bool isImm0_65535Expr() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000758 if (!isImm()) return false;
Jim Grosbachffa32252011-07-19 19:13:28 +0000759 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
760 // If it's not a constant expression, it'll generate a fixup and be
761 // handled later.
762 if (!CE) return true;
763 int64_t Value = CE->getValue();
764 return Value >= 0 && Value < 65536;
765 }
Jim Grosbached838482011-07-26 16:24:27 +0000766 bool isImm24bit() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000767 if (!isImm()) return false;
Jim Grosbached838482011-07-26 16:24:27 +0000768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
769 if (!CE) return false;
770 int64_t Value = CE->getValue();
771 return Value >= 0 && Value <= 0xffffff;
772 }
Jim Grosbach70939ee2011-08-17 21:51:27 +0000773 bool isImmThumbSR() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000774 if (!isImm()) return false;
Jim Grosbach70939ee2011-08-17 21:51:27 +0000775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 if (!CE) return false;
777 int64_t Value = CE->getValue();
778 return Value > 0 && Value < 33;
779 }
Jim Grosbachf6c05252011-07-21 17:23:04 +0000780 bool isPKHLSLImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000781 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
783 if (!CE) return false;
784 int64_t Value = CE->getValue();
785 return Value >= 0 && Value < 32;
786 }
787 bool isPKHASRImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000788 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000789 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
790 if (!CE) return false;
791 int64_t Value = CE->getValue();
792 return Value > 0 && Value <= 32;
793 }
Jiangning Liu1fb27ec2012-08-02 08:13:13 +0000794 bool isAdrLabel() const {
795 // If we have an immediate that's not a constant, treat it as a label
796 // reference needing a fixup. If it is a constant, but it can't fit
797 // into shift immediate encoding, we reject it.
798 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
799 else return (isARMSOImm() || isARMSOImmNeg());
800 }
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000801 bool isARMSOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000802 if (!isImm()) return false;
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return ARM_AM::getSOImmVal(Value) != -1;
807 }
Jim Grosbache70ec842011-10-28 22:50:54 +0000808 bool isARMSOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000809 if (!isImm()) return false;
Jim Grosbache70ec842011-10-28 22:50:54 +0000810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return ARM_AM::getSOImmVal(~Value) != -1;
814 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000815 bool isARMSOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000816 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
818 if (!CE) return false;
819 int64_t Value = CE->getValue();
Jim Grosbachad353c62012-03-30 19:59:02 +0000820 // Only use this when not representable as a plain so_imm.
821 return ARM_AM::getSOImmVal(Value) == -1 &&
822 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000823 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000824 bool isT2SOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000825 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000826 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
827 if (!CE) return false;
828 int64_t Value = CE->getValue();
829 return ARM_AM::getT2SOImmVal(Value) != -1;
830 }
Jim Grosbach89a63372011-10-28 22:36:30 +0000831 bool isT2SOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000832 if (!isImm()) return false;
Jim Grosbach89a63372011-10-28 22:36:30 +0000833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
834 if (!CE) return false;
835 int64_t Value = CE->getValue();
836 return ARM_AM::getT2SOImmVal(~Value) != -1;
837 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000838 bool isT2SOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000839 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000840 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
841 if (!CE) return false;
842 int64_t Value = CE->getValue();
Jim Grosbachad353c62012-03-30 19:59:02 +0000843 // Only use this when not representable as a plain so_imm.
844 return ARM_AM::getT2SOImmVal(Value) == -1 &&
845 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000846 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000847 bool isSetEndImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000848 if (!isImm()) return false;
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000849 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
850 if (!CE) return false;
851 int64_t Value = CE->getValue();
852 return Value == 1 || Value == 0;
853 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000854 bool isReg() const { return Kind == k_Register; }
855 bool isRegList() const { return Kind == k_RegisterList; }
856 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
857 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
858 bool isToken() const { return Kind == k_Token; }
859 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
860 bool isMemory() const { return Kind == k_Memory; }
861 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
862 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
863 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
864 bool isRotImm() const { return Kind == k_RotateImmediate; }
865 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
866 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000867 bool isPostIdxReg() const {
Jim Grosbach430052b2011-11-14 17:52:47 +0000868 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000869 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000870 bool isMemNoOffset(bool alignOK = false) const {
Jim Grosbachf6c35c52011-10-10 23:06:42 +0000871 if (!isMemory())
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000872 return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000873 // No offset of any kind.
Jim Grosbach57dcb852011-10-11 17:29:55 +0000874 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
875 (alignOK || Memory.Alignment == 0);
876 }
Jim Grosbach0b4c6732012-01-18 22:46:46 +0000877 bool isMemPCRelImm12() const {
878 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
879 return false;
880 // Base register must be PC.
881 if (Memory.BaseRegNum != ARM::PC)
882 return false;
883 // Immediate offset in range [-4095, 4095].
884 if (!Memory.OffsetImm) return true;
885 int64_t Val = Memory.OffsetImm->getValue();
886 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
887 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000888 bool isAlignedMemory() const {
889 return isMemNoOffset(true);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000890 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000891 bool isAddrMode2() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000892 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000893 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000894 if (Memory.OffsetRegNum) return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000895 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000896 if (!Memory.OffsetImm) return true;
897 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach7ce05792011-08-03 23:50:40 +0000898 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000899 }
Jim Grosbach039c2e12011-08-04 23:01:30 +0000900 bool isAM2OffsetImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000901 if (!isImm()) return false;
Jim Grosbach039c2e12011-08-04 23:01:30 +0000902 // Immediate offset in range [-4095, 4095].
903 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
904 if (!CE) return false;
905 int64_t Val = CE->getValue();
906 return Val > -4096 && Val < 4096;
907 }
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000908 bool isAddrMode3() const {
Jim Grosbach2f196742011-12-19 23:06:24 +0000909 // If we have an immediate that's not a constant, treat it as a label
910 // reference needing a fixup. If it is a constant, it's something else
911 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000912 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +0000913 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000914 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000915 // No shifts are legal for AM3.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000916 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000917 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000918 if (Memory.OffsetRegNum) return true;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000919 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000920 if (!Memory.OffsetImm) return true;
921 int64_t Val = Memory.OffsetImm->getValue();
Silviu Barangaca3cd412012-05-11 09:10:54 +0000922 // The #-0 offset is encoded as INT32_MIN, and we have to check
923 // for this too.
924 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000925 }
926 bool isAM3Offset() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000927 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000928 return false;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000929 if (Kind == k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000930 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
931 // Immediate offset in range [-255, 255].
932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
933 if (!CE) return false;
934 int64_t Val = CE->getValue();
Jim Grosbach251bf252011-08-10 21:56:18 +0000935 // Special case, #-0 is INT32_MIN.
936 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000937 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000938 bool isAddrMode5() const {
Jim Grosbach681460f2011-11-01 01:24:45 +0000939 // If we have an immediate that's not a constant, treat it as a label
940 // reference needing a fixup. If it is a constant, it's something else
941 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000942 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach681460f2011-11-01 01:24:45 +0000943 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000944 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000945 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000946 if (Memory.OffsetRegNum) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000947 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000948 if (!Memory.OffsetImm) return true;
949 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +0000950 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbach681460f2011-11-01 01:24:45 +0000951 Val == INT32_MIN;
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000952 }
Jim Grosbach7f739be2011-09-19 22:21:13 +0000953 bool isMemTBB() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000954 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000955 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach7f739be2011-09-19 22:21:13 +0000956 return false;
957 return true;
958 }
959 bool isMemTBH() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000960 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000961 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
962 Memory.Alignment != 0 )
Jim Grosbach7f739be2011-09-19 22:21:13 +0000963 return false;
964 return true;
965 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000966 bool isMemRegOffset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000967 if (!isMemory() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendlingf4caf692010-12-14 03:36:38 +0000968 return false;
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000969 return true;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000970 }
Jim Grosbachab899c12011-09-07 23:10:15 +0000971 bool isT2MemRegOffset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000972 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
973 Memory.Alignment != 0)
Jim Grosbachab899c12011-09-07 23:10:15 +0000974 return false;
975 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000976 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbachab899c12011-09-07 23:10:15 +0000977 return true;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000978 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbachab899c12011-09-07 23:10:15 +0000979 return false;
980 return true;
981 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000982 bool isMemThumbRR() const {
983 // Thumb reg+reg addressing is simple. Just two registers, a base and
984 // an offset. No shifts, negations or any other complicating factors.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000985 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000986 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000987 return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000988 return isARMLowRegister(Memory.BaseRegNum) &&
989 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +0000990 }
991 bool isMemThumbRIs4() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000992 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000993 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach60f91a32011-08-19 17:55:24 +0000994 return false;
995 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000996 if (!Memory.OffsetImm) return true;
997 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +0000998 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
999 }
Jim Grosbach38466302011-08-19 18:55:51 +00001000 bool isMemThumbRIs2() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +00001001 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001002 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach38466302011-08-19 18:55:51 +00001003 return false;
1004 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001005 if (!Memory.OffsetImm) return true;
1006 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach38466302011-08-19 18:55:51 +00001007 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1008 }
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001009 bool isMemThumbRIs1() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +00001010 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001011 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001012 return false;
1013 // Immediate offset in range [0, 31].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001014 if (!Memory.OffsetImm) return true;
1015 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001016 return Val >= 0 && Val <= 31;
1017 }
Jim Grosbachecd85892011-08-19 18:13:48 +00001018 bool isMemThumbSPI() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001019 if (!isMemory() || Memory.OffsetRegNum != 0 ||
1020 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbachecd85892011-08-19 18:13:48 +00001021 return false;
1022 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001023 if (!Memory.OffsetImm) return true;
1024 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +00001025 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001026 }
Jim Grosbacha77295d2011-09-08 22:07:06 +00001027 bool isMemImm8s4Offset() const {
Jim Grosbach2f196742011-12-19 23:06:24 +00001028 // If we have an immediate that's not a constant, treat it as a label
1029 // reference needing a fixup. If it is a constant, it's something else
1030 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001031 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +00001032 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +00001033 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha77295d2011-09-08 22:07:06 +00001034 return false;
1035 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001036 if (!Memory.OffsetImm) return true;
1037 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liufd652df2012-08-02 08:29:50 +00001038 // Special case, #-0 is INT32_MIN.
1039 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbacha77295d2011-09-08 22:07:06 +00001040 }
Jim Grosbachb6aed502011-09-09 18:37:27 +00001041 bool isMemImm0_1020s4Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001042 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachb6aed502011-09-09 18:37:27 +00001043 return false;
1044 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001045 if (!Memory.OffsetImm) return true;
1046 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachb6aed502011-09-09 18:37:27 +00001047 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1048 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001049 bool isMemImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001050 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001051 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001052 // Base reg of PC isn't allowed for these encodings.
1053 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001054 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001055 if (!Memory.OffsetImm) return true;
1056 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson4d2a0012011-09-23 22:25:02 +00001057 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001058 }
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001059 bool isMemPosImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001060 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001061 return false;
1062 // Immediate offset in range [0, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001063 if (!Memory.OffsetImm) return true;
1064 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001065 return Val >= 0 && Val < 256;
1066 }
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001067 bool isMemNegImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001068 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001069 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001070 // Base reg of PC isn't allowed for these encodings.
1071 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001072 // Immediate offset in range [-255, -1].
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001073 if (!Memory.OffsetImm) return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +00001074 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001075 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001076 }
1077 bool isMemUImm12Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001078 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001079 return false;
1080 // Immediate offset in range [0, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001081 if (!Memory.OffsetImm) return true;
1082 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001083 return (Val >= 0 && Val < 4096);
1084 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001085 bool isMemImm12Offset() const {
Jim Grosbach09176e12011-08-08 20:59:31 +00001086 // If we have an immediate that's not a constant, treat it as a label
1087 // reference needing a fixup. If it is a constant, it's something else
1088 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001089 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach09176e12011-08-08 20:59:31 +00001090 return true;
1091
Jim Grosbach57dcb852011-10-11 17:29:55 +00001092 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001093 return false;
1094 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001095 if (!Memory.OffsetImm) return true;
1096 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +00001097 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001098 }
1099 bool isPostIdxImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001100 if (!isImm()) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001101 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1102 if (!CE) return false;
1103 int64_t Val = CE->getValue();
Owen Anderson63553c72011-08-29 17:17:09 +00001104 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001105 }
Jim Grosbach2bd01182011-10-11 21:55:36 +00001106 bool isPostIdxImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001107 if (!isImm()) return false;
Jim Grosbach2bd01182011-10-11 21:55:36 +00001108 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1109 if (!CE) return false;
1110 int64_t Val = CE->getValue();
1111 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1112 (Val == INT32_MIN);
1113 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001114
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001115 bool isMSRMask() const { return Kind == k_MSRMask; }
1116 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001117
Jim Grosbach0e387b22011-10-17 22:26:03 +00001118 // NEON operands.
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001119 bool isSingleSpacedVectorList() const {
1120 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1121 }
1122 bool isDoubleSpacedVectorList() const {
1123 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1124 }
Jim Grosbach862019c2011-10-18 23:02:30 +00001125 bool isVecListOneD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001126 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach862019c2011-10-18 23:02:30 +00001127 return VectorList.Count == 1;
1128 }
1129
Jim Grosbach28f08c92012-03-05 19:33:30 +00001130 bool isVecListDPair() const {
1131 if (!isSingleSpacedVectorList()) return false;
1132 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1133 .contains(VectorList.RegNum));
1134 }
1135
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001136 bool isVecListThreeD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001137 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001138 return VectorList.Count == 3;
1139 }
1140
Jim Grosbachb6310312011-10-21 20:35:01 +00001141 bool isVecListFourD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001142 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachb6310312011-10-21 20:35:01 +00001143 return VectorList.Count == 4;
1144 }
1145
Jim Grosbachc3384c92012-03-05 21:43:40 +00001146 bool isVecListDPairSpaced() const {
Kevin Enderby9f2e1602012-03-20 17:41:51 +00001147 if (isSingleSpacedVectorList()) return false;
Jim Grosbachc3384c92012-03-05 21:43:40 +00001148 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1149 .contains(VectorList.RegNum));
1150 }
1151
Jim Grosbachc387fc62012-01-23 23:20:46 +00001152 bool isVecListThreeQ() const {
1153 if (!isDoubleSpacedVectorList()) return false;
1154 return VectorList.Count == 3;
1155 }
1156
Jim Grosbach7945ead2012-01-24 00:43:12 +00001157 bool isVecListFourQ() const {
1158 if (!isDoubleSpacedVectorList()) return false;
1159 return VectorList.Count == 4;
1160 }
1161
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001162 bool isSingleSpacedVectorAllLanes() const {
1163 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1164 }
1165 bool isDoubleSpacedVectorAllLanes() const {
1166 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1167 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00001168 bool isVecListOneDAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001169 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach98b05a52011-11-30 01:09:44 +00001170 return VectorList.Count == 1;
1171 }
1172
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001173 bool isVecListDPairAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001174 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001175 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1176 .contains(VectorList.RegNum));
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001177 }
1178
Jim Grosbach4d0983a2012-03-06 23:10:38 +00001179 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001180 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach13af2222011-11-30 18:21:25 +00001181 return VectorList.Count == 2;
1182 }
1183
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001184 bool isVecListThreeDAllLanes() const {
1185 if (!isSingleSpacedVectorAllLanes()) return false;
1186 return VectorList.Count == 3;
1187 }
1188
1189 bool isVecListThreeQAllLanes() const {
1190 if (!isDoubleSpacedVectorAllLanes()) return false;
1191 return VectorList.Count == 3;
1192 }
1193
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001194 bool isVecListFourDAllLanes() const {
1195 if (!isSingleSpacedVectorAllLanes()) return false;
1196 return VectorList.Count == 4;
1197 }
1198
1199 bool isVecListFourQAllLanes() const {
1200 if (!isDoubleSpacedVectorAllLanes()) return false;
1201 return VectorList.Count == 4;
1202 }
1203
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001204 bool isSingleSpacedVectorIndexed() const {
1205 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1206 }
1207 bool isDoubleSpacedVectorIndexed() const {
1208 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1209 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00001210 bool isVecListOneDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001211 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach7636bf62011-12-02 00:35:16 +00001212 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1213 }
1214
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001215 bool isVecListOneDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001216 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001217 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1218 }
1219
1220 bool isVecListOneDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001221 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001222 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1223 }
1224
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001225 bool isVecListTwoDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001226 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001227 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1228 }
1229
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001230 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001231 if (!isSingleSpacedVectorIndexed()) return false;
1232 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1233 }
1234
1235 bool isVecListTwoQWordIndexed() const {
1236 if (!isDoubleSpacedVectorIndexed()) return false;
1237 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1238 }
1239
1240 bool isVecListTwoQHWordIndexed() const {
1241 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001242 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1243 }
1244
1245 bool isVecListTwoDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001246 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001247 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1248 }
1249
Jim Grosbach3a678af2012-01-23 21:53:26 +00001250 bool isVecListThreeDByteIndexed() const {
1251 if (!isSingleSpacedVectorIndexed()) return false;
1252 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1253 }
1254
1255 bool isVecListThreeDHWordIndexed() const {
1256 if (!isSingleSpacedVectorIndexed()) return false;
1257 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1258 }
1259
1260 bool isVecListThreeQWordIndexed() const {
1261 if (!isDoubleSpacedVectorIndexed()) return false;
1262 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1263 }
1264
1265 bool isVecListThreeQHWordIndexed() const {
1266 if (!isDoubleSpacedVectorIndexed()) return false;
1267 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1268 }
1269
1270 bool isVecListThreeDWordIndexed() const {
1271 if (!isSingleSpacedVectorIndexed()) return false;
1272 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1273 }
1274
Jim Grosbache983a132012-01-24 18:37:25 +00001275 bool isVecListFourDByteIndexed() const {
1276 if (!isSingleSpacedVectorIndexed()) return false;
1277 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1278 }
1279
1280 bool isVecListFourDHWordIndexed() const {
1281 if (!isSingleSpacedVectorIndexed()) return false;
1282 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1283 }
1284
1285 bool isVecListFourQWordIndexed() const {
1286 if (!isDoubleSpacedVectorIndexed()) return false;
1287 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1288 }
1289
1290 bool isVecListFourQHWordIndexed() const {
1291 if (!isDoubleSpacedVectorIndexed()) return false;
1292 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1293 }
1294
1295 bool isVecListFourDWordIndexed() const {
1296 if (!isSingleSpacedVectorIndexed()) return false;
1297 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1298 }
1299
Jim Grosbach460a9052011-10-07 23:56:00 +00001300 bool isVectorIndex8() const {
1301 if (Kind != k_VectorIndex) return false;
1302 return VectorIndex.Val < 8;
1303 }
1304 bool isVectorIndex16() const {
1305 if (Kind != k_VectorIndex) return false;
1306 return VectorIndex.Val < 4;
1307 }
1308 bool isVectorIndex32() const {
1309 if (Kind != k_VectorIndex) return false;
1310 return VectorIndex.Val < 2;
1311 }
1312
Jim Grosbach0e387b22011-10-17 22:26:03 +00001313 bool isNEONi8splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001314 if (!isImm()) return false;
Jim Grosbach0e387b22011-10-17 22:26:03 +00001315 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1316 // Must be a constant.
1317 if (!CE) return false;
1318 int64_t Value = CE->getValue();
1319 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1320 // value.
Jim Grosbach0e387b22011-10-17 22:26:03 +00001321 return Value >= 0 && Value < 256;
1322 }
Jim Grosbach460a9052011-10-07 23:56:00 +00001323
Jim Grosbachea461102011-10-17 23:09:09 +00001324 bool isNEONi16splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001325 if (!isImm()) return false;
Jim Grosbachea461102011-10-17 23:09:09 +00001326 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1327 // Must be a constant.
1328 if (!CE) return false;
1329 int64_t Value = CE->getValue();
1330 // i16 value in the range [0,255] or [0x0100, 0xff00]
1331 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1332 }
1333
Jim Grosbach6248a542011-10-18 00:22:00 +00001334 bool isNEONi32splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001335 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001336 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1337 // Must be a constant.
1338 if (!CE) return false;
1339 int64_t Value = CE->getValue();
1340 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1341 return (Value >= 0 && Value < 256) ||
1342 (Value >= 0x0100 && Value <= 0xff00) ||
1343 (Value >= 0x010000 && Value <= 0xff0000) ||
1344 (Value >= 0x01000000 && Value <= 0xff000000);
1345 }
1346
1347 bool isNEONi32vmov() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001348 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001349 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1350 // Must be a constant.
1351 if (!CE) return false;
1352 int64_t Value = CE->getValue();
1353 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1354 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1355 return (Value >= 0 && Value < 256) ||
1356 (Value >= 0x0100 && Value <= 0xff00) ||
1357 (Value >= 0x010000 && Value <= 0xff0000) ||
1358 (Value >= 0x01000000 && Value <= 0xff000000) ||
1359 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1360 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1361 }
Jim Grosbach9b087852011-12-19 23:51:07 +00001362 bool isNEONi32vmovNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001363 if (!isImm()) return false;
Jim Grosbach9b087852011-12-19 23:51:07 +00001364 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1365 // Must be a constant.
1366 if (!CE) return false;
1367 int64_t Value = ~CE->getValue();
1368 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1369 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1370 return (Value >= 0 && Value < 256) ||
1371 (Value >= 0x0100 && Value <= 0xff00) ||
1372 (Value >= 0x010000 && Value <= 0xff0000) ||
1373 (Value >= 0x01000000 && Value <= 0xff000000) ||
1374 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1375 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1376 }
Jim Grosbach6248a542011-10-18 00:22:00 +00001377
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001378 bool isNEONi64splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001379 if (!isImm()) return false;
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001380 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1381 // Must be a constant.
1382 if (!CE) return false;
1383 uint64_t Value = CE->getValue();
1384 // i64 value with each byte being either 0 or 0xff.
1385 for (unsigned i = 0; i < 8; ++i)
1386 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1387 return true;
1388 }
1389
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001390 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +00001391 // Add as immediates when possible. Null MCExpr = 0.
1392 if (Expr == 0)
1393 Inst.addOperand(MCOperand::CreateImm(0));
1394 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001395 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1396 else
1397 Inst.addOperand(MCOperand::CreateExpr(Expr));
1398 }
1399
Daniel Dunbar8462b302010-08-11 06:36:53 +00001400 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001401 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +00001402 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +00001403 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1404 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +00001405 }
1406
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001407 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1408 assert(N == 1 && "Invalid number of operands!");
1409 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1410 }
1411
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00001412 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1413 assert(N == 1 && "Invalid number of operands!");
1414 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1415 }
1416
1417 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1418 assert(N == 1 && "Invalid number of operands!");
1419 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1420 }
1421
Jim Grosbach89df9962011-08-26 21:43:41 +00001422 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1423 assert(N == 1 && "Invalid number of operands!");
1424 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1425 }
1426
1427 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1428 assert(N == 1 && "Invalid number of operands!");
1429 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1430 }
1431
Jim Grosbachd67641b2010-12-06 18:21:12 +00001432 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1433 assert(N == 1 && "Invalid number of operands!");
1434 Inst.addOperand(MCOperand::CreateReg(getReg()));
1435 }
1436
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001437 void addRegOperands(MCInst &Inst, unsigned N) const {
1438 assert(N == 1 && "Invalid number of operands!");
1439 Inst.addOperand(MCOperand::CreateReg(getReg()));
1440 }
1441
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001442 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbache8606dc2011-07-13 17:50:29 +00001443 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001444 assert(isRegShiftedReg() &&
1445 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001446 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1447 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001448 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001449 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001450 }
1451
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001452 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson152d4a42011-07-21 23:38:37 +00001453 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001454 assert(isRegShiftedImm() &&
1455 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001456 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonb56e4112012-04-25 18:00:18 +00001457 // Shift of #32 is encoded as 0 where permitted
1458 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Anderson92a20222011-07-21 18:54:16 +00001459 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonb56e4112012-04-25 18:00:18 +00001460 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Anderson92a20222011-07-21 18:54:16 +00001461 }
1462
Jim Grosbach580f4a92011-07-25 22:20:28 +00001463 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson00828302011-03-18 22:50:18 +00001464 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach580f4a92011-07-25 22:20:28 +00001465 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1466 ShifterImm.Imm));
Owen Anderson00828302011-03-18 22:50:18 +00001467 }
1468
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001469 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +00001470 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +00001471 const SmallVectorImpl<unsigned> &RegList = getRegList();
1472 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00001473 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1474 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001475 }
1476
Bill Wendling0f630752010-11-17 04:32:08 +00001477 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1478 addRegListOperands(Inst, N);
1479 }
1480
1481 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1482 addRegListOperands(Inst, N);
1483 }
1484
Jim Grosbach7e1547e2011-07-27 20:15:40 +00001485 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1486 assert(N == 1 && "Invalid number of operands!");
1487 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1488 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1489 }
1490
Jim Grosbach293a2ee2011-07-28 21:34:26 +00001491 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1492 assert(N == 1 && "Invalid number of operands!");
1493 // Munge the lsb/width into a bitfield mask.
1494 unsigned lsb = Bitfield.LSB;
1495 unsigned width = Bitfield.Width;
1496 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1497 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1498 (32 - (lsb + width)));
1499 Inst.addOperand(MCOperand::CreateImm(Mask));
1500 }
1501
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001502 void addImmOperands(MCInst &Inst, unsigned N) const {
1503 assert(N == 1 && "Invalid number of operands!");
1504 addExpr(Inst, getImm());
1505 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001506
Jim Grosbach4050bc42011-12-22 22:19:05 +00001507 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1508 assert(N == 1 && "Invalid number of operands!");
1509 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1510 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1511 }
1512
1513 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1514 assert(N == 1 && "Invalid number of operands!");
1515 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1516 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1517 }
1518
Jim Grosbach9d390362011-10-03 23:38:36 +00001519 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1520 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach51222d12012-01-20 18:09:51 +00001521 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1522 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1523 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach9d390362011-10-03 23:38:36 +00001524 }
1525
Jim Grosbacha77295d2011-09-08 22:07:06 +00001526 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1527 assert(N == 1 && "Invalid number of operands!");
1528 // FIXME: We really want to scale the value here, but the LDRD/STRD
1529 // instruction don't encode operands that way yet.
1530 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1531 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1532 }
1533
Jim Grosbach72f39f82011-08-24 21:22:15 +00001534 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1535 assert(N == 1 && "Invalid number of operands!");
1536 // The immediate is scaled by four in the encoding and is stored
1537 // in the MCInst as such. Lop off the low two bits here.
1538 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1539 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1540 }
1541
Jim Grosbach4e53fe82012-04-05 20:57:13 +00001542 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1543 assert(N == 1 && "Invalid number of operands!");
1544 // The immediate is scaled by four in the encoding and is stored
1545 // in the MCInst as such. Lop off the low two bits here.
1546 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1547 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1548 }
1549
Jim Grosbach72f39f82011-08-24 21:22:15 +00001550 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1551 assert(N == 1 && "Invalid number of operands!");
1552 // The immediate is scaled by four in the encoding and is stored
1553 // in the MCInst as such. Lop off the low two bits here.
1554 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1555 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1556 }
1557
Jim Grosbachf4943352011-07-25 23:09:14 +00001558 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1559 assert(N == 1 && "Invalid number of operands!");
1560 // The constant encodes as the immediate-1, and we store in the instruction
1561 // the bits as encoded, so subtract off one here.
1562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1563 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1564 }
1565
Jim Grosbach4a5ffb32011-07-22 23:16:18 +00001566 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1567 assert(N == 1 && "Invalid number of operands!");
1568 // The constant encodes as the immediate-1, and we store in the instruction
1569 // the bits as encoded, so subtract off one here.
1570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1571 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1572 }
1573
Jim Grosbach70939ee2011-08-17 21:51:27 +00001574 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1575 assert(N == 1 && "Invalid number of operands!");
1576 // The constant encodes as the immediate, except for 32, which encodes as
1577 // zero.
1578 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1579 unsigned Imm = CE->getValue();
1580 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1581 }
1582
Jim Grosbachf6c05252011-07-21 17:23:04 +00001583 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1584 assert(N == 1 && "Invalid number of operands!");
1585 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1586 // the instruction as well.
1587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1588 int Val = CE->getValue();
1589 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1590 }
1591
Jim Grosbach89a63372011-10-28 22:36:30 +00001592 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1593 assert(N == 1 && "Invalid number of operands!");
1594 // The operand is actually a t2_so_imm, but we have its bitwise
1595 // negation in the assembly source, so twiddle it here.
1596 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1597 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1598 }
1599
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001600 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1601 assert(N == 1 && "Invalid number of operands!");
1602 // The operand is actually a t2_so_imm, but we have its
1603 // negation in the assembly source, so twiddle it here.
1604 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1605 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1606 }
1607
Jim Grosbach4e53fe82012-04-05 20:57:13 +00001608 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1609 assert(N == 1 && "Invalid number of operands!");
1610 // The operand is actually an imm0_4095, but we have its
1611 // negation in the assembly source, so twiddle it here.
1612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1613 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1614 }
1615
Jim Grosbache70ec842011-10-28 22:50:54 +00001616 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1617 assert(N == 1 && "Invalid number of operands!");
1618 // The operand is actually a so_imm, but we have its bitwise
1619 // negation in the assembly source, so twiddle it here.
1620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1621 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1622 }
1623
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001624 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1625 assert(N == 1 && "Invalid number of operands!");
1626 // The operand is actually a so_imm, but we have its
1627 // negation in the assembly source, so twiddle it here.
1628 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1629 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1630 }
1631
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001632 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1633 assert(N == 1 && "Invalid number of operands!");
1634 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1635 }
1636
Jim Grosbach7ce05792011-08-03 23:50:40 +00001637 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1638 assert(N == 1 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001639 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00001640 }
1641
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001642 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1643 assert(N == 1 && "Invalid number of operands!");
1644 int32_t Imm = Memory.OffsetImm->getValue();
1645 // FIXME: Handle #-0
1646 if (Imm == INT32_MIN) Imm = 0;
1647 Inst.addOperand(MCOperand::CreateImm(Imm));
1648 }
1649
Jiangning Liu1fb27ec2012-08-02 08:13:13 +00001650 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 assert(isImm() && "Not an immediate!");
1653
1654 // If we have an immediate that's not a constant, treat it as a label
1655 // reference needing a fixup.
1656 if (!isa<MCConstantExpr>(getImm())) {
1657 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1658 return;
1659 }
1660
1661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1662 int Val = CE->getValue();
1663 Inst.addOperand(MCOperand::CreateImm(Val));
1664 }
1665
Jim Grosbach57dcb852011-10-11 17:29:55 +00001666 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1667 assert(N == 2 && "Invalid number of operands!");
1668 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1669 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1670 }
1671
Jim Grosbach7ce05792011-08-03 23:50:40 +00001672 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1673 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001674 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1675 if (!Memory.OffsetRegNum) {
Jim Grosbach7ce05792011-08-03 23:50:40 +00001676 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1677 // Special case for #-0
1678 if (Val == INT32_MIN) Val = 0;
1679 if (Val < 0) Val = -Val;
1680 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1681 } else {
1682 // For register offset, we encode the shift type and negation flag
1683 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001684 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1685 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001686 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001687 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1688 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001689 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001690 }
1691
Jim Grosbach039c2e12011-08-04 23:01:30 +00001692 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1693 assert(N == 2 && "Invalid number of operands!");
1694 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1695 assert(CE && "non-constant AM2OffsetImm operand!");
1696 int32_t Val = CE->getValue();
1697 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1698 // Special case for #-0
1699 if (Val == INT32_MIN) Val = 0;
1700 if (Val < 0) Val = -Val;
1701 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1702 Inst.addOperand(MCOperand::CreateReg(0));
1703 Inst.addOperand(MCOperand::CreateImm(Val));
1704 }
1705
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001706 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1707 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001708 // If we have an immediate that's not a constant, treat it as a label
1709 // reference needing a fixup. If it is a constant, it's something else
1710 // and we reject it.
1711 if (isImm()) {
1712 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1713 Inst.addOperand(MCOperand::CreateReg(0));
1714 Inst.addOperand(MCOperand::CreateImm(0));
1715 return;
1716 }
1717
Jim Grosbache53c87b2011-10-11 15:59:20 +00001718 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1719 if (!Memory.OffsetRegNum) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001720 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1721 // Special case for #-0
1722 if (Val == INT32_MIN) Val = 0;
1723 if (Val < 0) Val = -Val;
1724 Val = ARM_AM::getAM3Opc(AddSub, Val);
1725 } else {
1726 // For register offset, we encode the shift type and negation flag
1727 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001728 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001729 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001730 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1731 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001732 Inst.addOperand(MCOperand::CreateImm(Val));
1733 }
1734
1735 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1736 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001737 if (Kind == k_PostIndexRegister) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001738 int32_t Val =
1739 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1740 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1741 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach251bf252011-08-10 21:56:18 +00001742 return;
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001743 }
1744
1745 // Constant offset.
1746 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1747 int32_t Val = CE->getValue();
1748 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1749 // Special case for #-0
1750 if (Val == INT32_MIN) Val = 0;
1751 if (Val < 0) Val = -Val;
Jim Grosbach251bf252011-08-10 21:56:18 +00001752 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001753 Inst.addOperand(MCOperand::CreateReg(0));
1754 Inst.addOperand(MCOperand::CreateImm(Val));
1755 }
1756
Jim Grosbach7ce05792011-08-03 23:50:40 +00001757 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1758 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach681460f2011-11-01 01:24:45 +00001759 // If we have an immediate that's not a constant, treat it as a label
1760 // reference needing a fixup. If it is a constant, it's something else
1761 // and we reject it.
1762 if (isImm()) {
1763 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1764 Inst.addOperand(MCOperand::CreateImm(0));
1765 return;
1766 }
1767
Jim Grosbach7ce05792011-08-03 23:50:40 +00001768 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001769 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001770 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1771 // Special case for #-0
1772 if (Val == INT32_MIN) Val = 0;
1773 if (Val < 0) Val = -Val;
1774 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001775 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001776 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001777 }
1778
Jim Grosbacha77295d2011-09-08 22:07:06 +00001779 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1780 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001781 // If we have an immediate that's not a constant, treat it as a label
1782 // reference needing a fixup. If it is a constant, it's something else
1783 // and we reject it.
1784 if (isImm()) {
1785 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1786 Inst.addOperand(MCOperand::CreateImm(0));
1787 return;
1788 }
1789
Jim Grosbache53c87b2011-10-11 15:59:20 +00001790 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1791 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha77295d2011-09-08 22:07:06 +00001792 Inst.addOperand(MCOperand::CreateImm(Val));
1793 }
1794
Jim Grosbachb6aed502011-09-09 18:37:27 +00001795 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1796 assert(N == 2 && "Invalid number of operands!");
1797 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001798 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1799 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachb6aed502011-09-09 18:37:27 +00001800 Inst.addOperand(MCOperand::CreateImm(Val));
1801 }
1802
Jim Grosbach7ce05792011-08-03 23:50:40 +00001803 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1804 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001805 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1806 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001807 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner14b93852010-10-29 00:27:31 +00001808 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001809
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001810 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1811 addMemImm8OffsetOperands(Inst, N);
1812 }
1813
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001814 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001815 addMemImm8OffsetOperands(Inst, N);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001816 }
1817
1818 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1819 assert(N == 2 && "Invalid number of operands!");
1820 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001821 if (isImm()) {
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001822 addExpr(Inst, getImm());
1823 Inst.addOperand(MCOperand::CreateImm(0));
1824 return;
1825 }
1826
1827 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001828 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1829 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001830 Inst.addOperand(MCOperand::CreateImm(Val));
1831 }
1832
Jim Grosbach7ce05792011-08-03 23:50:40 +00001833 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1834 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach09176e12011-08-08 20:59:31 +00001835 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001836 if (isImm()) {
Jim Grosbach09176e12011-08-08 20:59:31 +00001837 addExpr(Inst, getImm());
1838 Inst.addOperand(MCOperand::CreateImm(0));
1839 return;
1840 }
1841
1842 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001843 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1844 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001845 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendlingf4caf692010-12-14 03:36:38 +00001846 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001847
Jim Grosbach7f739be2011-09-19 22:21:13 +00001848 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1849 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001850 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1851 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001852 }
1853
1854 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1855 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001856 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1857 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001858 }
1859
Jim Grosbach7ce05792011-08-03 23:50:40 +00001860 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1861 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001862 unsigned Val =
1863 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1864 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001865 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1866 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001867 Inst.addOperand(MCOperand::CreateImm(Val));
1868 }
1869
Jim Grosbachab899c12011-09-07 23:10:15 +00001870 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1871 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001872 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1873 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1874 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbachab899c12011-09-07 23:10:15 +00001875 }
1876
Jim Grosbach7ce05792011-08-03 23:50:40 +00001877 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1878 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001879 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1880 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001881 }
1882
Jim Grosbach60f91a32011-08-19 17:55:24 +00001883 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1884 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001885 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1886 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +00001887 Inst.addOperand(MCOperand::CreateImm(Val));
1888 }
1889
Jim Grosbach38466302011-08-19 18:55:51 +00001890 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1891 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001892 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1893 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach38466302011-08-19 18:55:51 +00001894 Inst.addOperand(MCOperand::CreateImm(Val));
1895 }
1896
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001897 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1898 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001899 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1900 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001901 Inst.addOperand(MCOperand::CreateImm(Val));
1902 }
1903
Jim Grosbachecd85892011-08-19 18:13:48 +00001904 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1905 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001906 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1907 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachecd85892011-08-19 18:13:48 +00001908 Inst.addOperand(MCOperand::CreateImm(Val));
1909 }
1910
Jim Grosbach7ce05792011-08-03 23:50:40 +00001911 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1912 assert(N == 1 && "Invalid number of operands!");
1913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1914 assert(CE && "non-constant post-idx-imm8 operand!");
1915 int Imm = CE->getValue();
1916 bool isAdd = Imm >= 0;
Owen Anderson63553c72011-08-29 17:17:09 +00001917 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001918 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1919 Inst.addOperand(MCOperand::CreateImm(Imm));
1920 }
1921
Jim Grosbach2bd01182011-10-11 21:55:36 +00001922 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1923 assert(N == 1 && "Invalid number of operands!");
1924 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1925 assert(CE && "non-constant post-idx-imm8s4 operand!");
1926 int Imm = CE->getValue();
1927 bool isAdd = Imm >= 0;
1928 if (Imm == INT32_MIN) Imm = 0;
1929 // Immediate is scaled by 4.
1930 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1931 Inst.addOperand(MCOperand::CreateImm(Imm));
1932 }
1933
Jim Grosbach7ce05792011-08-03 23:50:40 +00001934 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1935 assert(N == 2 && "Invalid number of operands!");
1936 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00001937 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1938 }
1939
1940 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1941 assert(N == 2 && "Invalid number of operands!");
1942 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1943 // The sign, shift type, and shift amount are encoded in a single operand
1944 // using the AM2 encoding helpers.
1945 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1946 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1947 PostIdxReg.ShiftTy);
1948 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001949 }
1950
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001951 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1952 assert(N == 1 && "Invalid number of operands!");
1953 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1954 }
1955
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001956 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1957 assert(N == 1 && "Invalid number of operands!");
1958 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1959 }
1960
Jim Grosbach6029b6d2011-11-29 23:51:09 +00001961 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach862019c2011-10-18 23:02:30 +00001962 assert(N == 1 && "Invalid number of operands!");
1963 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1964 }
1965
Jim Grosbach7636bf62011-12-02 00:35:16 +00001966 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1967 assert(N == 2 && "Invalid number of operands!");
1968 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1969 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1970 }
1971
Jim Grosbach460a9052011-10-07 23:56:00 +00001972 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1973 assert(N == 1 && "Invalid number of operands!");
1974 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1975 }
1976
1977 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1978 assert(N == 1 && "Invalid number of operands!");
1979 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1980 }
1981
1982 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1983 assert(N == 1 && "Invalid number of operands!");
1984 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1985 }
1986
Jim Grosbach0e387b22011-10-17 22:26:03 +00001987 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1988 assert(N == 1 && "Invalid number of operands!");
1989 // The immediate encodes the type of constant as well as the value.
1990 // Mask in that this is an i8 splat.
1991 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1992 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1993 }
1994
Jim Grosbachea461102011-10-17 23:09:09 +00001995 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1996 assert(N == 1 && "Invalid number of operands!");
1997 // The immediate encodes the type of constant as well as the value.
1998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1999 unsigned Value = CE->getValue();
2000 if (Value >= 256)
2001 Value = (Value >> 8) | 0xa00;
2002 else
2003 Value |= 0x800;
2004 Inst.addOperand(MCOperand::CreateImm(Value));
2005 }
2006
Jim Grosbach6248a542011-10-18 00:22:00 +00002007 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2008 assert(N == 1 && "Invalid number of operands!");
2009 // The immediate encodes the type of constant as well as the value.
2010 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2011 unsigned Value = CE->getValue();
2012 if (Value >= 256 && Value <= 0xff00)
2013 Value = (Value >> 8) | 0x200;
2014 else if (Value > 0xffff && Value <= 0xff0000)
2015 Value = (Value >> 16) | 0x400;
2016 else if (Value > 0xffffff)
2017 Value = (Value >> 24) | 0x600;
2018 Inst.addOperand(MCOperand::CreateImm(Value));
2019 }
2020
2021 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2022 assert(N == 1 && "Invalid number of operands!");
2023 // The immediate encodes the type of constant as well as the value.
2024 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2025 unsigned Value = CE->getValue();
2026 if (Value >= 256 && Value <= 0xffff)
2027 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2028 else if (Value > 0xffff && Value <= 0xffffff)
2029 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2030 else if (Value > 0xffffff)
2031 Value = (Value >> 24) | 0x600;
2032 Inst.addOperand(MCOperand::CreateImm(Value));
2033 }
2034
Jim Grosbach9b087852011-12-19 23:51:07 +00002035 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2036 assert(N == 1 && "Invalid number of operands!");
2037 // The immediate encodes the type of constant as well as the value.
2038 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2039 unsigned Value = ~CE->getValue();
2040 if (Value >= 256 && Value <= 0xffff)
2041 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2042 else if (Value > 0xffff && Value <= 0xffffff)
2043 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2044 else if (Value > 0xffffff)
2045 Value = (Value >> 24) | 0x600;
2046 Inst.addOperand(MCOperand::CreateImm(Value));
2047 }
2048
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00002049 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2050 assert(N == 1 && "Invalid number of operands!");
2051 // The immediate encodes the type of constant as well as the value.
2052 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2053 uint64_t Value = CE->getValue();
2054 unsigned Imm = 0;
2055 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2056 Imm |= (Value & 1) << i;
2057 }
2058 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2059 }
2060
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002061 virtual void print(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +00002062
Jim Grosbach89df9962011-08-26 21:43:41 +00002063 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002064 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach89df9962011-08-26 21:43:41 +00002065 Op->ITMask.Mask = Mask;
2066 Op->StartLoc = S;
2067 Op->EndLoc = S;
2068 return Op;
2069 }
2070
Chris Lattner3a697562010-10-28 17:20:03 +00002071 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002072 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002073 Op->CC.Val = CC;
2074 Op->StartLoc = S;
2075 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002076 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002077 }
2078
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002079 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002080 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002081 Op->Cop.Val = CopVal;
2082 Op->StartLoc = S;
2083 Op->EndLoc = S;
2084 return Op;
2085 }
2086
2087 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002088 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002089 Op->Cop.Val = CopVal;
2090 Op->StartLoc = S;
2091 Op->EndLoc = S;
2092 return Op;
2093 }
2094
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002095 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2096 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2097 Op->Cop.Val = Val;
2098 Op->StartLoc = S;
2099 Op->EndLoc = E;
2100 return Op;
2101 }
2102
Jim Grosbachd67641b2010-12-06 18:21:12 +00002103 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002104 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbachd67641b2010-12-06 18:21:12 +00002105 Op->Reg.RegNum = RegNum;
2106 Op->StartLoc = S;
2107 Op->EndLoc = S;
2108 return Op;
2109 }
2110
Chris Lattner3a697562010-10-28 17:20:03 +00002111 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002112 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan76264762010-04-02 22:27:05 +00002113 Op->Tok.Data = Str.data();
2114 Op->Tok.Length = Str.size();
2115 Op->StartLoc = S;
2116 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002117 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002118 }
2119
Bill Wendling50d0f582010-11-18 23:43:05 +00002120 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002121 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan76264762010-04-02 22:27:05 +00002122 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +00002123 Op->StartLoc = S;
2124 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002125 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002126 }
2127
Jim Grosbache8606dc2011-07-13 17:50:29 +00002128 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2129 unsigned SrcReg,
2130 unsigned ShiftReg,
2131 unsigned ShiftImm,
2132 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002133 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002134 Op->RegShiftedReg.ShiftTy = ShTy;
2135 Op->RegShiftedReg.SrcReg = SrcReg;
2136 Op->RegShiftedReg.ShiftReg = ShiftReg;
2137 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002138 Op->StartLoc = S;
2139 Op->EndLoc = E;
2140 return Op;
2141 }
2142
Owen Anderson92a20222011-07-21 18:54:16 +00002143 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2144 unsigned SrcReg,
2145 unsigned ShiftImm,
2146 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002147 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002148 Op->RegShiftedImm.ShiftTy = ShTy;
2149 Op->RegShiftedImm.SrcReg = SrcReg;
2150 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Anderson92a20222011-07-21 18:54:16 +00002151 Op->StartLoc = S;
2152 Op->EndLoc = E;
2153 return Op;
2154 }
2155
Jim Grosbach580f4a92011-07-25 22:20:28 +00002156 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002157 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002158 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach580f4a92011-07-25 22:20:28 +00002159 Op->ShifterImm.isASR = isASR;
2160 Op->ShifterImm.Imm = Imm;
Owen Anderson00828302011-03-18 22:50:18 +00002161 Op->StartLoc = S;
2162 Op->EndLoc = E;
2163 return Op;
2164 }
2165
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002166 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002167 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002168 Op->RotImm.Imm = Imm;
2169 Op->StartLoc = S;
2170 Op->EndLoc = E;
2171 return Op;
2172 }
2173
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002174 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2175 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002176 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002177 Op->Bitfield.LSB = LSB;
2178 Op->Bitfield.Width = Width;
2179 Op->StartLoc = S;
2180 Op->EndLoc = E;
2181 return Op;
2182 }
2183
Bill Wendling7729e062010-11-09 22:44:22 +00002184 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +00002185 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002186 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002187 KindTy Kind = k_RegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002188
Jim Grosbachd300b942011-09-13 22:56:44 +00002189 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002190 Kind = k_DPRRegisterList;
Jim Grosbachd300b942011-09-13 22:56:44 +00002191 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng275944a2011-07-25 21:32:49 +00002192 contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002193 Kind = k_SPRRegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002194
2195 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +00002196 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002197 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +00002198 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +00002199 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002200 Op->StartLoc = StartLoc;
2201 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +00002202 return Op;
2203 }
2204
Jim Grosbach862019c2011-10-18 23:02:30 +00002205 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002206 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbach862019c2011-10-18 23:02:30 +00002207 ARMOperand *Op = new ARMOperand(k_VectorList);
2208 Op->VectorList.RegNum = RegNum;
2209 Op->VectorList.Count = Count;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002210 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +00002211 Op->StartLoc = S;
2212 Op->EndLoc = E;
2213 return Op;
2214 }
2215
Jim Grosbach98b05a52011-11-30 01:09:44 +00002216 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002217 bool isDoubleSpaced,
Jim Grosbach98b05a52011-11-30 01:09:44 +00002218 SMLoc S, SMLoc E) {
2219 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2220 Op->VectorList.RegNum = RegNum;
2221 Op->VectorList.Count = Count;
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002222 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002223 Op->StartLoc = S;
2224 Op->EndLoc = E;
2225 return Op;
2226 }
2227
Jim Grosbach7636bf62011-12-02 00:35:16 +00002228 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002229 unsigned Index,
2230 bool isDoubleSpaced,
2231 SMLoc S, SMLoc E) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00002232 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2233 Op->VectorList.RegNum = RegNum;
2234 Op->VectorList.Count = Count;
2235 Op->VectorList.LaneIndex = Index;
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002236 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002237 Op->StartLoc = S;
2238 Op->EndLoc = E;
2239 return Op;
2240 }
2241
Jim Grosbach460a9052011-10-07 23:56:00 +00002242 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2243 MCContext &Ctx) {
2244 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2245 Op->VectorIndex.Val = Idx;
2246 Op->StartLoc = S;
2247 Op->EndLoc = E;
2248 return Op;
2249 }
2250
Chris Lattner3a697562010-10-28 17:20:03 +00002251 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002252 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan76264762010-04-02 22:27:05 +00002253 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +00002254 Op->StartLoc = S;
2255 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002256 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +00002257 }
2258
Jim Grosbach7ce05792011-08-03 23:50:40 +00002259 static ARMOperand *CreateMem(unsigned BaseRegNum,
2260 const MCConstantExpr *OffsetImm,
2261 unsigned OffsetRegNum,
2262 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach0d6fac32011-08-05 22:03:36 +00002263 unsigned ShiftImm,
Jim Grosbach57dcb852011-10-11 17:29:55 +00002264 unsigned Alignment,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002265 bool isNegative,
Chris Lattner3a697562010-10-28 17:20:03 +00002266 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002267 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbache53c87b2011-10-11 15:59:20 +00002268 Op->Memory.BaseRegNum = BaseRegNum;
2269 Op->Memory.OffsetImm = OffsetImm;
2270 Op->Memory.OffsetRegNum = OffsetRegNum;
2271 Op->Memory.ShiftType = ShiftType;
2272 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbach57dcb852011-10-11 17:29:55 +00002273 Op->Memory.Alignment = Alignment;
Jim Grosbache53c87b2011-10-11 15:59:20 +00002274 Op->Memory.isNegative = isNegative;
Jim Grosbach7ce05792011-08-03 23:50:40 +00002275 Op->StartLoc = S;
2276 Op->EndLoc = E;
2277 return Op;
2278 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002279
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002280 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2281 ARM_AM::ShiftOpc ShiftTy,
2282 unsigned ShiftImm,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002283 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002284 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbach7ce05792011-08-03 23:50:40 +00002285 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002286 Op->PostIdxReg.isAdd = isAdd;
2287 Op->PostIdxReg.ShiftTy = ShiftTy;
2288 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan76264762010-04-02 22:27:05 +00002289 Op->StartLoc = S;
2290 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002291 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002292 }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002293
2294 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002295 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002296 Op->MBOpt.Val = Opt;
2297 Op->StartLoc = S;
2298 Op->EndLoc = S;
2299 return Op;
2300 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002301
2302 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002303 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002304 Op->IFlags.Val = IFlags;
2305 Op->StartLoc = S;
2306 Op->EndLoc = S;
2307 return Op;
2308 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002309
2310 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002311 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002312 Op->MMask.Val = MMask;
2313 Op->StartLoc = S;
2314 Op->EndLoc = S;
2315 return Op;
2316 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002317};
2318
2319} // end anonymous namespace.
2320
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002321void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002322 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002323 case k_CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +00002324 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002325 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002326 case k_CCOut:
Jim Grosbachd67641b2010-12-06 18:21:12 +00002327 OS << "<ccout " << getReg() << ">";
2328 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002329 case k_ITCondMask: {
Craig Topper032f4412012-05-24 04:11:15 +00002330 static const char *const MaskStr[] = {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002331 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2332 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2333 };
Jim Grosbach89df9962011-08-26 21:43:41 +00002334 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2335 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2336 break;
2337 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002338 case k_CoprocNum:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002339 OS << "<coprocessor number: " << getCoproc() << ">";
2340 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002341 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002342 OS << "<coprocessor register: " << getCoproc() << ">";
2343 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002344 case k_CoprocOption:
2345 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2346 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002347 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002348 OS << "<mask: " << getMSRMask() << ">";
2349 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002350 case k_Immediate:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002351 getImm()->print(OS);
2352 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002353 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002354 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2355 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002356 case k_Memory:
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002357 OS << "<memory "
Jim Grosbache53c87b2011-10-11 15:59:20 +00002358 << " base:" << Memory.BaseRegNum;
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002359 OS << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002360 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002361 case k_PostIndexRegister:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002362 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2363 << PostIdxReg.RegNum;
2364 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2365 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2366 << PostIdxReg.ShiftImm;
2367 OS << ">";
Jim Grosbach7ce05792011-08-03 23:50:40 +00002368 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002369 case k_ProcIFlags: {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002370 OS << "<ARM_PROC::";
2371 unsigned IFlags = getProcIFlags();
2372 for (int i=2; i >= 0; --i)
2373 if (IFlags & (1 << i))
2374 OS << ARM_PROC::IFlagsToString(1 << i);
2375 OS << ">";
2376 break;
2377 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002378 case k_Register:
Bill Wendling50d0f582010-11-18 23:43:05 +00002379 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002380 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002381 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +00002382 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2383 << " #" << ShifterImm.Imm << ">";
Jim Grosbache8606dc2011-07-13 17:50:29 +00002384 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002385 case k_ShiftedRegister:
Owen Anderson92a20222011-07-21 18:54:16 +00002386 OS << "<so_reg_reg "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002387 << RegShiftedReg.SrcReg << " "
2388 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2389 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson00828302011-03-18 22:50:18 +00002390 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002391 case k_ShiftedImmediate:
Owen Anderson92a20222011-07-21 18:54:16 +00002392 OS << "<so_reg_imm "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002393 << RegShiftedImm.SrcReg << " "
2394 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2395 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Anderson92a20222011-07-21 18:54:16 +00002396 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002397 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002398 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2399 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002400 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002401 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2402 << ", width: " << Bitfield.Width << ">";
2403 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002404 case k_RegisterList:
2405 case k_DPRRegisterList:
2406 case k_SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +00002407 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002408
Bill Wendling5fa22a12010-11-09 23:28:44 +00002409 const SmallVectorImpl<unsigned> &RegList = getRegList();
2410 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002411 I = RegList.begin(), E = RegList.end(); I != E; ) {
2412 OS << *I;
2413 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002414 }
2415
2416 OS << ">";
2417 break;
2418 }
Jim Grosbach862019c2011-10-18 23:02:30 +00002419 case k_VectorList:
2420 OS << "<vector_list " << VectorList.Count << " * "
2421 << VectorList.RegNum << ">";
2422 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002423 case k_VectorListAllLanes:
2424 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2425 << VectorList.RegNum << ">";
2426 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002427 case k_VectorListIndexed:
2428 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2429 << VectorList.Count << " * " << VectorList.RegNum << ">";
2430 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002431 case k_Token:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002432 OS << "'" << getToken() << "'";
2433 break;
Jim Grosbach460a9052011-10-07 23:56:00 +00002434 case k_VectorIndex:
2435 OS << "<vectorindex " << getVectorIndex() << ">";
2436 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002437 }
2438}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002439
2440/// @name Auto-generated Match Functions
2441/// {
2442
2443static unsigned MatchRegisterName(StringRef Name);
2444
2445/// }
2446
Bob Wilson69df7232011-02-03 21:46:10 +00002447bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2448 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbacha39cda72011-12-14 02:16:11 +00002449 StartLoc = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002450 RegNo = tryParseRegister();
Jim Grosbacha39cda72011-12-14 02:16:11 +00002451 EndLoc = Parser.getTok().getLoc();
Roman Divackybf755322011-01-27 17:14:22 +00002452
2453 return (RegNo == (unsigned)-1);
2454}
2455
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002456/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +00002457/// and if it is a register name the token is eaten and the register number is
2458/// returned. Otherwise return -1.
2459///
Jim Grosbach1355cf12011-07-26 17:10:22 +00002460int ARMAsmParser::tryParseRegister() {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002461 const AsmToken &Tok = Parser.getTok();
Jim Grosbach7ce05792011-08-03 23:50:40 +00002462 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002463
Benjamin Kramer59085362011-11-06 20:37:06 +00002464 std::string lowerCase = Tok.getString().lower();
Owen Anderson0c9f2502011-01-13 22:50:36 +00002465 unsigned RegNum = MatchRegisterName(lowerCase);
2466 if (!RegNum) {
2467 RegNum = StringSwitch<unsigned>(lowerCase)
2468 .Case("r13", ARM::SP)
2469 .Case("r14", ARM::LR)
2470 .Case("r15", ARM::PC)
2471 .Case("ip", ARM::R12)
Jim Grosbach40e28552011-12-08 19:27:38 +00002472 // Additional register name aliases for 'gas' compatibility.
2473 .Case("a1", ARM::R0)
2474 .Case("a2", ARM::R1)
2475 .Case("a3", ARM::R2)
2476 .Case("a4", ARM::R3)
2477 .Case("v1", ARM::R4)
2478 .Case("v2", ARM::R5)
2479 .Case("v3", ARM::R6)
2480 .Case("v4", ARM::R7)
2481 .Case("v5", ARM::R8)
2482 .Case("v6", ARM::R9)
2483 .Case("v7", ARM::R10)
2484 .Case("v8", ARM::R11)
2485 .Case("sb", ARM::R9)
2486 .Case("sl", ARM::R10)
2487 .Case("fp", ARM::R11)
Owen Anderson0c9f2502011-01-13 22:50:36 +00002488 .Default(0);
2489 }
Jim Grosbacha39cda72011-12-14 02:16:11 +00002490 if (!RegNum) {
Jim Grosbachaee718b2011-12-20 23:11:00 +00002491 // Check for aliases registered via .req. Canonicalize to lower case.
2492 // That's more consistent since register names are case insensitive, and
2493 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2494 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbacha39cda72011-12-14 02:16:11 +00002495 // If no match, return failure.
2496 if (Entry == RegisterReqs.end())
2497 return -1;
2498 Parser.Lex(); // Eat identifier token.
2499 return Entry->getValue();
2500 }
Bob Wilson69df7232011-02-03 21:46:10 +00002501
Chris Lattnere5658fa2010-10-30 04:09:10 +00002502 Parser.Lex(); // Eat identifier token.
Jim Grosbach460a9052011-10-07 23:56:00 +00002503
Chris Lattnere5658fa2010-10-30 04:09:10 +00002504 return RegNum;
2505}
Jim Grosbachd4462a52010-11-01 16:44:21 +00002506
Jim Grosbach19906722011-07-13 18:49:30 +00002507// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2508// If a recoverable error occurs, return 1. If an irrecoverable error
2509// occurs, return -1. An irrecoverable error is one where tokens have been
2510// consumed in the process of trying to parse the shifter (i.e., when it is
2511// indeed a shifter operand, but malformed).
Jim Grosbach0d87ec22011-07-26 20:41:24 +00002512int ARMAsmParser::tryParseShiftRegister(
Owen Anderson00828302011-03-18 22:50:18 +00002513 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2514 SMLoc S = Parser.getTok().getLoc();
2515 const AsmToken &Tok = Parser.getTok();
2516 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2517
Benjamin Kramer59085362011-11-06 20:37:06 +00002518 std::string lowerCase = Tok.getString().lower();
Owen Anderson00828302011-03-18 22:50:18 +00002519 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbachaf4edea2011-12-07 23:40:58 +00002520 .Case("asl", ARM_AM::lsl)
Owen Anderson00828302011-03-18 22:50:18 +00002521 .Case("lsl", ARM_AM::lsl)
2522 .Case("lsr", ARM_AM::lsr)
2523 .Case("asr", ARM_AM::asr)
2524 .Case("ror", ARM_AM::ror)
2525 .Case("rrx", ARM_AM::rrx)
2526 .Default(ARM_AM::no_shift);
2527
2528 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbach19906722011-07-13 18:49:30 +00002529 return 1;
Owen Anderson00828302011-03-18 22:50:18 +00002530
Jim Grosbache8606dc2011-07-13 17:50:29 +00002531 Parser.Lex(); // Eat the operator.
Owen Anderson00828302011-03-18 22:50:18 +00002532
Jim Grosbache8606dc2011-07-13 17:50:29 +00002533 // The source register for the shift has already been added to the
2534 // operand list, so we need to pop it off and combine it into the shifted
2535 // register operand instead.
Benjamin Kramereac07962011-07-14 18:41:22 +00002536 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbache8606dc2011-07-13 17:50:29 +00002537 if (!PrevOp->isReg())
2538 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2539 int SrcReg = PrevOp->getReg();
2540 int64_t Imm = 0;
2541 int ShiftReg = 0;
2542 if (ShiftTy == ARM_AM::rrx) {
2543 // RRX Doesn't have an explicit shift amount. The encoder expects
2544 // the shift register to be the same as the source register. Seems odd,
2545 // but OK.
2546 ShiftReg = SrcReg;
2547 } else {
2548 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00002549 if (Parser.getTok().is(AsmToken::Hash) ||
2550 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbache8606dc2011-07-13 17:50:29 +00002551 Parser.Lex(); // Eat hash.
2552 SMLoc ImmLoc = Parser.getTok().getLoc();
2553 const MCExpr *ShiftExpr = 0;
Jim Grosbach19906722011-07-13 18:49:30 +00002554 if (getParser().ParseExpression(ShiftExpr)) {
2555 Error(ImmLoc, "invalid immediate shift value");
2556 return -1;
2557 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002558 // The expression must be evaluatable as an immediate.
2559 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbach19906722011-07-13 18:49:30 +00002560 if (!CE) {
2561 Error(ImmLoc, "invalid immediate shift value");
2562 return -1;
2563 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002564 // Range check the immediate.
2565 // lsl, ror: 0 <= imm <= 31
2566 // lsr, asr: 0 <= imm <= 32
2567 Imm = CE->getValue();
2568 if (Imm < 0 ||
2569 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2570 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbach19906722011-07-13 18:49:30 +00002571 Error(ImmLoc, "immediate shift value out of range");
2572 return -1;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002573 }
Jim Grosbachde626ad2011-12-22 17:37:00 +00002574 // shift by zero is a nop. Always send it through as lsl.
2575 // ('as' compatibility)
2576 if (Imm == 0)
2577 ShiftTy = ARM_AM::lsl;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002578 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach1355cf12011-07-26 17:10:22 +00002579 ShiftReg = tryParseRegister();
Jim Grosbache8606dc2011-07-13 17:50:29 +00002580 SMLoc L = Parser.getTok().getLoc();
Jim Grosbach19906722011-07-13 18:49:30 +00002581 if (ShiftReg == -1) {
2582 Error (L, "expected immediate or register in shift operand");
2583 return -1;
2584 }
2585 } else {
2586 Error (Parser.getTok().getLoc(),
Jim Grosbache8606dc2011-07-13 17:50:29 +00002587 "expected immediate or register in shift operand");
Jim Grosbach19906722011-07-13 18:49:30 +00002588 return -1;
2589 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002590 }
2591
Owen Anderson92a20222011-07-21 18:54:16 +00002592 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2593 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002594 ShiftReg, Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002595 S, Parser.getTok().getLoc()));
Owen Anderson92a20222011-07-21 18:54:16 +00002596 else
2597 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2598 S, Parser.getTok().getLoc()));
Owen Anderson00828302011-03-18 22:50:18 +00002599
Jim Grosbach19906722011-07-13 18:49:30 +00002600 return 0;
Owen Anderson00828302011-03-18 22:50:18 +00002601}
2602
2603
Bill Wendling50d0f582010-11-18 23:43:05 +00002604/// Try to parse a register name. The token must be an Identifier when called.
2605/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2606/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +00002607///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002608/// TODO this is likely to change to allow different register types and or to
2609/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +00002610bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002611tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002612 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002613 int RegNo = tryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +00002614 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +00002615 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002616
Bill Wendling50d0f582010-11-18 23:43:05 +00002617 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002618
Chris Lattnere5658fa2010-10-30 04:09:10 +00002619 const AsmToken &ExclaimTok = Parser.getTok();
2620 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +00002621 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2622 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +00002623 Parser.Lex(); // Eat exclaim token
Jim Grosbach460a9052011-10-07 23:56:00 +00002624 return false;
2625 }
2626
2627 // Also check for an index operand. This is only legal for vector registers,
2628 // but that'll get caught OK in operand matching, so we don't need to
2629 // explicitly filter everything else out here.
2630 if (Parser.getTok().is(AsmToken::LBrac)) {
2631 SMLoc SIdx = Parser.getTok().getLoc();
2632 Parser.Lex(); // Eat left bracket token.
2633
2634 const MCExpr *ImmVal;
Jim Grosbach460a9052011-10-07 23:56:00 +00002635 if (getParser().ParseExpression(ImmVal))
Jim Grosbach24dda212012-01-31 23:51:09 +00002636 return true;
Jim Grosbach460a9052011-10-07 23:56:00 +00002637 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002638 if (!MCE)
2639 return TokError("immediate value expected for vector index");
Jim Grosbach460a9052011-10-07 23:56:00 +00002640
2641 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002642 if (Parser.getTok().isNot(AsmToken::RBrac))
2643 return Error(E, "']' expected");
Jim Grosbach460a9052011-10-07 23:56:00 +00002644
2645 Parser.Lex(); // Eat right bracket token.
2646
2647 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2648 SIdx, E,
2649 getContext()));
Kevin Enderby99e6d4e2009-10-07 18:01:35 +00002650 }
2651
Bill Wendling50d0f582010-11-18 23:43:05 +00002652 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002653}
2654
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002655/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2656/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2657/// "c5", ...
2658static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002659 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2660 // but efficient.
2661 switch (Name.size()) {
David Blaikie4d6ccb52012-01-20 21:51:11 +00002662 default: return -1;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002663 case 2:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002664 if (Name[0] != CoprocOp)
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002665 return -1;
2666 switch (Name[1]) {
2667 default: return -1;
2668 case '0': return 0;
2669 case '1': return 1;
2670 case '2': return 2;
2671 case '3': return 3;
2672 case '4': return 4;
2673 case '5': return 5;
2674 case '6': return 6;
2675 case '7': return 7;
2676 case '8': return 8;
2677 case '9': return 9;
2678 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002679 case 3:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002680 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002681 return -1;
2682 switch (Name[2]) {
2683 default: return -1;
2684 case '0': return 10;
2685 case '1': return 11;
2686 case '2': return 12;
2687 case '3': return 13;
2688 case '4': return 14;
2689 case '5': return 15;
2690 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002691 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002692}
2693
Jim Grosbach89df9962011-08-26 21:43:41 +00002694/// parseITCondCode - Try to parse a condition code for an IT instruction.
2695ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2696parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2697 SMLoc S = Parser.getTok().getLoc();
2698 const AsmToken &Tok = Parser.getTok();
2699 if (!Tok.is(AsmToken::Identifier))
2700 return MatchOperand_NoMatch;
Richard Barton04a09a42012-04-27 17:34:01 +00002701 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach89df9962011-08-26 21:43:41 +00002702 .Case("eq", ARMCC::EQ)
2703 .Case("ne", ARMCC::NE)
2704 .Case("hs", ARMCC::HS)
2705 .Case("cs", ARMCC::HS)
2706 .Case("lo", ARMCC::LO)
2707 .Case("cc", ARMCC::LO)
2708 .Case("mi", ARMCC::MI)
2709 .Case("pl", ARMCC::PL)
2710 .Case("vs", ARMCC::VS)
2711 .Case("vc", ARMCC::VC)
2712 .Case("hi", ARMCC::HI)
2713 .Case("ls", ARMCC::LS)
2714 .Case("ge", ARMCC::GE)
2715 .Case("lt", ARMCC::LT)
2716 .Case("gt", ARMCC::GT)
2717 .Case("le", ARMCC::LE)
2718 .Case("al", ARMCC::AL)
2719 .Default(~0U);
2720 if (CC == ~0U)
2721 return MatchOperand_NoMatch;
2722 Parser.Lex(); // Eat the token.
2723
2724 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2725
2726 return MatchOperand_Success;
2727}
2728
Jim Grosbach43904292011-07-25 20:14:50 +00002729/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002730/// token must be an Identifier when called, and if it is a coprocessor
2731/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002732ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002733parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002734 SMLoc S = Parser.getTok().getLoc();
2735 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002736 if (Tok.isNot(AsmToken::Identifier))
2737 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002738
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002739 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002740 if (Num == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002741 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002742
2743 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002744 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002745 return MatchOperand_Success;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002746}
2747
Jim Grosbach43904292011-07-25 20:14:50 +00002748/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002749/// token must be an Identifier when called, and if it is a coprocessor
2750/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002751ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002752parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002753 SMLoc S = Parser.getTok().getLoc();
2754 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002755 if (Tok.isNot(AsmToken::Identifier))
2756 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002757
2758 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2759 if (Reg == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002760 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002761
2762 Parser.Lex(); // Eat identifier token.
2763 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002764 return MatchOperand_Success;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002765}
2766
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002767/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2768/// coproc_option : '{' imm0_255 '}'
2769ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2770parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2771 SMLoc S = Parser.getTok().getLoc();
2772
2773 // If this isn't a '{', this isn't a coprocessor immediate operand.
2774 if (Parser.getTok().isNot(AsmToken::LCurly))
2775 return MatchOperand_NoMatch;
2776 Parser.Lex(); // Eat the '{'
2777
2778 const MCExpr *Expr;
2779 SMLoc Loc = Parser.getTok().getLoc();
2780 if (getParser().ParseExpression(Expr)) {
2781 Error(Loc, "illegal expression");
2782 return MatchOperand_ParseFail;
2783 }
2784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2785 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2786 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2787 return MatchOperand_ParseFail;
2788 }
2789 int Val = CE->getValue();
2790
2791 // Check for and consume the closing '}'
2792 if (Parser.getTok().isNot(AsmToken::RCurly))
2793 return MatchOperand_ParseFail;
2794 SMLoc E = Parser.getTok().getLoc();
2795 Parser.Lex(); // Eat the '}'
2796
2797 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2798 return MatchOperand_Success;
2799}
2800
Jim Grosbachd0588e22011-09-14 18:08:35 +00002801// For register list parsing, we need to map from raw GPR register numbering
2802// to the enumeration values. The enumeration values aren't sorted by
2803// register number due to our using "sp", "lr" and "pc" as canonical names.
2804static unsigned getNextRegister(unsigned Reg) {
2805 // If this is a GPR, we need to do it manually, otherwise we can rely
2806 // on the sort ordering of the enumeration since the other reg-classes
2807 // are sane.
2808 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2809 return Reg + 1;
2810 switch(Reg) {
Craig Topperbc219812012-02-07 02:50:20 +00002811 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbachd0588e22011-09-14 18:08:35 +00002812 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2813 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2814 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2815 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2816 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2817 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2818 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2819 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2820 }
2821}
2822
Jim Grosbachce485e72011-11-11 21:27:40 +00002823// Return the low-subreg of a given Q register.
2824static unsigned getDRegFromQReg(unsigned QReg) {
2825 switch (QReg) {
2826 default: llvm_unreachable("expected a Q register!");
2827 case ARM::Q0: return ARM::D0;
2828 case ARM::Q1: return ARM::D2;
2829 case ARM::Q2: return ARM::D4;
2830 case ARM::Q3: return ARM::D6;
2831 case ARM::Q4: return ARM::D8;
2832 case ARM::Q5: return ARM::D10;
2833 case ARM::Q6: return ARM::D12;
2834 case ARM::Q7: return ARM::D14;
2835 case ARM::Q8: return ARM::D16;
Jim Grosbach25e0a872011-11-15 21:01:30 +00002836 case ARM::Q9: return ARM::D18;
Jim Grosbachce485e72011-11-11 21:27:40 +00002837 case ARM::Q10: return ARM::D20;
2838 case ARM::Q11: return ARM::D22;
2839 case ARM::Q12: return ARM::D24;
2840 case ARM::Q13: return ARM::D26;
2841 case ARM::Q14: return ARM::D28;
2842 case ARM::Q15: return ARM::D30;
2843 }
2844}
2845
Jim Grosbachd0588e22011-09-14 18:08:35 +00002846/// Parse a register list.
Bill Wendling50d0f582010-11-18 23:43:05 +00002847bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002848parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +00002849 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00002850 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +00002851 SMLoc S = Parser.getTok().getLoc();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002852 Parser.Lex(); // Eat '{' token.
2853 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002854
Jim Grosbachd0588e22011-09-14 18:08:35 +00002855 // Check the first register in the list to see what register class
2856 // this is a list of.
2857 int Reg = tryParseRegister();
2858 if (Reg == -1)
2859 return Error(RegLoc, "register expected");
2860
Jim Grosbachce485e72011-11-11 21:27:40 +00002861 // The reglist instructions have at most 16 registers, so reserve
2862 // space for that many.
2863 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2864
2865 // Allow Q regs and just interpret them as the two D sub-registers.
2866 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2867 Reg = getDRegFromQReg(Reg);
2868 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2869 ++Reg;
2870 }
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002871 const MCRegisterClass *RC;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002872 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2873 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2874 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2875 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2876 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2877 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2878 else
2879 return Error(RegLoc, "invalid register in register list");
2880
Jim Grosbachce485e72011-11-11 21:27:40 +00002881 // Store the register.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002882 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002883
Jim Grosbachd0588e22011-09-14 18:08:35 +00002884 // This starts immediately after the first register token in the list,
2885 // so we can see either a comma or a minus (range separator) as a legal
2886 // next token.
2887 while (Parser.getTok().is(AsmToken::Comma) ||
2888 Parser.getTok().is(AsmToken::Minus)) {
2889 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache43862b2011-11-15 23:19:15 +00002890 Parser.Lex(); // Eat the minus.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002891 SMLoc EndLoc = Parser.getTok().getLoc();
2892 int EndReg = tryParseRegister();
2893 if (EndReg == -1)
2894 return Error(EndLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002895 // Allow Q regs and just interpret them as the two D sub-registers.
2896 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2897 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002898 // If the register is the same as the start reg, there's nothing
2899 // more to do.
2900 if (Reg == EndReg)
2901 continue;
2902 // The register must be in the same register class as the first.
2903 if (!RC->contains(EndReg))
2904 return Error(EndLoc, "invalid register in register list");
2905 // Ranges must go from low to high.
Eric Christopherdf1c6372012-08-09 22:10:21 +00002906 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jim Grosbachd0588e22011-09-14 18:08:35 +00002907 return Error(EndLoc, "bad range in register list");
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002908
Jim Grosbachd0588e22011-09-14 18:08:35 +00002909 // Add all the registers in the range to the register list.
2910 while (Reg != EndReg) {
2911 Reg = getNextRegister(Reg);
2912 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2913 }
2914 continue;
2915 }
2916 Parser.Lex(); // Eat the comma.
2917 RegLoc = Parser.getTok().getLoc();
2918 int OldReg = Reg;
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002919 const AsmToken RegTok = Parser.getTok();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002920 Reg = tryParseRegister();
2921 if (Reg == -1)
Jim Grosbach2d539692011-09-12 23:36:42 +00002922 return Error(RegLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002923 // Allow Q regs and just interpret them as the two D sub-registers.
2924 bool isQReg = false;
2925 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2926 Reg = getDRegFromQReg(Reg);
2927 isQReg = true;
2928 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002929 // The register must be in the same register class as the first.
2930 if (!RC->contains(Reg))
2931 return Error(RegLoc, "invalid register in register list");
2932 // List must be monotonically increasing.
Eric Christopherdf1c6372012-08-09 22:10:21 +00002933 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbachbe7cf2b2012-03-16 20:48:38 +00002934 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2935 Warning(RegLoc, "register list not in ascending order");
2936 else
2937 return Error(RegLoc, "register list not in ascending order");
2938 }
Eric Christopherdf1c6372012-08-09 22:10:21 +00002939 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002940 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2941 ") in register list");
2942 continue;
2943 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002944 // VFP register lists must also be contiguous.
2945 // It's OK to use the enumeration values directly here rather, as the
2946 // VFP register classes have the enum sorted properly.
2947 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2948 Reg != OldReg + 1)
2949 return Error(RegLoc, "non-contiguous register range");
2950 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbachce485e72011-11-11 21:27:40 +00002951 if (isQReg)
2952 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge7176102010-11-06 22:36:58 +00002953 }
2954
Jim Grosbachd0588e22011-09-14 18:08:35 +00002955 SMLoc E = Parser.getTok().getLoc();
2956 if (Parser.getTok().isNot(AsmToken::RCurly))
2957 return Error(E, "'}' expected");
2958 Parser.Lex(); // Eat '}' token.
2959
Jim Grosbach27debd62011-12-13 21:48:29 +00002960 // Push the register list operand.
Bill Wendling50d0f582010-11-18 23:43:05 +00002961 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach27debd62011-12-13 21:48:29 +00002962
2963 // The ARM system instruction variants for LDM/STM have a '^' token here.
2964 if (Parser.getTok().is(AsmToken::Caret)) {
2965 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2966 Parser.Lex(); // Eat '^' token.
2967 }
2968
Bill Wendling50d0f582010-11-18 23:43:05 +00002969 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002970}
2971
Jim Grosbach98b05a52011-11-30 01:09:44 +00002972// Helper function to parse the lane index for vector lists.
2973ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach7636bf62011-12-02 00:35:16 +00002974parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2975 Index = 0; // Always return a defined index value.
Jim Grosbach98b05a52011-11-30 01:09:44 +00002976 if (Parser.getTok().is(AsmToken::LBrac)) {
2977 Parser.Lex(); // Eat the '['.
2978 if (Parser.getTok().is(AsmToken::RBrac)) {
2979 // "Dn[]" is the 'all lanes' syntax.
2980 LaneKind = AllLanes;
2981 Parser.Lex(); // Eat the ']'.
2982 return MatchOperand_Success;
2983 }
Jim Grosbachceee9842012-03-19 20:39:53 +00002984
2985 // There's an optional '#' token here. Normally there wouldn't be, but
2986 // inline assemble puts one in, and it's friendly to accept that.
2987 if (Parser.getTok().is(AsmToken::Hash))
2988 Parser.Lex(); // Eat the '#'
2989
Jim Grosbachc9313252011-12-21 01:19:23 +00002990 const MCExpr *LaneIndex;
2991 SMLoc Loc = Parser.getTok().getLoc();
2992 if (getParser().ParseExpression(LaneIndex)) {
2993 Error(Loc, "illegal expression");
2994 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002995 }
Jim Grosbachc9313252011-12-21 01:19:23 +00002996 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2997 if (!CE) {
2998 Error(Loc, "lane index must be empty or an integer");
2999 return MatchOperand_ParseFail;
3000 }
3001 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3002 Error(Parser.getTok().getLoc(), "']' expected");
3003 return MatchOperand_ParseFail;
3004 }
3005 Parser.Lex(); // Eat the ']'.
3006 int64_t Val = CE->getValue();
3007
3008 // FIXME: Make this range check context sensitive for .8, .16, .32.
3009 if (Val < 0 || Val > 7) {
3010 Error(Parser.getTok().getLoc(), "lane index out of range");
3011 return MatchOperand_ParseFail;
3012 }
3013 Index = Val;
3014 LaneKind = IndexedLane;
3015 return MatchOperand_Success;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003016 }
3017 LaneKind = NoLanes;
3018 return MatchOperand_Success;
3019}
3020
Jim Grosbach862019c2011-10-18 23:02:30 +00003021// parse a vector register list
3022ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3023parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003024 VectorLaneTy LaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003025 unsigned LaneIndex;
Jim Grosbach5c984e42011-11-15 21:45:55 +00003026 SMLoc S = Parser.getTok().getLoc();
3027 // As an extension (to match gas), support a plain D register or Q register
3028 // (without encosing curly braces) as a single or double entry list,
3029 // respectively.
3030 if (Parser.getTok().is(AsmToken::Identifier)) {
3031 int Reg = tryParseRegister();
3032 if (Reg == -1)
3033 return MatchOperand_NoMatch;
3034 SMLoc E = Parser.getTok().getLoc();
3035 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00003036 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00003037 if (Res != MatchOperand_Success)
3038 return Res;
3039 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003040 case NoLanes:
3041 E = Parser.getTok().getLoc();
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003042 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003043 break;
3044 case AllLanes:
3045 E = Parser.getTok().getLoc();
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003046 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3047 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003048 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003049 case IndexedLane:
3050 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003051 LaneIndex,
3052 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003053 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003054 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003055 return MatchOperand_Success;
3056 }
3057 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3058 Reg = getDRegFromQReg(Reg);
Jim Grosbach7636bf62011-12-02 00:35:16 +00003059 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00003060 if (Res != MatchOperand_Success)
3061 return Res;
3062 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003063 case NoLanes:
3064 E = Parser.getTok().getLoc();
Jim Grosbach28f08c92012-03-05 19:33:30 +00003065 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003066 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003067 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003068 break;
3069 case AllLanes:
3070 E = Parser.getTok().getLoc();
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003071 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3072 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003073 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3074 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003075 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003076 case IndexedLane:
3077 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003078 LaneIndex,
3079 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003080 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003081 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003082 return MatchOperand_Success;
3083 }
3084 Error(S, "vector register expected");
3085 return MatchOperand_ParseFail;
3086 }
3087
3088 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbach862019c2011-10-18 23:02:30 +00003089 return MatchOperand_NoMatch;
3090
Jim Grosbach862019c2011-10-18 23:02:30 +00003091 Parser.Lex(); // Eat '{' token.
3092 SMLoc RegLoc = Parser.getTok().getLoc();
3093
3094 int Reg = tryParseRegister();
3095 if (Reg == -1) {
3096 Error(RegLoc, "register expected");
3097 return MatchOperand_ParseFail;
3098 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003099 unsigned Count = 1;
Jim Grosbach276ed032011-12-15 21:54:55 +00003100 int Spacing = 0;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003101 unsigned FirstReg = Reg;
3102 // The list is of D registers, but we also allow Q regs and just interpret
3103 // them as the two D sub-registers.
3104 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3105 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003106 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3107 // it's ambiguous with four-register single spaced.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003108 ++Reg;
3109 ++Count;
3110 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00003111 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003112 return MatchOperand_ParseFail;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003113
Jim Grosbache43862b2011-11-15 23:19:15 +00003114 while (Parser.getTok().is(AsmToken::Comma) ||
3115 Parser.getTok().is(AsmToken::Minus)) {
3116 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003117 if (!Spacing)
3118 Spacing = 1; // Register range implies a single spaced list.
3119 else if (Spacing == 2) {
3120 Error(Parser.getTok().getLoc(),
3121 "sequential registers in double spaced list");
3122 return MatchOperand_ParseFail;
3123 }
Jim Grosbache43862b2011-11-15 23:19:15 +00003124 Parser.Lex(); // Eat the minus.
3125 SMLoc EndLoc = Parser.getTok().getLoc();
3126 int EndReg = tryParseRegister();
3127 if (EndReg == -1) {
3128 Error(EndLoc, "register expected");
3129 return MatchOperand_ParseFail;
3130 }
3131 // Allow Q regs and just interpret them as the two D sub-registers.
3132 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3133 EndReg = getDRegFromQReg(EndReg) + 1;
3134 // If the register is the same as the start reg, there's nothing
3135 // more to do.
3136 if (Reg == EndReg)
3137 continue;
3138 // The register must be in the same register class as the first.
3139 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3140 Error(EndLoc, "invalid register in register list");
3141 return MatchOperand_ParseFail;
3142 }
3143 // Ranges must go from low to high.
3144 if (Reg > EndReg) {
3145 Error(EndLoc, "bad range in register list");
3146 return MatchOperand_ParseFail;
3147 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003148 // Parse the lane specifier if present.
3149 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003150 unsigned NextLaneIndex;
3151 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003152 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003153 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003154 Error(EndLoc, "mismatched lane index in register list");
3155 return MatchOperand_ParseFail;
3156 }
3157 EndLoc = Parser.getTok().getLoc();
Jim Grosbache43862b2011-11-15 23:19:15 +00003158
3159 // Add all the registers in the range to the register list.
3160 Count += EndReg - Reg;
3161 Reg = EndReg;
3162 continue;
3163 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003164 Parser.Lex(); // Eat the comma.
3165 RegLoc = Parser.getTok().getLoc();
3166 int OldReg = Reg;
3167 Reg = tryParseRegister();
3168 if (Reg == -1) {
3169 Error(RegLoc, "register expected");
3170 return MatchOperand_ParseFail;
3171 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003172 // vector register lists must be contiguous.
Jim Grosbach862019c2011-10-18 23:02:30 +00003173 // It's OK to use the enumeration values directly here rather, as the
3174 // VFP register classes have the enum sorted properly.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003175 //
3176 // The list is of D registers, but we also allow Q regs and just interpret
3177 // them as the two D sub-registers.
3178 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003179 if (!Spacing)
3180 Spacing = 1; // Register range implies a single spaced list.
3181 else if (Spacing == 2) {
3182 Error(RegLoc,
3183 "invalid register in double-spaced list (must be 'D' register')");
3184 return MatchOperand_ParseFail;
3185 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003186 Reg = getDRegFromQReg(Reg);
3187 if (Reg != OldReg + 1) {
3188 Error(RegLoc, "non-contiguous register range");
3189 return MatchOperand_ParseFail;
3190 }
3191 ++Reg;
3192 Count += 2;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003193 // Parse the lane specifier if present.
3194 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003195 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003196 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003197 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003198 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003199 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003200 Error(EndLoc, "mismatched lane index in register list");
3201 return MatchOperand_ParseFail;
3202 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003203 continue;
3204 }
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003205 // Normal D register.
3206 // Figure out the register spacing (single or double) of the list if
3207 // we don't know it already.
3208 if (!Spacing)
3209 Spacing = 1 + (Reg == OldReg + 2);
3210
3211 // Just check that it's contiguous and keep going.
3212 if (Reg != OldReg + Spacing) {
Jim Grosbach862019c2011-10-18 23:02:30 +00003213 Error(RegLoc, "non-contiguous register range");
3214 return MatchOperand_ParseFail;
3215 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003216 ++Count;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003217 // Parse the lane specifier if present.
3218 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003219 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003220 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003221 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003222 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003223 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003224 Error(EndLoc, "mismatched lane index in register list");
3225 return MatchOperand_ParseFail;
3226 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003227 }
3228
3229 SMLoc E = Parser.getTok().getLoc();
3230 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3231 Error(E, "'}' expected");
3232 return MatchOperand_ParseFail;
3233 }
3234 Parser.Lex(); // Eat '}' token.
3235
Jim Grosbach98b05a52011-11-30 01:09:44 +00003236 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003237 case NoLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003238 // Two-register operands have been converted to the
Jim Grosbachc3384c92012-03-05 21:43:40 +00003239 // composite register classes.
3240 if (Count == 2) {
3241 const MCRegisterClass *RC = (Spacing == 1) ?
3242 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3243 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3244 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3245 }
Jim Grosbach28f08c92012-03-05 19:33:30 +00003246
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003247 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3248 (Spacing == 2), S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003249 break;
3250 case AllLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003251 // Two-register operands have been converted to the
3252 // composite register classes.
Jim Grosbach4d0983a2012-03-06 23:10:38 +00003253 if (Count == 2) {
3254 const MCRegisterClass *RC = (Spacing == 1) ?
3255 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3256 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003257 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3258 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003259 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003260 (Spacing == 2),
Jim Grosbach98b05a52011-11-30 01:09:44 +00003261 S, E));
3262 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003263 case IndexedLane:
3264 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003265 LaneIndex,
3266 (Spacing == 2),
3267 S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003268 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003269 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003270 return MatchOperand_Success;
3271}
3272
Jim Grosbach43904292011-07-25 20:14:50 +00003273/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbachf922c472011-02-12 01:34:40 +00003274ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003275parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003276 SMLoc S = Parser.getTok().getLoc();
3277 const AsmToken &Tok = Parser.getTok();
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003278 unsigned Opt;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003279
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003280 if (Tok.is(AsmToken::Identifier)) {
3281 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003282
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003283 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3284 .Case("sy", ARM_MB::SY)
3285 .Case("st", ARM_MB::ST)
3286 .Case("sh", ARM_MB::ISH)
3287 .Case("ish", ARM_MB::ISH)
3288 .Case("shst", ARM_MB::ISHST)
3289 .Case("ishst", ARM_MB::ISHST)
3290 .Case("nsh", ARM_MB::NSH)
3291 .Case("un", ARM_MB::NSH)
3292 .Case("nshst", ARM_MB::NSHST)
3293 .Case("unst", ARM_MB::NSHST)
3294 .Case("osh", ARM_MB::OSH)
3295 .Case("oshst", ARM_MB::OSHST)
3296 .Default(~0U);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003297
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003298 if (Opt == ~0U)
3299 return MatchOperand_NoMatch;
3300
3301 Parser.Lex(); // Eat identifier token.
3302 } else if (Tok.is(AsmToken::Hash) ||
3303 Tok.is(AsmToken::Dollar) ||
3304 Tok.is(AsmToken::Integer)) {
3305 if (Parser.getTok().isNot(AsmToken::Integer))
3306 Parser.Lex(); // Eat the '#'.
3307 SMLoc Loc = Parser.getTok().getLoc();
3308
3309 const MCExpr *MemBarrierID;
3310 if (getParser().ParseExpression(MemBarrierID)) {
3311 Error(Loc, "illegal expression");
3312 return MatchOperand_ParseFail;
3313 }
3314
3315 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3316 if (!CE) {
3317 Error(Loc, "constant expression expected");
3318 return MatchOperand_ParseFail;
3319 }
3320
3321 int Val = CE->getValue();
3322 if (Val & ~0xf) {
3323 Error(Loc, "immediate value out of range");
3324 return MatchOperand_ParseFail;
3325 }
3326
3327 Opt = ARM_MB::RESERVED_0 + Val;
3328 } else
3329 return MatchOperand_ParseFail;
3330
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003331 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00003332 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003333}
3334
Jim Grosbach43904292011-07-25 20:14:50 +00003335/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003336ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003337parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003338 SMLoc S = Parser.getTok().getLoc();
3339 const AsmToken &Tok = Parser.getTok();
Richard Bartona1c73672012-06-14 10:48:04 +00003340 if (!Tok.is(AsmToken::Identifier))
3341 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003342 StringRef IFlagsStr = Tok.getString();
3343
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003344 // An iflags string of "none" is interpreted to mean that none of the AIF
3345 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003346 unsigned IFlags = 0;
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003347 if (IFlagsStr != "none") {
3348 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3349 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3350 .Case("a", ARM_PROC::A)
3351 .Case("i", ARM_PROC::I)
3352 .Case("f", ARM_PROC::F)
3353 .Default(~0U);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003354
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003355 // If some specific iflag is already set, it means that some letter is
3356 // present more than once, this is not acceptable.
3357 if (Flag == ~0U || (IFlags & Flag))
3358 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003359
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003360 IFlags |= Flag;
3361 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003362 }
3363
3364 Parser.Lex(); // Eat identifier token.
3365 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3366 return MatchOperand_Success;
3367}
3368
Jim Grosbach43904292011-07-25 20:14:50 +00003369/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003370ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003371parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003372 SMLoc S = Parser.getTok().getLoc();
3373 const AsmToken &Tok = Parser.getTok();
3374 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3375 StringRef Mask = Tok.getString();
3376
James Molloyacad68d2011-09-28 14:21:38 +00003377 if (isMClass()) {
3378 // See ARMv6-M 10.1.1
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00003379 std::string Name = Mask.lower();
3380 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderby0fd4f3c2012-05-17 22:18:01 +00003381 // Note: in the documentation:
3382 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3383 // for MSR APSR_nzcvq.
3384 // but we do make it an alias here. This is so to get the "mask encoding"
3385 // bits correct on MSR APSR writes.
3386 //
3387 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3388 // should really only be allowed when writing a special register. Note
3389 // they get dropped in the MRS instruction reading a special register as
3390 // the SYSm field is only 8 bits.
3391 //
3392 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3393 // includes the DSP extension but that is not checked.
3394 .Case("apsr", 0x800)
3395 .Case("apsr_nzcvq", 0x800)
3396 .Case("apsr_g", 0x400)
3397 .Case("apsr_nzcvqg", 0xc00)
3398 .Case("iapsr", 0x801)
3399 .Case("iapsr_nzcvq", 0x801)
3400 .Case("iapsr_g", 0x401)
3401 .Case("iapsr_nzcvqg", 0xc01)
3402 .Case("eapsr", 0x802)
3403 .Case("eapsr_nzcvq", 0x802)
3404 .Case("eapsr_g", 0x402)
3405 .Case("eapsr_nzcvqg", 0xc02)
3406 .Case("xpsr", 0x803)
3407 .Case("xpsr_nzcvq", 0x803)
3408 .Case("xpsr_g", 0x403)
3409 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderbyf49a4092012-06-15 22:14:44 +00003410 .Case("ipsr", 0x805)
3411 .Case("epsr", 0x806)
3412 .Case("iepsr", 0x807)
3413 .Case("msp", 0x808)
3414 .Case("psp", 0x809)
3415 .Case("primask", 0x810)
3416 .Case("basepri", 0x811)
3417 .Case("basepri_max", 0x812)
3418 .Case("faultmask", 0x813)
3419 .Case("control", 0x814)
James Molloyacad68d2011-09-28 14:21:38 +00003420 .Default(~0U);
Jim Grosbach18c8d122011-12-22 17:17:10 +00003421
James Molloyacad68d2011-09-28 14:21:38 +00003422 if (FlagsVal == ~0U)
3423 return MatchOperand_NoMatch;
3424
Kevin Enderbyf49a4092012-06-15 22:14:44 +00003425 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloyacad68d2011-09-28 14:21:38 +00003426 // basepri, basepri_max and faultmask only valid for V7m.
3427 return MatchOperand_NoMatch;
Jim Grosbach18c8d122011-12-22 17:17:10 +00003428
James Molloyacad68d2011-09-28 14:21:38 +00003429 Parser.Lex(); // Eat identifier token.
3430 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3431 return MatchOperand_Success;
3432 }
3433
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003434 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3435 size_t Start = 0, Next = Mask.find('_');
3436 StringRef Flags = "";
Benjamin Kramer59085362011-11-06 20:37:06 +00003437 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003438 if (Next != StringRef::npos)
3439 Flags = Mask.slice(Next+1, Mask.size());
3440
3441 // FlagsVal contains the complete mask:
3442 // 3-0: Mask
3443 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3444 unsigned FlagsVal = 0;
3445
3446 if (SpecReg == "apsr") {
3447 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +00003448 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003449 .Case("g", 0x4) // same as CPSR_s
3450 .Case("nzcvqg", 0xc) // same as CPSR_fs
3451 .Default(~0U);
3452
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003453 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003454 if (!Flags.empty())
3455 return MatchOperand_NoMatch;
3456 else
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003457 FlagsVal = 8; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003458 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003459 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbachb657a902012-04-05 03:17:53 +00003460 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3461 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00003462 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003463 for (int i = 0, e = Flags.size(); i != e; ++i) {
3464 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3465 .Case("c", 1)
3466 .Case("x", 2)
3467 .Case("s", 4)
3468 .Case("f", 8)
3469 .Default(~0U);
3470
3471 // If some specific flag is already set, it means that some letter is
3472 // present more than once, this is not acceptable.
3473 if (FlagsVal == ~0U || (FlagsVal & Flag))
3474 return MatchOperand_NoMatch;
3475 FlagsVal |= Flag;
3476 }
3477 } else // No match for special register.
3478 return MatchOperand_NoMatch;
3479
Owen Anderson7784f1d2011-10-21 18:43:28 +00003480 // Special register without flags is NOT equivalent to "fc" flags.
3481 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3482 // two lines would enable gas compatibility at the expense of breaking
3483 // round-tripping.
3484 //
3485 // if (!FlagsVal)
3486 // FlagsVal = 0x9;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003487
3488 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3489 if (SpecReg == "spsr")
3490 FlagsVal |= 16;
3491
3492 Parser.Lex(); // Eat identifier token.
3493 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3494 return MatchOperand_Success;
3495}
3496
Jim Grosbachf6c05252011-07-21 17:23:04 +00003497ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3498parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3499 int Low, int High) {
3500 const AsmToken &Tok = Parser.getTok();
3501 if (Tok.isNot(AsmToken::Identifier)) {
3502 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3503 return MatchOperand_ParseFail;
3504 }
3505 StringRef ShiftName = Tok.getString();
Benjamin Kramer59085362011-11-06 20:37:06 +00003506 std::string LowerOp = Op.lower();
3507 std::string UpperOp = Op.upper();
Jim Grosbachf6c05252011-07-21 17:23:04 +00003508 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3509 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3510 return MatchOperand_ParseFail;
3511 }
3512 Parser.Lex(); // Eat shift type token.
3513
3514 // There must be a '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003515 if (Parser.getTok().isNot(AsmToken::Hash) &&
3516 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbachf6c05252011-07-21 17:23:04 +00003517 Error(Parser.getTok().getLoc(), "'#' expected");
3518 return MatchOperand_ParseFail;
3519 }
3520 Parser.Lex(); // Eat hash token.
3521
3522 const MCExpr *ShiftAmount;
3523 SMLoc Loc = Parser.getTok().getLoc();
3524 if (getParser().ParseExpression(ShiftAmount)) {
3525 Error(Loc, "illegal expression");
3526 return MatchOperand_ParseFail;
3527 }
3528 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3529 if (!CE) {
3530 Error(Loc, "constant expression expected");
3531 return MatchOperand_ParseFail;
3532 }
3533 int Val = CE->getValue();
3534 if (Val < Low || Val > High) {
3535 Error(Loc, "immediate value out of range");
3536 return MatchOperand_ParseFail;
3537 }
3538
3539 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3540
3541 return MatchOperand_Success;
3542}
3543
Jim Grosbachc27d4f92011-07-22 17:44:50 +00003544ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3545parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3546 const AsmToken &Tok = Parser.getTok();
3547 SMLoc S = Tok.getLoc();
3548 if (Tok.isNot(AsmToken::Identifier)) {
3549 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3550 return MatchOperand_ParseFail;
3551 }
3552 int Val = StringSwitch<int>(Tok.getString())
3553 .Case("be", 1)
3554 .Case("le", 0)
3555 .Default(-1);
3556 Parser.Lex(); // Eat the token.
3557
3558 if (Val == -1) {
3559 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3560 return MatchOperand_ParseFail;
3561 }
3562 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3563 getContext()),
3564 S, Parser.getTok().getLoc()));
3565 return MatchOperand_Success;
3566}
3567
Jim Grosbach580f4a92011-07-25 22:20:28 +00003568/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3569/// instructions. Legal values are:
3570/// lsl #n 'n' in [0,31]
3571/// asr #n 'n' in [1,32]
3572/// n == 32 encoded as n == 0.
3573ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3574parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3575 const AsmToken &Tok = Parser.getTok();
3576 SMLoc S = Tok.getLoc();
3577 if (Tok.isNot(AsmToken::Identifier)) {
3578 Error(S, "shift operator 'asr' or 'lsl' expected");
3579 return MatchOperand_ParseFail;
3580 }
3581 StringRef ShiftName = Tok.getString();
3582 bool isASR;
3583 if (ShiftName == "lsl" || ShiftName == "LSL")
3584 isASR = false;
3585 else if (ShiftName == "asr" || ShiftName == "ASR")
3586 isASR = true;
3587 else {
3588 Error(S, "shift operator 'asr' or 'lsl' expected");
3589 return MatchOperand_ParseFail;
3590 }
3591 Parser.Lex(); // Eat the operator.
3592
3593 // A '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003594 if (Parser.getTok().isNot(AsmToken::Hash) &&
3595 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach580f4a92011-07-25 22:20:28 +00003596 Error(Parser.getTok().getLoc(), "'#' expected");
3597 return MatchOperand_ParseFail;
3598 }
3599 Parser.Lex(); // Eat hash token.
3600
3601 const MCExpr *ShiftAmount;
3602 SMLoc E = Parser.getTok().getLoc();
3603 if (getParser().ParseExpression(ShiftAmount)) {
3604 Error(E, "malformed shift expression");
3605 return MatchOperand_ParseFail;
3606 }
3607 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3608 if (!CE) {
3609 Error(E, "shift amount must be an immediate");
3610 return MatchOperand_ParseFail;
3611 }
3612
3613 int64_t Val = CE->getValue();
3614 if (isASR) {
3615 // Shift amount must be in [1,32]
3616 if (Val < 1 || Val > 32) {
3617 Error(E, "'asr' shift amount must be in range [1,32]");
3618 return MatchOperand_ParseFail;
3619 }
Owen Anderson0afa0092011-09-26 21:06:22 +00003620 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3621 if (isThumb() && Val == 32) {
3622 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3623 return MatchOperand_ParseFail;
3624 }
Jim Grosbach580f4a92011-07-25 22:20:28 +00003625 if (Val == 32) Val = 0;
3626 } else {
3627 // Shift amount must be in [1,32]
3628 if (Val < 0 || Val > 31) {
3629 Error(E, "'lsr' shift amount must be in range [0,31]");
3630 return MatchOperand_ParseFail;
3631 }
3632 }
3633
3634 E = Parser.getTok().getLoc();
3635 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3636
3637 return MatchOperand_Success;
3638}
3639
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003640/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3641/// of instructions. Legal values are:
3642/// ror #n 'n' in {0, 8, 16, 24}
3643ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3644parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3645 const AsmToken &Tok = Parser.getTok();
3646 SMLoc S = Tok.getLoc();
Jim Grosbach326efe52011-09-19 20:29:33 +00003647 if (Tok.isNot(AsmToken::Identifier))
3648 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003649 StringRef ShiftName = Tok.getString();
Jim Grosbach326efe52011-09-19 20:29:33 +00003650 if (ShiftName != "ror" && ShiftName != "ROR")
3651 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003652 Parser.Lex(); // Eat the operator.
3653
3654 // A '#' and a rotate amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003655 if (Parser.getTok().isNot(AsmToken::Hash) &&
3656 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003657 Error(Parser.getTok().getLoc(), "'#' expected");
3658 return MatchOperand_ParseFail;
3659 }
3660 Parser.Lex(); // Eat hash token.
3661
3662 const MCExpr *ShiftAmount;
3663 SMLoc E = Parser.getTok().getLoc();
3664 if (getParser().ParseExpression(ShiftAmount)) {
3665 Error(E, "malformed rotate expression");
3666 return MatchOperand_ParseFail;
3667 }
3668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3669 if (!CE) {
3670 Error(E, "rotate amount must be an immediate");
3671 return MatchOperand_ParseFail;
3672 }
3673
3674 int64_t Val = CE->getValue();
3675 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3676 // normally, zero is represented in asm by omitting the rotate operand
3677 // entirely.
3678 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3679 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3680 return MatchOperand_ParseFail;
3681 }
3682
3683 E = Parser.getTok().getLoc();
3684 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3685
3686 return MatchOperand_Success;
3687}
3688
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003689ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3690parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3691 SMLoc S = Parser.getTok().getLoc();
3692 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003693 if (Parser.getTok().isNot(AsmToken::Hash) &&
3694 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003695 Error(Parser.getTok().getLoc(), "'#' expected");
3696 return MatchOperand_ParseFail;
3697 }
3698 Parser.Lex(); // Eat hash token.
3699
3700 const MCExpr *LSBExpr;
3701 SMLoc E = Parser.getTok().getLoc();
3702 if (getParser().ParseExpression(LSBExpr)) {
3703 Error(E, "malformed immediate expression");
3704 return MatchOperand_ParseFail;
3705 }
3706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3707 if (!CE) {
3708 Error(E, "'lsb' operand must be an immediate");
3709 return MatchOperand_ParseFail;
3710 }
3711
3712 int64_t LSB = CE->getValue();
3713 // The LSB must be in the range [0,31]
3714 if (LSB < 0 || LSB > 31) {
3715 Error(E, "'lsb' operand must be in the range [0,31]");
3716 return MatchOperand_ParseFail;
3717 }
3718 E = Parser.getTok().getLoc();
3719
3720 // Expect another immediate operand.
3721 if (Parser.getTok().isNot(AsmToken::Comma)) {
3722 Error(Parser.getTok().getLoc(), "too few operands");
3723 return MatchOperand_ParseFail;
3724 }
3725 Parser.Lex(); // Eat hash token.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003726 if (Parser.getTok().isNot(AsmToken::Hash) &&
3727 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003728 Error(Parser.getTok().getLoc(), "'#' expected");
3729 return MatchOperand_ParseFail;
3730 }
3731 Parser.Lex(); // Eat hash token.
3732
3733 const MCExpr *WidthExpr;
3734 if (getParser().ParseExpression(WidthExpr)) {
3735 Error(E, "malformed immediate expression");
3736 return MatchOperand_ParseFail;
3737 }
3738 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3739 if (!CE) {
3740 Error(E, "'width' operand must be an immediate");
3741 return MatchOperand_ParseFail;
3742 }
3743
3744 int64_t Width = CE->getValue();
3745 // The LSB must be in the range [1,32-lsb]
3746 if (Width < 1 || Width > 32 - LSB) {
3747 Error(E, "'width' operand must be in the range [1,32-lsb]");
3748 return MatchOperand_ParseFail;
3749 }
3750 E = Parser.getTok().getLoc();
3751
3752 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3753
3754 return MatchOperand_Success;
3755}
3756
Jim Grosbach7ce05792011-08-03 23:50:40 +00003757ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3758parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3759 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003760 // postidx_reg := '+' register {, shift}
3761 // | '-' register {, shift}
3762 // | register {, shift}
Jim Grosbach7ce05792011-08-03 23:50:40 +00003763
3764 // This method must return MatchOperand_NoMatch without consuming any tokens
3765 // in the case where there is no match, as other alternatives take other
3766 // parse methods.
3767 AsmToken Tok = Parser.getTok();
3768 SMLoc S = Tok.getLoc();
3769 bool haveEaten = false;
Jim Grosbach16578b52011-08-05 16:11:38 +00003770 bool isAdd = true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003771 int Reg = -1;
3772 if (Tok.is(AsmToken::Plus)) {
3773 Parser.Lex(); // Eat the '+' token.
3774 haveEaten = true;
3775 } else if (Tok.is(AsmToken::Minus)) {
3776 Parser.Lex(); // Eat the '-' token.
Jim Grosbach16578b52011-08-05 16:11:38 +00003777 isAdd = false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003778 haveEaten = true;
3779 }
3780 if (Parser.getTok().is(AsmToken::Identifier))
3781 Reg = tryParseRegister();
3782 if (Reg == -1) {
3783 if (!haveEaten)
3784 return MatchOperand_NoMatch;
3785 Error(Parser.getTok().getLoc(), "register expected");
3786 return MatchOperand_ParseFail;
3787 }
3788 SMLoc E = Parser.getTok().getLoc();
3789
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003790 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3791 unsigned ShiftImm = 0;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00003792 if (Parser.getTok().is(AsmToken::Comma)) {
3793 Parser.Lex(); // Eat the ','.
3794 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3795 return MatchOperand_ParseFail;
3796 }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003797
3798 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3799 ShiftImm, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003800
3801 return MatchOperand_Success;
3802}
3803
Jim Grosbach251bf252011-08-10 21:56:18 +00003804ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3805parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3806 // Check for a post-index addressing register operand. Specifically:
3807 // am3offset := '+' register
3808 // | '-' register
3809 // | register
3810 // | # imm
3811 // | # + imm
3812 // | # - imm
3813
3814 // This method must return MatchOperand_NoMatch without consuming any tokens
3815 // in the case where there is no match, as other alternatives take other
3816 // parse methods.
3817 AsmToken Tok = Parser.getTok();
3818 SMLoc S = Tok.getLoc();
3819
3820 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003821 if (Parser.getTok().is(AsmToken::Hash) ||
3822 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach251bf252011-08-10 21:56:18 +00003823 Parser.Lex(); // Eat the '#'.
3824 // Explicitly look for a '-', as we need to encode negative zero
3825 // differently.
3826 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3827 const MCExpr *Offset;
3828 if (getParser().ParseExpression(Offset))
3829 return MatchOperand_ParseFail;
3830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3831 if (!CE) {
3832 Error(S, "constant expression expected");
3833 return MatchOperand_ParseFail;
3834 }
3835 SMLoc E = Tok.getLoc();
3836 // Negative zero is encoded as the flag value INT32_MIN.
3837 int32_t Val = CE->getValue();
3838 if (isNegative && Val == 0)
3839 Val = INT32_MIN;
3840
3841 Operands.push_back(
3842 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3843
3844 return MatchOperand_Success;
3845 }
3846
3847
3848 bool haveEaten = false;
3849 bool isAdd = true;
3850 int Reg = -1;
3851 if (Tok.is(AsmToken::Plus)) {
3852 Parser.Lex(); // Eat the '+' token.
3853 haveEaten = true;
3854 } else if (Tok.is(AsmToken::Minus)) {
3855 Parser.Lex(); // Eat the '-' token.
3856 isAdd = false;
3857 haveEaten = true;
3858 }
3859 if (Parser.getTok().is(AsmToken::Identifier))
3860 Reg = tryParseRegister();
3861 if (Reg == -1) {
3862 if (!haveEaten)
3863 return MatchOperand_NoMatch;
3864 Error(Parser.getTok().getLoc(), "register expected");
3865 return MatchOperand_ParseFail;
3866 }
3867 SMLoc E = Parser.getTok().getLoc();
3868
3869 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3870 0, S, E));
3871
3872 return MatchOperand_Success;
3873}
3874
Jim Grosbacha77295d2011-09-08 22:07:06 +00003875/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3876/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3877/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003878void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003879cvtT2LdrdPre(MCInst &Inst,
Jim Grosbacha77295d2011-09-08 22:07:06 +00003880 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3881 // Rt, Rt2
3882 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3883 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3884 // Create a writeback register dummy placeholder.
3885 Inst.addOperand(MCOperand::CreateReg(0));
3886 // addr
3887 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3888 // pred
3889 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacha77295d2011-09-08 22:07:06 +00003890}
3891
3892/// cvtT2StrdPre - Convert parsed operands to MCInst.
3893/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3894/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003895void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003896cvtT2StrdPre(MCInst &Inst,
Jim Grosbacha77295d2011-09-08 22:07:06 +00003897 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3898 // Create a writeback register dummy placeholder.
3899 Inst.addOperand(MCOperand::CreateReg(0));
3900 // Rt, Rt2
3901 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3902 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3903 // addr
3904 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3905 // pred
3906 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacha77295d2011-09-08 22:07:06 +00003907}
3908
Jim Grosbacheeec0252011-09-08 00:39:19 +00003909/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3910/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3911/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003912void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003913cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbacheeec0252011-09-08 00:39:19 +00003914 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3915 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3916
3917 // Create a writeback register dummy placeholder.
3918 Inst.addOperand(MCOperand::CreateImm(0));
3919
3920 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3921 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheeec0252011-09-08 00:39:19 +00003922}
3923
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003924/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3925/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3926/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003927void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003928cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003929 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3930 // Create a writeback register dummy placeholder.
3931 Inst.addOperand(MCOperand::CreateImm(0));
3932 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3933 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3934 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003935}
3936
Jim Grosbach1355cf12011-07-26 17:10:22 +00003937/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003938/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3939/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003940void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003941cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003942 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3943 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3944
3945 // Create a writeback register dummy placeholder.
3946 Inst.addOperand(MCOperand::CreateImm(0));
3947
Jim Grosbach7ce05792011-08-03 23:50:40 +00003948 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003949 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003950}
3951
Owen Anderson9ab0f252011-08-26 20:43:14 +00003952/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3953/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3954/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003955void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003956cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson9ab0f252011-08-26 20:43:14 +00003957 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3958 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3959
3960 // Create a writeback register dummy placeholder.
3961 Inst.addOperand(MCOperand::CreateImm(0));
3962
3963 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3964 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson9ab0f252011-08-26 20:43:14 +00003965}
3966
3967
Jim Grosbach548340c2011-08-11 19:22:40 +00003968/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3969/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3970/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003971void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003972cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbach548340c2011-08-11 19:22:40 +00003973 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3974 // Create a writeback register dummy placeholder.
3975 Inst.addOperand(MCOperand::CreateImm(0));
3976 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3977 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3978 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach548340c2011-08-11 19:22:40 +00003979}
3980
Jim Grosbach1355cf12011-07-26 17:10:22 +00003981/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003982/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3983/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003984void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003985cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003986 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3987 // Create a writeback register dummy placeholder.
3988 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach548340c2011-08-11 19:22:40 +00003989 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3990 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3991 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003992}
3993
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00003994/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3995/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3996/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003997void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003998cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00003999 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4000 // Create a writeback register dummy placeholder.
4001 Inst.addOperand(MCOperand::CreateImm(0));
4002 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4003 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4004 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00004005}
4006
Jim Grosbach7ce05792011-08-03 23:50:40 +00004007/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4008/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4009/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004010void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004011cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004012 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4013 // Rt
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004014 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004015 // Create a writeback register dummy placeholder.
4016 Inst.addOperand(MCOperand::CreateImm(0));
4017 // addr
4018 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4019 // offset
4020 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4021 // pred
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004022 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004023}
4024
Jim Grosbach7ce05792011-08-03 23:50:40 +00004025/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004026/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4027/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004028void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004029cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004030 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4031 // Rt
Owen Andersonaa3402e2011-07-28 17:18:57 +00004032 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004033 // Create a writeback register dummy placeholder.
4034 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004035 // addr
4036 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4037 // offset
4038 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4039 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004040 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004041}
4042
Jim Grosbach7ce05792011-08-03 23:50:40 +00004043/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004044/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4045/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004046void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004047cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004048 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004049 // Create a writeback register dummy placeholder.
4050 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004051 // Rt
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004052 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004053 // addr
4054 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4055 // offset
4056 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4057 // pred
4058 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004059}
4060
4061/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4062/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4063/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004064void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004065cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004066 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4067 // Create a writeback register dummy placeholder.
4068 Inst.addOperand(MCOperand::CreateImm(0));
4069 // Rt
4070 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4071 // addr
4072 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4073 // offset
4074 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4075 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004076 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004077}
4078
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004079/// cvtLdrdPre - Convert parsed operands to MCInst.
4080/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4081/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004082void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004083cvtLdrdPre(MCInst &Inst,
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004084 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4085 // Rt, Rt2
4086 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4087 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4088 // Create a writeback register dummy placeholder.
4089 Inst.addOperand(MCOperand::CreateImm(0));
4090 // addr
4091 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4092 // pred
4093 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004094}
4095
Jim Grosbach14605d12011-08-11 20:28:23 +00004096/// cvtStrdPre - Convert parsed operands to MCInst.
4097/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4098/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004099void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004100cvtStrdPre(MCInst &Inst,
Jim Grosbach14605d12011-08-11 20:28:23 +00004101 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4102 // Create a writeback register dummy placeholder.
4103 Inst.addOperand(MCOperand::CreateImm(0));
4104 // Rt, Rt2
4105 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4106 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4107 // addr
4108 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4109 // pred
4110 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach14605d12011-08-11 20:28:23 +00004111}
4112
Jim Grosbach623a4542011-08-10 22:42:16 +00004113/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4114/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4115/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004116void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004117cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbach623a4542011-08-10 22:42:16 +00004118 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4119 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4120 // Create a writeback register dummy placeholder.
4121 Inst.addOperand(MCOperand::CreateImm(0));
4122 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4123 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach623a4542011-08-10 22:42:16 +00004124}
4125
Chad Rosier1122fc42012-08-30 23:00:00 +00004126/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004127/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4128/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004129void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004130cvtThumbMultiply(MCInst &Inst,
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004131 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004132 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4133 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach1b332862011-11-10 22:10:12 +00004134 // If we have a three-operand form, make sure to set Rn to be the operand
4135 // that isn't the same as Rd.
4136 unsigned RegOp = 4;
4137 if (Operands.size() == 6 &&
4138 ((ARMOperand*)Operands[4])->getReg() ==
4139 ((ARMOperand*)Operands[3])->getReg())
4140 RegOp = 5;
4141 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4142 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004143 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004144}
Jim Grosbach623a4542011-08-10 22:42:16 +00004145
Chad Rosier359956d2012-08-31 00:03:31 +00004146void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004147cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach12431322011-10-24 22:16:58 +00004148 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4149 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004150 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004151 // Create a writeback register dummy placeholder.
4152 Inst.addOperand(MCOperand::CreateImm(0));
4153 // Vn
4154 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4155 // pred
4156 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach12431322011-10-24 22:16:58 +00004157}
4158
Chad Rosier359956d2012-08-31 00:03:31 +00004159void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004160cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach12431322011-10-24 22:16:58 +00004161 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4162 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004163 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004164 // Create a writeback register dummy placeholder.
4165 Inst.addOperand(MCOperand::CreateImm(0));
4166 // Vn
4167 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4168 // Vm
4169 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4170 // pred
4171 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach12431322011-10-24 22:16:58 +00004172}
4173
Chad Rosier359956d2012-08-31 00:03:31 +00004174void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004175cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach4334e032011-10-31 21:50:31 +00004176 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4177 // Create a writeback register dummy placeholder.
4178 Inst.addOperand(MCOperand::CreateImm(0));
4179 // Vn
4180 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4181 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004182 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004183 // pred
4184 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach4334e032011-10-31 21:50:31 +00004185}
4186
Chad Rosier359956d2012-08-31 00:03:31 +00004187void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004188cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach4334e032011-10-31 21:50:31 +00004189 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4190 // Create a writeback register dummy placeholder.
4191 Inst.addOperand(MCOperand::CreateImm(0));
4192 // Vn
4193 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4194 // Vm
4195 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4196 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004197 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004198 // pred
4199 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach4334e032011-10-31 21:50:31 +00004200}
4201
Bill Wendlinge7176102010-11-06 22:36:58 +00004202/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004203/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00004204bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004205parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +00004206 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00004207 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00004208 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00004209 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004210 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004211
Sean Callanan18b83232010-01-19 21:44:56 +00004212 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbach1355cf12011-07-26 17:10:22 +00004213 int BaseRegNum = tryParseRegister();
Jim Grosbach7ce05792011-08-03 23:50:40 +00004214 if (BaseRegNum == -1)
4215 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004216
Daniel Dunbar05710932011-01-18 05:34:17 +00004217 // The next token must either be a comma or a closing bracket.
4218 const AsmToken &Tok = Parser.getTok();
4219 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004220 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar05710932011-01-18 05:34:17 +00004221
Jim Grosbach7ce05792011-08-03 23:50:40 +00004222 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan76264762010-04-02 22:27:05 +00004223 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004224 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004225
Jim Grosbach7ce05792011-08-03 23:50:40 +00004226 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004227 0, 0, false, S, E));
Jim Grosbach03f44a02010-11-29 23:18:01 +00004228
Jim Grosbachfb12f352011-09-19 18:42:21 +00004229 // If there's a pre-indexing writeback marker, '!', just add it as a token
4230 // operand. It's rather odd, but syntactically valid.
4231 if (Parser.getTok().is(AsmToken::Exclaim)) {
4232 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4233 Parser.Lex(); // Eat the '!'.
4234 }
4235
Jim Grosbach7ce05792011-08-03 23:50:40 +00004236 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004237 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004238
Jim Grosbach7ce05792011-08-03 23:50:40 +00004239 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4240 Parser.Lex(); // Eat the comma.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004241
Jim Grosbach57dcb852011-10-11 17:29:55 +00004242 // If we have a ':', it's an alignment specifier.
4243 if (Parser.getTok().is(AsmToken::Colon)) {
4244 Parser.Lex(); // Eat the ':'.
4245 E = Parser.getTok().getLoc();
4246
4247 const MCExpr *Expr;
4248 if (getParser().ParseExpression(Expr))
4249 return true;
4250
4251 // The expression has to be a constant. Memory references with relocations
4252 // don't come through here, as they use the <label> forms of the relevant
4253 // instructions.
4254 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4255 if (!CE)
4256 return Error (E, "constant expression expected");
4257
4258 unsigned Align = 0;
4259 switch (CE->getValue()) {
4260 default:
Jim Grosbacheeaf1c12011-12-19 18:31:43 +00004261 return Error(E,
4262 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4263 case 16: Align = 2; break;
4264 case 32: Align = 4; break;
Jim Grosbach57dcb852011-10-11 17:29:55 +00004265 case 64: Align = 8; break;
4266 case 128: Align = 16; break;
4267 case 256: Align = 32; break;
4268 }
4269
4270 // Now we should have the closing ']'
4271 E = Parser.getTok().getLoc();
4272 if (Parser.getTok().isNot(AsmToken::RBrac))
4273 return Error(E, "']' expected");
4274 Parser.Lex(); // Eat right bracket token.
4275
4276 // Don't worry about range checking the value here. That's handled by
4277 // the is*() predicates.
4278 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4279 ARM_AM::no_shift, 0, Align,
4280 false, S, E));
4281
4282 // If there's a pre-indexing writeback marker, '!', just add it as a token
4283 // operand.
4284 if (Parser.getTok().is(AsmToken::Exclaim)) {
4285 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4286 Parser.Lex(); // Eat the '!'.
4287 }
4288
4289 return false;
4290 }
4291
4292 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004293 // offset. Be friendly and also accept a plain integer (without a leading
4294 // hash) for gas compatibility.
4295 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004296 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004297 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004298 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004299 Parser.Lex(); // Eat the '#'.
Jim Grosbach7ce05792011-08-03 23:50:40 +00004300 E = Parser.getTok().getLoc();
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004301
Owen Anderson0da10cf2011-08-29 19:36:44 +00004302 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004303 const MCExpr *Offset;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004304 if (getParser().ParseExpression(Offset))
4305 return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004306
4307 // The expression has to be a constant. Memory references with relocations
4308 // don't come through here, as they use the <label> forms of the relevant
4309 // instructions.
4310 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4311 if (!CE)
4312 return Error (E, "constant expression expected");
4313
Owen Anderson0da10cf2011-08-29 19:36:44 +00004314 // If the constant was #-0, represent it as INT32_MIN.
4315 int32_t Val = CE->getValue();
4316 if (isNegative && Val == 0)
4317 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4318
Jim Grosbach7ce05792011-08-03 23:50:40 +00004319 // Now we should have the closing ']'
4320 E = Parser.getTok().getLoc();
4321 if (Parser.getTok().isNot(AsmToken::RBrac))
4322 return Error(E, "']' expected");
4323 Parser.Lex(); // Eat right bracket token.
4324
4325 // Don't worry about range checking the value here. That's handled by
4326 // the is*() predicates.
4327 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004328 ARM_AM::no_shift, 0, 0,
4329 false, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004330
4331 // If there's a pre-indexing writeback marker, '!', just add it as a token
4332 // operand.
4333 if (Parser.getTok().is(AsmToken::Exclaim)) {
4334 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4335 Parser.Lex(); // Eat the '!'.
4336 }
4337
4338 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004339 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004340
4341 // The register offset is optionally preceded by a '+' or '-'
4342 bool isNegative = false;
4343 if (Parser.getTok().is(AsmToken::Minus)) {
4344 isNegative = true;
4345 Parser.Lex(); // Eat the '-'.
4346 } else if (Parser.getTok().is(AsmToken::Plus)) {
4347 // Nothing to do.
4348 Parser.Lex(); // Eat the '+'.
4349 }
4350
4351 E = Parser.getTok().getLoc();
4352 int OffsetRegNum = tryParseRegister();
4353 if (OffsetRegNum == -1)
4354 return Error(E, "register expected");
4355
4356 // If there's a shift operator, handle it.
4357 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004358 unsigned ShiftImm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004359 if (Parser.getTok().is(AsmToken::Comma)) {
4360 Parser.Lex(); // Eat the ','.
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004361 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004362 return true;
4363 }
4364
4365 // Now we should have the closing ']'
4366 E = Parser.getTok().getLoc();
4367 if (Parser.getTok().isNot(AsmToken::RBrac))
4368 return Error(E, "']' expected");
4369 Parser.Lex(); // Eat right bracket token.
4370
4371 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004372 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004373 S, E));
4374
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00004375 // If there's a pre-indexing writeback marker, '!', just add it as a token
4376 // operand.
4377 if (Parser.getTok().is(AsmToken::Exclaim)) {
4378 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4379 Parser.Lex(); // Eat the '!'.
4380 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004381
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004382 return false;
4383}
4384
Jim Grosbach7ce05792011-08-03 23:50:40 +00004385/// parseMemRegOffsetShift - one of these two:
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004386/// ( lsl | lsr | asr | ror ) , # shift_amount
4387/// rrx
Jim Grosbach7ce05792011-08-03 23:50:40 +00004388/// return true if it parses a shift otherwise it returns false.
4389bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4390 unsigned &Amount) {
4391 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan18b83232010-01-19 21:44:56 +00004392 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004393 if (Tok.isNot(AsmToken::Identifier))
4394 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00004395 StringRef ShiftName = Tok.getString();
Jim Grosbachaf4edea2011-12-07 23:40:58 +00004396 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4397 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson00828302011-03-18 22:50:18 +00004398 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004399 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00004400 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004401 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00004402 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004403 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00004404 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004405 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00004406 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004407 else
Jim Grosbach7ce05792011-08-03 23:50:40 +00004408 return Error(Loc, "illegal shift operator");
Sean Callananb9a25b72010-01-19 20:27:46 +00004409 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004410
Jim Grosbach7ce05792011-08-03 23:50:40 +00004411 // rrx stands alone.
4412 Amount = 0;
4413 if (St != ARM_AM::rrx) {
4414 Loc = Parser.getTok().getLoc();
4415 // A '#' and a shift amount.
4416 const AsmToken &HashTok = Parser.getTok();
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004417 if (HashTok.isNot(AsmToken::Hash) &&
4418 HashTok.isNot(AsmToken::Dollar))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004419 return Error(HashTok.getLoc(), "'#' expected");
4420 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004421
Jim Grosbach7ce05792011-08-03 23:50:40 +00004422 const MCExpr *Expr;
4423 if (getParser().ParseExpression(Expr))
4424 return true;
4425 // Range check the immediate.
4426 // lsl, ror: 0 <= imm <= 31
4427 // lsr, asr: 0 <= imm <= 32
4428 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4429 if (!CE)
4430 return Error(Loc, "shift amount must be an immediate");
4431 int64_t Imm = CE->getValue();
4432 if (Imm < 0 ||
4433 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4434 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4435 return Error(Loc, "immediate shift value out of range");
4436 Amount = Imm;
4437 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004438
4439 return false;
4440}
4441
Jim Grosbach9d390362011-10-03 23:38:36 +00004442/// parseFPImm - A floating point immediate expression operand.
4443ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4444parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004445 // Anything that can accept a floating point constant as an operand
4446 // needs to go through here, as the regular ParseExpression is
4447 // integer only.
4448 //
4449 // This routine still creates a generic Immediate operand, containing
4450 // a bitcast of the 64-bit floating point value. The various operands
4451 // that accept floats can check whether the value is valid for them
4452 // via the standard is*() predicates.
4453
Jim Grosbach9d390362011-10-03 23:38:36 +00004454 SMLoc S = Parser.getTok().getLoc();
4455
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004456 if (Parser.getTok().isNot(AsmToken::Hash) &&
4457 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbach9d390362011-10-03 23:38:36 +00004458 return MatchOperand_NoMatch;
Jim Grosbach0e387b22011-10-17 22:26:03 +00004459
4460 // Disambiguate the VMOV forms that can accept an FP immediate.
4461 // vmov.f32 <sreg>, #imm
4462 // vmov.f64 <dreg>, #imm
4463 // vmov.f32 <dreg>, #imm @ vector f32x2
4464 // vmov.f32 <qreg>, #imm @ vector f32x4
4465 //
4466 // There are also the NEON VMOV instructions which expect an
4467 // integer constant. Make sure we don't try to parse an FPImm
4468 // for these:
4469 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4470 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4471 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4472 TyOp->getToken() != ".f64"))
4473 return MatchOperand_NoMatch;
4474
Jim Grosbach9d390362011-10-03 23:38:36 +00004475 Parser.Lex(); // Eat the '#'.
4476
4477 // Handle negation, as that still comes through as a separate token.
4478 bool isNegative = false;
4479 if (Parser.getTok().is(AsmToken::Minus)) {
4480 isNegative = true;
4481 Parser.Lex();
4482 }
4483 const AsmToken &Tok = Parser.getTok();
Jim Grosbachae69f702012-01-19 02:47:30 +00004484 SMLoc Loc = Tok.getLoc();
Jim Grosbach9d390362011-10-03 23:38:36 +00004485 if (Tok.is(AsmToken::Real)) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004486 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbach9d390362011-10-03 23:38:36 +00004487 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4488 // If we had a '-' in front, toggle the sign bit.
Jim Grosbach51222d12012-01-20 18:09:51 +00004489 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbach9d390362011-10-03 23:38:36 +00004490 Parser.Lex(); // Eat the token.
Jim Grosbach51222d12012-01-20 18:09:51 +00004491 Operands.push_back(ARMOperand::CreateImm(
4492 MCConstantExpr::Create(IntVal, getContext()),
4493 S, Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004494 return MatchOperand_Success;
4495 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004496 // Also handle plain integers. Instructions which allow floating point
4497 // immediates also allow a raw encoded 8-bit value.
Jim Grosbach9d390362011-10-03 23:38:36 +00004498 if (Tok.is(AsmToken::Integer)) {
4499 int64_t Val = Tok.getIntVal();
4500 Parser.Lex(); // Eat the token.
4501 if (Val > 255 || Val < 0) {
Jim Grosbachae69f702012-01-19 02:47:30 +00004502 Error(Loc, "encoded floating point value out of range");
Jim Grosbach9d390362011-10-03 23:38:36 +00004503 return MatchOperand_ParseFail;
4504 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004505 double RealVal = ARM_AM::getFPImmFloat(Val);
4506 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4507 Operands.push_back(ARMOperand::CreateImm(
4508 MCConstantExpr::Create(Val, getContext()), S,
4509 Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004510 return MatchOperand_Success;
4511 }
4512
Jim Grosbachae69f702012-01-19 02:47:30 +00004513 Error(Loc, "invalid floating point immediate");
Jim Grosbach9d390362011-10-03 23:38:36 +00004514 return MatchOperand_ParseFail;
4515}
Jim Grosbach51222d12012-01-20 18:09:51 +00004516
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004517/// Parse a arm instruction operand. For now this parses the operand regardless
4518/// of the mnemonic.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004519bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004520 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00004521 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004522
4523 // Check if the current operand has a custom associated parser, if so, try to
4524 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00004525 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4526 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004527 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00004528 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4529 // there was a match, but an error occurred, in which case, just return that
4530 // the operand parsing failed.
4531 if (ResTy == MatchOperand_ParseFail)
4532 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004533
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004534 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00004535 default:
4536 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00004537 return true;
Jim Grosbach19906722011-07-13 18:49:30 +00004538 case AsmToken::Identifier: {
Jim Grosbach1355cf12011-07-26 17:10:22 +00004539 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling50d0f582010-11-18 23:43:05 +00004540 return false;
Jim Grosbach0d87ec22011-07-26 20:41:24 +00004541 int Res = tryParseShiftRegister(Operands);
Jim Grosbach19906722011-07-13 18:49:30 +00004542 if (Res == 0) // success
Owen Anderson00828302011-03-18 22:50:18 +00004543 return false;
Jim Grosbach19906722011-07-13 18:49:30 +00004544 else if (Res == -1) // irrecoverable error
4545 return true;
Jim Grosbach3cbe43f2011-12-20 22:26:38 +00004546 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004547 if (Mnemonic == "vmrs" &&
4548 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004549 S = Parser.getTok().getLoc();
4550 Parser.Lex();
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004551 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004552 return false;
4553 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00004554
4555 // Fall though for the Identifier case that is not a register or a
4556 // special name.
Jim Grosbach19906722011-07-13 18:49:30 +00004557 }
Jim Grosbach758a5192011-10-26 21:14:08 +00004558 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderby67b212e2011-01-13 20:32:36 +00004559 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach6284afc2011-11-01 22:38:31 +00004560 case AsmToken::String: // quoted label names.
Kevin Enderby67b212e2011-01-13 20:32:36 +00004561 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00004562 // This was not a register so parse other operands that start with an
4563 // identifier (like labels) as expressions and create them as immediates.
4564 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00004565 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00004566 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004567 return true;
Sean Callanan76264762010-04-02 22:27:05 +00004568 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004569 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4570 return false;
4571 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004572 case AsmToken::LBrac:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004573 return parseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00004574 case AsmToken::LCurly:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004575 return parseRegisterList(Operands);
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004576 case AsmToken::Dollar:
Owen Anderson63553c72011-08-29 17:17:09 +00004577 case AsmToken::Hash: {
Kevin Enderby079469f2009-10-13 23:33:38 +00004578 // #42 -> immediate.
Sean Callanan76264762010-04-02 22:27:05 +00004579 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004580 Parser.Lex();
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004581
4582 if (Parser.getTok().isNot(AsmToken::Colon)) {
4583 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4584 const MCExpr *ImmVal;
4585 if (getParser().ParseExpression(ImmVal))
4586 return true;
4587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4588 if (CE) {
4589 int32_t Val = CE->getValue();
4590 if (isNegative && Val == 0)
4591 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4592 }
4593 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4594 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4595 return false;
Owen Anderson63553c72011-08-29 17:17:09 +00004596 }
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004597 // w/ a ':' after the '#', it's just like a plain ':'.
4598 // FALLTHROUGH
Owen Anderson63553c72011-08-29 17:17:09 +00004599 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004600 case AsmToken::Colon: {
4601 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00004602 // FIXME: Check it's an expression prefix,
4603 // e.g. (FOO - :lower16:BAR) isn't legal.
4604 ARMMCExpr::VariantKind RefKind;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004605 if (parsePrefix(RefKind))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004606 return true;
4607
Evan Cheng75972122011-01-13 07:58:56 +00004608 const MCExpr *SubExprVal;
4609 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004610 return true;
4611
Evan Cheng75972122011-01-13 07:58:56 +00004612 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4613 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00004614 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00004615 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00004616 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004617 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004618 }
4619}
4620
Jim Grosbach1355cf12011-07-26 17:10:22 +00004621// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng75972122011-01-13 07:58:56 +00004622// :lower16: and :upper16:.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004623bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng75972122011-01-13 07:58:56 +00004624 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004625
4626 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00004627 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00004628 Parser.Lex(); // Eat ':'
4629
4630 if (getLexer().isNot(AsmToken::Identifier)) {
4631 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4632 return true;
4633 }
4634
4635 StringRef IDVal = Parser.getTok().getIdentifier();
4636 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00004637 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004638 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00004639 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004640 } else {
4641 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4642 return true;
4643 }
4644 Parser.Lex();
4645
4646 if (getLexer().isNot(AsmToken::Colon)) {
4647 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4648 return true;
4649 }
4650 Parser.Lex(); // Eat the last ':'
4651 return false;
4652}
4653
Daniel Dunbar352e1482011-01-11 15:59:50 +00004654/// \brief Given a mnemonic, split out possible predication code and carry
4655/// setting letters to form a canonical mnemonic and flags.
4656//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004657// FIXME: Would be nice to autogen this.
Jim Grosbach89df9962011-08-26 21:43:41 +00004658// FIXME: This is a bit of a maze of special cases.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004659StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5f160572011-07-19 20:10:31 +00004660 unsigned &PredicationCode,
4661 bool &CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004662 unsigned &ProcessorIMod,
4663 StringRef &ITMask) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004664 PredicationCode = ARMCC::AL;
4665 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004666 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004667
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004668 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00004669 //
4670 // FIXME: Would be nice to autogen this.
Jim Grosbach5f160572011-07-19 20:10:31 +00004671 if ((Mnemonic == "movs" && isThumb()) ||
4672 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4673 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4674 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4675 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4676 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4677 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbach68490192011-12-19 19:43:50 +00004678 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4679 Mnemonic == "fmuls")
Daniel Dunbar352e1482011-01-11 15:59:50 +00004680 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00004681
Jim Grosbach3f00e312011-07-11 17:09:57 +00004682 // First, split out any predication code. Ignore mnemonics we know aren't
4683 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbachab40f4b2011-07-20 18:20:31 +00004684 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach71725a02011-07-27 21:58:11 +00004685 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach04d55f12011-08-22 23:55:58 +00004686 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbach2f25d9b2011-09-01 18:22:13 +00004687 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbach3f00e312011-07-11 17:09:57 +00004688 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4689 .Case("eq", ARMCC::EQ)
4690 .Case("ne", ARMCC::NE)
4691 .Case("hs", ARMCC::HS)
4692 .Case("cs", ARMCC::HS)
4693 .Case("lo", ARMCC::LO)
4694 .Case("cc", ARMCC::LO)
4695 .Case("mi", ARMCC::MI)
4696 .Case("pl", ARMCC::PL)
4697 .Case("vs", ARMCC::VS)
4698 .Case("vc", ARMCC::VC)
4699 .Case("hi", ARMCC::HI)
4700 .Case("ls", ARMCC::LS)
4701 .Case("ge", ARMCC::GE)
4702 .Case("lt", ARMCC::LT)
4703 .Case("gt", ARMCC::GT)
4704 .Case("le", ARMCC::LE)
4705 .Case("al", ARMCC::AL)
4706 .Default(~0U);
4707 if (CC != ~0U) {
4708 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4709 PredicationCode = CC;
4710 }
Bill Wendling52925b62010-10-29 23:50:21 +00004711 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004712
Daniel Dunbar352e1482011-01-11 15:59:50 +00004713 // Next, determine if we have a carry setting bit. We explicitly ignore all
4714 // the instructions we know end in 's'.
4715 if (Mnemonic.endswith("s") &&
Jim Grosbach00f5d982011-08-17 22:49:09 +00004716 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5f160572011-07-19 20:10:31 +00004717 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4718 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4719 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach67ca1ad2011-12-08 00:49:29 +00004720 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach48171e72011-12-10 00:01:02 +00004721 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach9c397892011-12-19 19:02:41 +00004722 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbach6357cae2012-03-15 20:48:18 +00004723 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004724 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbache1cf5902011-07-29 20:26:09 +00004725 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004726 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4727 CarrySetting = true;
4728 }
4729
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004730 // The "cps" instruction can have a interrupt mode operand which is glued into
4731 // the mnemonic. Check if this is the case, split it and parse the imod op
4732 if (Mnemonic.startswith("cps")) {
4733 // Split out any imod code.
4734 unsigned IMod =
4735 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4736 .Case("ie", ARM_PROC::IE)
4737 .Case("id", ARM_PROC::ID)
4738 .Default(~0U);
4739 if (IMod != ~0U) {
4740 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4741 ProcessorIMod = IMod;
4742 }
4743 }
4744
Jim Grosbach89df9962011-08-26 21:43:41 +00004745 // The "it" instruction has the condition mask on the end of the mnemonic.
4746 if (Mnemonic.startswith("it")) {
4747 ITMask = Mnemonic.slice(2, Mnemonic.size());
4748 Mnemonic = Mnemonic.slice(0, 2);
4749 }
4750
Daniel Dunbar352e1482011-01-11 15:59:50 +00004751 return Mnemonic;
4752}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004753
4754/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4755/// inclusion of carry set or predication code operands.
4756//
4757// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004758void ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00004759getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004760 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004761 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4762 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004763 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004764 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004765 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004766 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004767 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004768 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004769 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004770 Mnemonic == "mla" || Mnemonic == "smlal" ||
4771 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004772 CanAcceptCarrySet = true;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004773 } else
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004774 CanAcceptCarrySet = false;
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004775
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004776 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4777 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4778 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4779 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbachad2dad92011-09-06 20:27:04 +00004780 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4781 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach0780b632011-08-19 23:24:36 +00004782 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach2bd01182011-10-11 21:55:36 +00004783 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4784 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4785 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbach4af54a42011-08-26 22:21:51 +00004786 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4787 !isThumb()) ||
Jim Grosbach1ad60c22011-09-10 00:15:36 +00004788 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004789 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004790 } else
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004791 CanAcceptPredicationCode = true;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004792
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004793 if (isThumb()) {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004794 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00004795 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004796 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004797 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004798}
4799
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004800bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4801 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004802 // FIXME: This is all horribly hacky. We really need a better way to deal
4803 // with optional operands like this in the matcher table.
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004804
4805 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4806 // another does not. Specifically, the MOVW instruction does not. So we
4807 // special case it here and remove the defaulted (non-setting) cc_out
4808 // operand if that's the instruction we're trying to match.
4809 //
4810 // We do this as post-processing of the explicit operands rather than just
4811 // conditionally adding the cc_out in the first place because we need
4812 // to check the type of the parsed immediate operand.
Owen Anderson8adf6202011-09-14 22:46:14 +00004813 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004814 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4815 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4816 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4817 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004818
4819 // Register-register 'add' for thumb does not have a cc_out operand
4820 // when there are only two register operands.
4821 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4822 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4823 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4824 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4825 return true;
Jim Grosbach72f39f82011-08-24 21:22:15 +00004826 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004827 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4828 // have to check the immediate range here since Thumb2 has a variant
4829 // that can handle a different range and has a cc_out operand.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004830 if (((isThumb() && Mnemonic == "add") ||
4831 (isThumbTwo() && Mnemonic == "sub")) &&
4832 Operands.size() == 6 &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004833 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4834 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4835 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004836 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004837 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004838 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004839 return true;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004840 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4841 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004842 // selecting via the generic "add" mnemonic, so to know that we
4843 // should remove the cc_out operand, we have to explicitly check that
4844 // it's not one of the other variants. Ugh.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004845 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4846 Operands.size() == 6 &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004847 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4848 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4849 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4850 // Nest conditions rather than one big 'if' statement for readability.
4851 //
4852 // If either register is a high reg, it's either one of the SP
4853 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach12a88632012-01-21 00:07:56 +00004854 // check against T3. If the second register is the PC, this is an
4855 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004856 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4857 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach12a88632012-01-21 00:07:56 +00004858 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004859 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4860 return false;
4861 // If both registers are low, we're in an IT block, and the immediate is
4862 // in range, we should use encoding T1 instead, which has a cc_out.
4863 if (inITBlock() &&
Jim Grosbach64944f42011-09-14 21:00:40 +00004864 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004865 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4866 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4867 return false;
4868
4869 // Otherwise, we use encoding T4, which does not have a cc_out
4870 // operand.
4871 return true;
4872 }
4873
Jim Grosbach64944f42011-09-14 21:00:40 +00004874 // The thumb2 multiply instruction doesn't have a CCOut register, so
4875 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4876 // use the 16-bit encoding or not.
4877 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4878 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4879 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4880 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4881 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4882 // If the registers aren't low regs, the destination reg isn't the
4883 // same as one of the source regs, or the cc_out operand is zero
4884 // outside of an IT block, we have to use the 32-bit encoding, so
4885 // remove the cc_out operand.
4886 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4887 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach1de0bd12011-11-15 19:29:45 +00004888 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach64944f42011-09-14 21:00:40 +00004889 !inITBlock() ||
4890 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4891 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4892 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4893 static_cast<ARMOperand*>(Operands[4])->getReg())))
4894 return true;
4895
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004896 // Also check the 'mul' syntax variant that doesn't specify an explicit
4897 // destination register.
4898 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4899 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4900 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4901 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4902 // If the registers aren't low regs or the cc_out operand is zero
4903 // outside of an IT block, we have to use the 32-bit encoding, so
4904 // remove the cc_out operand.
4905 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4906 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4907 !inITBlock()))
4908 return true;
4909
Jim Grosbach64944f42011-09-14 21:00:40 +00004910
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004911
Jim Grosbachf69c8042011-08-24 21:42:27 +00004912 // Register-register 'add/sub' for thumb does not have a cc_out operand
4913 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4914 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4915 // right, this will result in better diagnostics (which operand is off)
4916 // anyway.
4917 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4918 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004919 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4920 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004921 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4922 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4923 (Operands.size() == 6 &&
4924 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004925 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004926
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004927 return false;
4928}
4929
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004930static bool isDataTypeToken(StringRef Tok) {
4931 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4932 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4933 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4934 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4935 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4936 Tok == ".f" || Tok == ".d";
4937}
4938
4939// FIXME: This bit should probably be handled via an explicit match class
4940// in the .td files that matches the suffix instead of having it be
4941// a literal string token the way it is now.
4942static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4943 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4944}
4945
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004946static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004947/// Parse an arm instruction mnemonic followed by its operands.
4948bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4949 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004950 // Apply mnemonic aliases before doing anything else, as the destination
4951 // mnemnonic may include suffices and we want to handle them normally.
4952 // The generic tblgen'erated code does this later, at the start of
4953 // MatchInstructionImpl(), but that's too late for aliases that include
4954 // any sort of suffix.
4955 unsigned AvailableFeatures = getAvailableFeatures();
4956 applyMnemonicAliases(Name, AvailableFeatures);
4957
Jim Grosbacha39cda72011-12-14 02:16:11 +00004958 // First check for the ARM-specific .req directive.
4959 if (Parser.getTok().is(AsmToken::Identifier) &&
4960 Parser.getTok().getIdentifier() == ".req") {
4961 parseDirectiveReq(Name, NameLoc);
4962 // We always return 'error' for this, as we're done with this
4963 // statement and don't need to match the 'instruction."
4964 return true;
4965 }
4966
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004967 // Create the leading tokens for the mnemonic, split by '.' characters.
4968 size_t Start = 0, Next = Name.find('.');
Jim Grosbachffa32252011-07-19 19:13:28 +00004969 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004970
Daniel Dunbar352e1482011-01-11 15:59:50 +00004971 // Split out the predication code and carry setting flag from the mnemonic.
4972 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004973 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004974 bool CarrySetting;
Jim Grosbach89df9962011-08-26 21:43:41 +00004975 StringRef ITMask;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004976 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004977 ProcessorIMod, ITMask);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004978
Jim Grosbach0c49ac02011-08-25 17:23:55 +00004979 // In Thumb1, only the branch (B) instruction can be predicated.
4980 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4981 Parser.EatToEndOfStatement();
4982 return Error(NameLoc, "conditional execution not supported in Thumb1");
4983 }
4984
Jim Grosbachffa32252011-07-19 19:13:28 +00004985 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4986
Jim Grosbach89df9962011-08-26 21:43:41 +00004987 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4988 // is the mask as it will be for the IT encoding if the conditional
4989 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4990 // where the conditional bit0 is zero, the instruction post-processing
4991 // will adjust the mask accordingly.
4992 if (Mnemonic == "it") {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004993 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4994 if (ITMask.size() > 3) {
4995 Parser.EatToEndOfStatement();
4996 return Error(Loc, "too many conditions on IT instruction");
4997 }
Jim Grosbach89df9962011-08-26 21:43:41 +00004998 unsigned Mask = 8;
4999 for (unsigned i = ITMask.size(); i != 0; --i) {
5000 char pos = ITMask[i - 1];
5001 if (pos != 't' && pos != 'e') {
5002 Parser.EatToEndOfStatement();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005003 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach89df9962011-08-26 21:43:41 +00005004 }
5005 Mask >>= 1;
5006 if (ITMask[i - 1] == 't')
5007 Mask |= 8;
5008 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005009 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach89df9962011-08-26 21:43:41 +00005010 }
5011
Jim Grosbachffa32252011-07-19 19:13:28 +00005012 // FIXME: This is all a pretty gross hack. We should automatically handle
5013 // optional operands like this via tblgen.
Bill Wendling9717fa92010-11-21 10:56:05 +00005014
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005015 // Next, add the CCOut and ConditionCode operands, if needed.
5016 //
5017 // For mnemonics which can ever incorporate a carry setting bit or predication
5018 // code, our matching model involves us always generating CCOut and
5019 // ConditionCode operands to match the mnemonic "as written" and then we let
5020 // the matcher deal with finding the right instruction or generating an
5021 // appropriate error.
5022 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbach1355cf12011-07-26 17:10:22 +00005023 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005024
Jim Grosbach33c16a22011-07-14 22:04:21 +00005025 // If we had a carry-set on an instruction that can't do that, issue an
5026 // error.
5027 if (!CanAcceptCarrySet && CarrySetting) {
5028 Parser.EatToEndOfStatement();
Jim Grosbachffa32252011-07-19 19:13:28 +00005029 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach33c16a22011-07-14 22:04:21 +00005030 "' can not set flags, but 's' suffix specified");
5031 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +00005032 // If we had a predication code on an instruction that can't do that, issue an
5033 // error.
5034 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5035 Parser.EatToEndOfStatement();
5036 return Error(NameLoc, "instruction '" + Mnemonic +
5037 "' is not predicable, but condition code specified");
5038 }
Jim Grosbach33c16a22011-07-14 22:04:21 +00005039
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005040 // Add the carry setting operand, if necessary.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005041 if (CanAcceptCarrySet) {
5042 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005043 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005044 Loc));
5045 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005046
5047 // Add the predication code operand, if necessary.
5048 if (CanAcceptPredicationCode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005049 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5050 CarrySetting);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005051 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005052 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00005053 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005054
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005055 // Add the processor imod operand, if necessary.
5056 if (ProcessorIMod) {
5057 Operands.push_back(ARMOperand::CreateImm(
5058 MCConstantExpr::Create(ProcessorIMod, getContext()),
5059 NameLoc, NameLoc));
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005060 }
5061
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005062 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00005063 while (Next != StringRef::npos) {
5064 Start = Next;
5065 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005066 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005067
Jim Grosbach7aef99b2011-11-11 23:08:10 +00005068 // Some NEON instructions have an optional datatype suffix that is
5069 // completely ignored. Check for that.
5070 if (isDataTypeToken(ExtraToken) &&
5071 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5072 continue;
5073
Jim Grosbach81d2e392011-09-07 16:06:04 +00005074 if (ExtraToken != ".n") {
5075 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5076 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5077 }
Daniel Dunbar5747b132010-08-11 06:37:16 +00005078 }
5079
5080 // Read the remaining operands.
5081 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005082 // Read the first operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005083 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005084 Parser.EatToEndOfStatement();
5085 return true;
5086 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005087
5088 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00005089 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005090
5091 // Parse and remember the operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005092 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005093 Parser.EatToEndOfStatement();
5094 return true;
5095 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005096 }
5097 }
Jim Grosbach16c74252010-10-29 14:46:02 +00005098
Chris Lattnercbf8a982010-09-11 16:18:25 +00005099 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbach186ffac2011-10-07 18:27:04 +00005100 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00005101 Parser.EatToEndOfStatement();
Jim Grosbach186ffac2011-10-07 18:27:04 +00005102 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00005103 }
Bill Wendling146018f2010-11-06 21:42:12 +00005104
Chris Lattner34e53142010-09-08 05:10:46 +00005105 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbachffa32252011-07-19 19:13:28 +00005106
Jim Grosbachd54b4e62011-08-16 21:12:37 +00005107 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5108 // do and don't have a cc_out optional-def operand. With some spot-checks
5109 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach20ed2e72011-09-01 00:28:52 +00005110 // parse and adjust accordingly before actually matching. We shouldn't ever
5111 // try to remove a cc_out operand that was explicitly set on the the
5112 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5113 // table driven matcher doesn't fit well with the ARM instruction set.
5114 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbachffa32252011-07-19 19:13:28 +00005115 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5116 Operands.erase(Operands.begin() + 1);
5117 delete Op;
5118 }
5119
Jim Grosbachcf121c32011-07-28 21:57:55 +00005120 // ARM mode 'blx' need special handling, as the register operand version
5121 // is predicable, but the label operand version is not. So, we can't rely
5122 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach21ff17c2011-10-07 23:24:09 +00005123 // a k_CondCode operand in the list. If we're trying to match the label
5124 // version, remove the k_CondCode operand here.
Jim Grosbachcf121c32011-07-28 21:57:55 +00005125 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5126 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5127 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5128 Operands.erase(Operands.begin() + 1);
5129 delete Op;
5130 }
Jim Grosbach857e1a72011-08-11 23:51:13 +00005131
5132 // The vector-compare-to-zero instructions have a literal token "#0" at
5133 // the end that comes to here as an immediate operand. Convert it to a
5134 // token to play nicely with the matcher.
5135 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5136 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5137 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5138 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5139 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5140 if (CE && CE->getValue() == 0) {
5141 Operands.erase(Operands.begin() + 5);
5142 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5143 delete Op;
5144 }
5145 }
Jim Grosbach68259142011-10-03 22:30:24 +00005146 // VCMP{E} does the same thing, but with a different operand count.
5147 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5148 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5149 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5150 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5151 if (CE && CE->getValue() == 0) {
5152 Operands.erase(Operands.begin() + 4);
5153 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5154 delete Op;
5155 }
5156 }
Jim Grosbach934755a2011-08-22 23:47:13 +00005157 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach55b02f22011-12-13 20:50:38 +00005158 // end. Convert it to a token here. Take care not to convert those
5159 // that should hit the Thumb2 encoding.
Jim Grosbach934755a2011-08-22 23:47:13 +00005160 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach55b02f22011-12-13 20:50:38 +00005161 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5162 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbach934755a2011-08-22 23:47:13 +00005163 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5164 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5165 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach55b02f22011-12-13 20:50:38 +00005166 if (CE && CE->getValue() == 0 &&
5167 (isThumbOne() ||
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005168 // The cc_out operand matches the IT block.
5169 ((inITBlock() != CarrySetting) &&
5170 // Neither register operand is a high register.
Jim Grosbach55b02f22011-12-13 20:50:38 +00005171 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005172 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbach934755a2011-08-22 23:47:13 +00005173 Operands.erase(Operands.begin() + 5);
5174 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5175 delete Op;
5176 }
5177 }
5178
Chris Lattner98986712010-01-14 22:21:20 +00005179 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00005180}
5181
Jim Grosbach189610f2011-07-26 18:25:39 +00005182// Validate context-sensitive operand constraints.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005183
5184// return 'true' if register list contains non-low GPR registers,
5185// 'false' otherwise. If Reg is in the register list or is HiReg, set
5186// 'containsReg' to true.
5187static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5188 unsigned HiReg, bool &containsReg) {
5189 containsReg = false;
5190 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5191 unsigned OpReg = Inst.getOperand(i).getReg();
5192 if (OpReg == Reg)
5193 containsReg = true;
5194 // Anything other than a low register isn't legal here.
5195 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5196 return true;
5197 }
5198 return false;
5199}
5200
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005201// Check if the specified regisgter is in the register list of the inst,
5202// starting at the indicated operand number.
5203static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5204 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5205 unsigned OpReg = Inst.getOperand(i).getReg();
5206 if (OpReg == Reg)
5207 return true;
5208 }
5209 return false;
5210}
5211
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005212// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5213// the ARMInsts array) instead. Getting that here requires awkward
5214// API changes, though. Better way?
5215namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005216extern const MCInstrDesc ARMInsts[];
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005217}
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005218static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005219 return ARMInsts[Opcode];
5220}
5221
Jim Grosbach189610f2011-07-26 18:25:39 +00005222// FIXME: We would really like to be able to tablegen'erate this.
5223bool ARMAsmParser::
5224validateInstruction(MCInst &Inst,
5225 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005226 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005227 SMLoc Loc = Operands[0]->getStartLoc();
5228 // Check the IT block state first.
Jim Grosbach74423e32012-01-25 19:52:01 +00005229 // NOTE: BKPT instruction has the interesting property of being
5230 // allowed in IT blocks, but not being predicable. It just always
Owen Andersonb6b7f512011-09-13 17:59:19 +00005231 // executes.
Jim Grosbach74423e32012-01-25 19:52:01 +00005232 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5233 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005234 unsigned bit = 1;
5235 if (ITState.FirstCond)
5236 ITState.FirstCond = false;
5237 else
Jim Grosbacha1109882011-09-02 23:22:08 +00005238 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005239 // The instruction must be predicable.
5240 if (!MCID.isPredicable())
5241 return Error(Loc, "instructions in IT block must be predicable");
5242 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5243 unsigned ITCond = bit ? ITState.Cond :
5244 ARMCC::getOppositeCondition(ITState.Cond);
5245 if (Cond != ITCond) {
5246 // Find the condition code Operand to get its SMLoc information.
5247 SMLoc CondLoc;
5248 for (unsigned i = 1; i < Operands.size(); ++i)
5249 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5250 CondLoc = Operands[i]->getStartLoc();
5251 return Error(CondLoc, "incorrect condition in IT block; got '" +
5252 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5253 "', but expected '" +
5254 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5255 }
Jim Grosbachc9a9b442011-08-31 18:29:05 +00005256 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005257 } else if (isThumbTwo() && MCID.isPredicable() &&
5258 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson51f6a7a2011-09-09 21:48:23 +00005259 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5260 Inst.getOpcode() != ARM::t2B)
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005261 return Error(Loc, "predicated instructions must be in IT block");
5262
Jim Grosbach189610f2011-07-26 18:25:39 +00005263 switch (Inst.getOpcode()) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00005264 case ARM::LDRD:
5265 case ARM::LDRD_PRE:
5266 case ARM::LDRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005267 case ARM::LDREXD: {
5268 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005269 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5270 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbach189610f2011-07-26 18:25:39 +00005271 if (Rt2 != Rt + 1)
5272 return Error(Operands[3]->getStartLoc(),
5273 "destination operands must be sequential");
5274 return false;
5275 }
Jim Grosbach14605d12011-08-11 20:28:23 +00005276 case ARM::STRD: {
5277 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005278 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5279 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbach14605d12011-08-11 20:28:23 +00005280 if (Rt2 != Rt + 1)
5281 return Error(Operands[3]->getStartLoc(),
5282 "source operands must be sequential");
5283 return false;
5284 }
Jim Grosbach53642c52011-08-10 20:49:18 +00005285 case ARM::STRD_PRE:
5286 case ARM::STRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005287 case ARM::STREXD: {
5288 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005289 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5290 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbach189610f2011-07-26 18:25:39 +00005291 if (Rt2 != Rt + 1)
Jim Grosbach14605d12011-08-11 20:28:23 +00005292 return Error(Operands[3]->getStartLoc(),
Jim Grosbach189610f2011-07-26 18:25:39 +00005293 "source operands must be sequential");
5294 return false;
5295 }
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005296 case ARM::SBFX:
5297 case ARM::UBFX: {
5298 // width must be in range [1, 32-lsb]
5299 unsigned lsb = Inst.getOperand(2).getImm();
5300 unsigned widthm1 = Inst.getOperand(3).getImm();
5301 if (widthm1 >= 32 - lsb)
5302 return Error(Operands[5]->getStartLoc(),
5303 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach00c9a512011-08-16 21:42:31 +00005304 return false;
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005305 }
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005306 case ARM::tLDMIA: {
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005307 // If we're parsing Thumb2, the .w variant is available and handles
5308 // most cases that are normally illegal for a Thumb1 LDM
5309 // instruction. We'll make the transformation in processInstruction()
5310 // if necessary.
5311 //
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005312 // Thumb LDM instructions are writeback iff the base register is not
5313 // in the register list.
5314 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005315 bool hasWritebackToken =
5316 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5317 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbachaa875f82011-08-23 18:13:04 +00005318 bool listContainsBase;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005319 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005320 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5321 "registers must be in range r0-r7");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005322 // If we should have writeback, then there should be a '!' token.
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005323 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005324 return Error(Operands[2]->getStartLoc(),
5325 "writeback operator '!' expected");
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005326 // If we should not have writeback, there must not be a '!'. This is
5327 // true even for the 32-bit wide encodings.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005328 if (listContainsBase && hasWritebackToken)
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005329 return Error(Operands[3]->getStartLoc(),
5330 "writeback operator '!' not allowed when base register "
5331 "in register list");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005332
5333 break;
5334 }
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005335 case ARM::t2LDMIA_UPD: {
5336 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5337 return Error(Operands[4]->getStartLoc(),
5338 "writeback operator '!' not allowed when base register "
5339 "in register list");
5340 break;
5341 }
Chad Rosier64b34442012-08-30 23:20:38 +00005342 case ARM::tMUL: {
5343 // The second source operand must be the same register as the destination
5344 // operand.
Chad Rosier429af6f2012-08-31 17:24:10 +00005345 //
5346 // In this case, we must directly check the parsed operands because the
5347 // cvtThumbMultiply() function is written in such a way that it guarantees
5348 // this first statement is always true for the new Inst. Essentially, the
5349 // destination is unconditionally copied into the second source operand
5350 // without checking to see if it matches what we actually parsed.
Chad Rosier64b34442012-08-30 23:20:38 +00005351 if (Operands.size() == 6 &&
5352 (((ARMOperand*)Operands[3])->getReg() !=
5353 ((ARMOperand*)Operands[5])->getReg()) &&
5354 (((ARMOperand*)Operands[3])->getReg() !=
5355 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierfafa2832012-08-30 23:22:05 +00005356 return Error(Operands[3]->getStartLoc(),
5357 "destination register must match source register");
Chad Rosier64b34442012-08-30 23:20:38 +00005358 }
5359 break;
5360 }
Jim Grosbach54026372011-11-10 23:17:11 +00005361 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5362 // so only issue a diagnostic for thumb1. The instructions will be
5363 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005364 case ARM::tPOP: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005365 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005366 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5367 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005368 return Error(Operands[2]->getStartLoc(),
5369 "registers must be in range r0-r7 or pc");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005370 break;
5371 }
5372 case ARM::tPUSH: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005373 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005374 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5375 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005376 return Error(Operands[2]->getStartLoc(),
5377 "registers must be in range r0-r7 or lr");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005378 break;
5379 }
Jim Grosbach1e84f192011-08-23 18:15:37 +00005380 case ARM::tSTMIA_UPD: {
5381 bool listContainsBase;
Jim Grosbach8213c962011-09-16 20:50:13 +00005382 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach1e84f192011-08-23 18:15:37 +00005383 return Error(Operands[4]->getStartLoc(),
5384 "registers must be in range r0-r7");
5385 break;
5386 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00005387 case ARM::tADDrSP: {
5388 // If the non-SP source operand and the destination operand are not the
5389 // same, we need thumb2 (for the wide encoding), or we have an error.
5390 if (!isThumbTwo() &&
5391 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5392 return Error(Operands[4]->getStartLoc(),
5393 "source register must be the same as destination");
5394 }
5395 break;
5396 }
Jim Grosbach189610f2011-07-26 18:25:39 +00005397 }
5398
5399 return false;
5400}
5401
Jim Grosbachd7433e22012-01-23 23:45:44 +00005402static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach84defb52011-12-02 22:34:51 +00005403 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005404 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005405 // VST1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005406 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5407 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5408 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5409 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5410 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5411 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5412 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5413 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5414 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005415
5416 // VST2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005417 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5418 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5419 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5420 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5421 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005422
Jim Grosbach7945ead2012-01-24 00:43:12 +00005423 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5424 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5425 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5426 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5427 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005428
Jim Grosbach7945ead2012-01-24 00:43:12 +00005429 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5430 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5431 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5432 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5433 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005434
Jim Grosbach4adb1822012-01-24 00:07:41 +00005435 // VST3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005436 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5437 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5438 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5439 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5440 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5441 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5442 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5443 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5444 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5445 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5446 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5447 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5448 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5449 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5450 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbach4adb1822012-01-24 00:07:41 +00005451
Jim Grosbachd7433e22012-01-23 23:45:44 +00005452 // VST3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005453 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5454 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5455 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5456 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5457 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5458 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5459 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5460 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5461 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5462 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5463 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5464 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5465 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5466 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5467 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5468 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5469 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5470 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbach539aab72012-01-24 00:58:13 +00005471
Jim Grosbach88a54de2012-01-24 18:53:13 +00005472 // VST4LN
5473 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5474 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5475 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5476 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5477 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5478 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5479 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5480 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5481 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5482 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5483 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5484 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5485 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5486 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5487 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5488
Jim Grosbach539aab72012-01-24 00:58:13 +00005489 // VST4
5490 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5491 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5492 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5493 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5494 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5495 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5496 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5497 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5498 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5499 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5500 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5501 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5502 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5503 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5504 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5505 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5506 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5507 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbach84defb52011-12-02 22:34:51 +00005508 }
5509}
5510
Jim Grosbachd7433e22012-01-23 23:45:44 +00005511static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00005512 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005513 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005514 // VLD1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005515 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5516 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5517 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5518 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5519 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5520 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5521 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5522 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5523 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005524
5525 // VLD2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005526 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5527 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5528 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5529 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5530 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5531 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5532 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5533 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5534 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5535 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5536 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5537 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5538 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5539 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5540 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbach3a678af2012-01-23 21:53:26 +00005541
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00005542 // VLD3DUP
5543 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5544 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5545 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5546 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5547 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5548 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5549 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5550 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5551 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5552 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5553 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5554 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5555 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5556 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5557 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5558 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5559 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5560 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5561
Jim Grosbach3a678af2012-01-23 21:53:26 +00005562 // VLD3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005563 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5564 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5565 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5566 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5567 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5568 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5569 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5570 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5571 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5572 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5573 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5574 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5575 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5576 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5577 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachc387fc62012-01-23 23:20:46 +00005578
5579 // VLD3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005580 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5581 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5582 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5583 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5584 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5585 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5586 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5587 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5588 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5589 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5590 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5591 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5592 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5593 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5594 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5595 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5596 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5597 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005598
Jim Grosbache983a132012-01-24 18:37:25 +00005599 // VLD4LN
5600 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5601 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5602 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5603 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5604 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5605 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5606 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5607 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5608 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5609 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5610 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5611 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5612 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5613 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5614 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5615
Jim Grosbacha57a36a2012-01-25 00:01:08 +00005616 // VLD4DUP
5617 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5618 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5619 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5620 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5621 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5622 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5623 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5624 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5625 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5626 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5627 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5628 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5629 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5630 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5631 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5632 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5633 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5634 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5635
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005636 // VLD4
5637 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5638 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5639 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5640 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5641 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5642 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5643 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5644 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5645 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5646 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5647 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5648 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5649 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5650 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5651 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5652 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5653 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5654 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach7636bf62011-12-02 00:35:16 +00005655 }
5656}
5657
Jim Grosbach83ec8772011-11-10 23:42:14 +00005658bool ARMAsmParser::
Jim Grosbachf8fce712011-08-11 17:35:48 +00005659processInstruction(MCInst &Inst,
5660 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5661 switch (Inst.getOpcode()) {
Jim Grosbach0b4c6732012-01-18 22:46:46 +00005662 // Aliases for alternate PC+imm syntax of LDR instructions.
5663 case ARM::t2LDRpcrel:
5664 Inst.setOpcode(ARM::t2LDRpci);
5665 return true;
5666 case ARM::t2LDRBpcrel:
5667 Inst.setOpcode(ARM::t2LDRBpci);
5668 return true;
5669 case ARM::t2LDRHpcrel:
5670 Inst.setOpcode(ARM::t2LDRHpci);
5671 return true;
5672 case ARM::t2LDRSBpcrel:
5673 Inst.setOpcode(ARM::t2LDRSBpci);
5674 return true;
5675 case ARM::t2LDRSHpcrel:
5676 Inst.setOpcode(ARM::t2LDRSHpci);
5677 return true;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005678 // Handle NEON VST complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005679 case ARM::VST1LNdWB_register_Asm_8:
5680 case ARM::VST1LNdWB_register_Asm_16:
5681 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005682 MCInst TmpInst;
5683 // Shuffle the operands around so the lane index operand is in the
5684 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005685 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005686 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005687 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5688 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5689 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5690 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5691 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5692 TmpInst.addOperand(Inst.getOperand(1)); // lane
5693 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5694 TmpInst.addOperand(Inst.getOperand(6));
5695 Inst = TmpInst;
5696 return true;
5697 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005698
Jim Grosbach8b31f952012-01-23 19:39:08 +00005699 case ARM::VST2LNdWB_register_Asm_8:
5700 case ARM::VST2LNdWB_register_Asm_16:
5701 case ARM::VST2LNdWB_register_Asm_32:
5702 case ARM::VST2LNqWB_register_Asm_16:
5703 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005704 MCInst TmpInst;
5705 // Shuffle the operands around so the lane index operand is in the
5706 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005707 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005708 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005709 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5710 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5711 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5712 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5713 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005714 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5715 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005716 TmpInst.addOperand(Inst.getOperand(1)); // lane
5717 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5718 TmpInst.addOperand(Inst.getOperand(6));
5719 Inst = TmpInst;
5720 return true;
5721 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005722
5723 case ARM::VST3LNdWB_register_Asm_8:
5724 case ARM::VST3LNdWB_register_Asm_16:
5725 case ARM::VST3LNdWB_register_Asm_32:
5726 case ARM::VST3LNqWB_register_Asm_16:
5727 case ARM::VST3LNqWB_register_Asm_32: {
5728 MCInst TmpInst;
5729 // Shuffle the operands around so the lane index operand is in the
5730 // right place.
5731 unsigned Spacing;
5732 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5733 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5734 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5735 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5736 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5737 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5738 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5739 Spacing));
5740 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5741 Spacing * 2));
5742 TmpInst.addOperand(Inst.getOperand(1)); // lane
5743 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5744 TmpInst.addOperand(Inst.getOperand(6));
5745 Inst = TmpInst;
5746 return true;
5747 }
5748
Jim Grosbach88a54de2012-01-24 18:53:13 +00005749 case ARM::VST4LNdWB_register_Asm_8:
5750 case ARM::VST4LNdWB_register_Asm_16:
5751 case ARM::VST4LNdWB_register_Asm_32:
5752 case ARM::VST4LNqWB_register_Asm_16:
5753 case ARM::VST4LNqWB_register_Asm_32: {
5754 MCInst TmpInst;
5755 // Shuffle the operands around so the lane index operand is in the
5756 // right place.
5757 unsigned Spacing;
5758 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5759 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5760 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5761 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5762 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5763 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5764 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5765 Spacing));
5766 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5767 Spacing * 2));
5768 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5769 Spacing * 3));
5770 TmpInst.addOperand(Inst.getOperand(1)); // lane
5771 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5772 TmpInst.addOperand(Inst.getOperand(6));
5773 Inst = TmpInst;
5774 return true;
5775 }
5776
Jim Grosbach8b31f952012-01-23 19:39:08 +00005777 case ARM::VST1LNdWB_fixed_Asm_8:
5778 case ARM::VST1LNdWB_fixed_Asm_16:
5779 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005780 MCInst TmpInst;
5781 // Shuffle the operands around so the lane index operand is in the
5782 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005783 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005784 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005785 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5786 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5787 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5788 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5789 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5790 TmpInst.addOperand(Inst.getOperand(1)); // lane
5791 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5792 TmpInst.addOperand(Inst.getOperand(5));
5793 Inst = TmpInst;
5794 return true;
5795 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005796
Jim Grosbach8b31f952012-01-23 19:39:08 +00005797 case ARM::VST2LNdWB_fixed_Asm_8:
5798 case ARM::VST2LNdWB_fixed_Asm_16:
5799 case ARM::VST2LNdWB_fixed_Asm_32:
5800 case ARM::VST2LNqWB_fixed_Asm_16:
5801 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005802 MCInst TmpInst;
5803 // Shuffle the operands around so the lane index operand is in the
5804 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005805 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005806 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005807 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5808 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5809 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5810 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5811 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005812 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5813 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005814 TmpInst.addOperand(Inst.getOperand(1)); // lane
5815 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5816 TmpInst.addOperand(Inst.getOperand(5));
5817 Inst = TmpInst;
5818 return true;
5819 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005820
5821 case ARM::VST3LNdWB_fixed_Asm_8:
5822 case ARM::VST3LNdWB_fixed_Asm_16:
5823 case ARM::VST3LNdWB_fixed_Asm_32:
5824 case ARM::VST3LNqWB_fixed_Asm_16:
5825 case ARM::VST3LNqWB_fixed_Asm_32: {
5826 MCInst TmpInst;
5827 // Shuffle the operands around so the lane index operand is in the
5828 // right place.
5829 unsigned Spacing;
5830 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5831 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5832 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5833 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5834 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5835 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5836 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5837 Spacing));
5838 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5839 Spacing * 2));
5840 TmpInst.addOperand(Inst.getOperand(1)); // lane
5841 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5842 TmpInst.addOperand(Inst.getOperand(5));
5843 Inst = TmpInst;
5844 return true;
5845 }
5846
Jim Grosbach88a54de2012-01-24 18:53:13 +00005847 case ARM::VST4LNdWB_fixed_Asm_8:
5848 case ARM::VST4LNdWB_fixed_Asm_16:
5849 case ARM::VST4LNdWB_fixed_Asm_32:
5850 case ARM::VST4LNqWB_fixed_Asm_16:
5851 case ARM::VST4LNqWB_fixed_Asm_32: {
5852 MCInst TmpInst;
5853 // Shuffle the operands around so the lane index operand is in the
5854 // right place.
5855 unsigned Spacing;
5856 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5857 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5858 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5859 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5860 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5861 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5862 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5863 Spacing));
5864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5865 Spacing * 2));
5866 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5867 Spacing * 3));
5868 TmpInst.addOperand(Inst.getOperand(1)); // lane
5869 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5870 TmpInst.addOperand(Inst.getOperand(5));
5871 Inst = TmpInst;
5872 return true;
5873 }
5874
Jim Grosbach8b31f952012-01-23 19:39:08 +00005875 case ARM::VST1LNdAsm_8:
5876 case ARM::VST1LNdAsm_16:
5877 case ARM::VST1LNdAsm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005878 MCInst TmpInst;
5879 // Shuffle the operands around so the lane index operand is in the
5880 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005881 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005882 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005883 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5884 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5885 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5886 TmpInst.addOperand(Inst.getOperand(1)); // lane
5887 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5888 TmpInst.addOperand(Inst.getOperand(5));
5889 Inst = TmpInst;
5890 return true;
5891 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005892
Jim Grosbach8b31f952012-01-23 19:39:08 +00005893 case ARM::VST2LNdAsm_8:
5894 case ARM::VST2LNdAsm_16:
5895 case ARM::VST2LNdAsm_32:
5896 case ARM::VST2LNqAsm_16:
5897 case ARM::VST2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005898 MCInst TmpInst;
5899 // Shuffle the operands around so the lane index operand is in the
5900 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005901 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005902 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005903 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5904 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5905 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005906 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5907 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005908 TmpInst.addOperand(Inst.getOperand(1)); // lane
5909 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5910 TmpInst.addOperand(Inst.getOperand(5));
5911 Inst = TmpInst;
5912 return true;
5913 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005914
5915 case ARM::VST3LNdAsm_8:
5916 case ARM::VST3LNdAsm_16:
5917 case ARM::VST3LNdAsm_32:
5918 case ARM::VST3LNqAsm_16:
5919 case ARM::VST3LNqAsm_32: {
5920 MCInst TmpInst;
5921 // Shuffle the operands around so the lane index operand is in the
5922 // right place.
5923 unsigned Spacing;
5924 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5925 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5926 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5927 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5928 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5929 Spacing));
5930 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5931 Spacing * 2));
5932 TmpInst.addOperand(Inst.getOperand(1)); // lane
5933 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5934 TmpInst.addOperand(Inst.getOperand(5));
5935 Inst = TmpInst;
5936 return true;
5937 }
5938
Jim Grosbach88a54de2012-01-24 18:53:13 +00005939 case ARM::VST4LNdAsm_8:
5940 case ARM::VST4LNdAsm_16:
5941 case ARM::VST4LNdAsm_32:
5942 case ARM::VST4LNqAsm_16:
5943 case ARM::VST4LNqAsm_32: {
5944 MCInst TmpInst;
5945 // Shuffle the operands around so the lane index operand is in the
5946 // right place.
5947 unsigned Spacing;
5948 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5949 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5950 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5951 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5952 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5953 Spacing));
5954 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5955 Spacing * 2));
5956 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5957 Spacing * 3));
5958 TmpInst.addOperand(Inst.getOperand(1)); // lane
5959 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5960 TmpInst.addOperand(Inst.getOperand(5));
5961 Inst = TmpInst;
5962 return true;
5963 }
5964
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005965 // Handle NEON VLD complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005966 case ARM::VLD1LNdWB_register_Asm_8:
5967 case ARM::VLD1LNdWB_register_Asm_16:
5968 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005969 MCInst TmpInst;
5970 // Shuffle the operands around so the lane index operand is in the
5971 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005972 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005973 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005974 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5975 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5976 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5977 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5978 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5979 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5980 TmpInst.addOperand(Inst.getOperand(1)); // lane
5981 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5982 TmpInst.addOperand(Inst.getOperand(6));
5983 Inst = TmpInst;
5984 return true;
5985 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005986
Jim Grosbach8b31f952012-01-23 19:39:08 +00005987 case ARM::VLD2LNdWB_register_Asm_8:
5988 case ARM::VLD2LNdWB_register_Asm_16:
5989 case ARM::VLD2LNdWB_register_Asm_32:
5990 case ARM::VLD2LNqWB_register_Asm_16:
5991 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005992 MCInst TmpInst;
5993 // Shuffle the operands around so the lane index operand is in the
5994 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005995 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005996 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005997 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005998 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5999 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006000 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6001 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6002 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6003 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6004 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6006 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006007 TmpInst.addOperand(Inst.getOperand(1)); // lane
6008 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6009 TmpInst.addOperand(Inst.getOperand(6));
6010 Inst = TmpInst;
6011 return true;
6012 }
6013
Jim Grosbach3a678af2012-01-23 21:53:26 +00006014 case ARM::VLD3LNdWB_register_Asm_8:
6015 case ARM::VLD3LNdWB_register_Asm_16:
6016 case ARM::VLD3LNdWB_register_Asm_32:
6017 case ARM::VLD3LNqWB_register_Asm_16:
6018 case ARM::VLD3LNqWB_register_Asm_32: {
6019 MCInst TmpInst;
6020 // Shuffle the operands around so the lane index operand is in the
6021 // right place.
6022 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006023 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006024 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6025 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6026 Spacing));
6027 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006028 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006029 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6030 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6031 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6032 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6033 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6034 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6035 Spacing));
6036 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006037 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006038 TmpInst.addOperand(Inst.getOperand(1)); // lane
6039 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6040 TmpInst.addOperand(Inst.getOperand(6));
6041 Inst = TmpInst;
6042 return true;
6043 }
6044
Jim Grosbache983a132012-01-24 18:37:25 +00006045 case ARM::VLD4LNdWB_register_Asm_8:
6046 case ARM::VLD4LNdWB_register_Asm_16:
6047 case ARM::VLD4LNdWB_register_Asm_32:
6048 case ARM::VLD4LNqWB_register_Asm_16:
6049 case ARM::VLD4LNqWB_register_Asm_32: {
6050 MCInst TmpInst;
6051 // Shuffle the operands around so the lane index operand is in the
6052 // right place.
6053 unsigned Spacing;
6054 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6055 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6056 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6057 Spacing));
6058 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6059 Spacing * 2));
6060 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6061 Spacing * 3));
6062 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6063 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6064 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6065 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6066 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6068 Spacing));
6069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6070 Spacing * 2));
6071 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6072 Spacing * 3));
6073 TmpInst.addOperand(Inst.getOperand(1)); // lane
6074 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6075 TmpInst.addOperand(Inst.getOperand(6));
6076 Inst = TmpInst;
6077 return true;
6078 }
6079
Jim Grosbach8b31f952012-01-23 19:39:08 +00006080 case ARM::VLD1LNdWB_fixed_Asm_8:
6081 case ARM::VLD1LNdWB_fixed_Asm_16:
6082 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00006083 MCInst TmpInst;
6084 // Shuffle the operands around so the lane index operand is in the
6085 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006086 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006087 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00006088 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6089 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6090 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6091 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6092 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6093 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6094 TmpInst.addOperand(Inst.getOperand(1)); // lane
6095 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6096 TmpInst.addOperand(Inst.getOperand(5));
6097 Inst = TmpInst;
6098 return true;
6099 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006100
Jim Grosbach8b31f952012-01-23 19:39:08 +00006101 case ARM::VLD2LNdWB_fixed_Asm_8:
6102 case ARM::VLD2LNdWB_fixed_Asm_16:
6103 case ARM::VLD2LNdWB_fixed_Asm_32:
6104 case ARM::VLD2LNqWB_fixed_Asm_16:
6105 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006106 MCInst TmpInst;
6107 // Shuffle the operands around so the lane index operand is in the
6108 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006109 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006110 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006111 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6113 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006114 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6115 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6116 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6117 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6118 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006119 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6120 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006121 TmpInst.addOperand(Inst.getOperand(1)); // lane
6122 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6123 TmpInst.addOperand(Inst.getOperand(5));
6124 Inst = TmpInst;
6125 return true;
6126 }
6127
Jim Grosbach3a678af2012-01-23 21:53:26 +00006128 case ARM::VLD3LNdWB_fixed_Asm_8:
6129 case ARM::VLD3LNdWB_fixed_Asm_16:
6130 case ARM::VLD3LNdWB_fixed_Asm_32:
6131 case ARM::VLD3LNqWB_fixed_Asm_16:
6132 case ARM::VLD3LNqWB_fixed_Asm_32: {
6133 MCInst TmpInst;
6134 // Shuffle the operands around so the lane index operand is in the
6135 // right place.
6136 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006137 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006138 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6139 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6140 Spacing));
6141 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006142 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006143 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6144 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6145 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6146 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6147 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6148 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6149 Spacing));
6150 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006151 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006152 TmpInst.addOperand(Inst.getOperand(1)); // lane
6153 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6154 TmpInst.addOperand(Inst.getOperand(5));
6155 Inst = TmpInst;
6156 return true;
6157 }
6158
Jim Grosbache983a132012-01-24 18:37:25 +00006159 case ARM::VLD4LNdWB_fixed_Asm_8:
6160 case ARM::VLD4LNdWB_fixed_Asm_16:
6161 case ARM::VLD4LNdWB_fixed_Asm_32:
6162 case ARM::VLD4LNqWB_fixed_Asm_16:
6163 case ARM::VLD4LNqWB_fixed_Asm_32: {
6164 MCInst TmpInst;
6165 // Shuffle the operands around so the lane index operand is in the
6166 // right place.
6167 unsigned Spacing;
6168 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6169 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6171 Spacing));
6172 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6173 Spacing * 2));
6174 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6175 Spacing * 3));
6176 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6177 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6178 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6179 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6180 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6181 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6182 Spacing));
6183 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6184 Spacing * 2));
6185 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6186 Spacing * 3));
6187 TmpInst.addOperand(Inst.getOperand(1)); // lane
6188 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6189 TmpInst.addOperand(Inst.getOperand(5));
6190 Inst = TmpInst;
6191 return true;
6192 }
6193
Jim Grosbach8b31f952012-01-23 19:39:08 +00006194 case ARM::VLD1LNdAsm_8:
6195 case ARM::VLD1LNdAsm_16:
6196 case ARM::VLD1LNdAsm_32: {
Jim Grosbach7636bf62011-12-02 00:35:16 +00006197 MCInst TmpInst;
6198 // Shuffle the operands around so the lane index operand is in the
6199 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006200 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006201 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach7636bf62011-12-02 00:35:16 +00006202 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6203 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6204 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6205 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6206 TmpInst.addOperand(Inst.getOperand(1)); // lane
6207 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6208 TmpInst.addOperand(Inst.getOperand(5));
6209 Inst = TmpInst;
6210 return true;
6211 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006212
Jim Grosbach8b31f952012-01-23 19:39:08 +00006213 case ARM::VLD2LNdAsm_8:
6214 case ARM::VLD2LNdAsm_16:
6215 case ARM::VLD2LNdAsm_32:
6216 case ARM::VLD2LNqAsm_16:
6217 case ARM::VLD2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006218 MCInst TmpInst;
6219 // Shuffle the operands around so the lane index operand is in the
6220 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006221 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006222 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006223 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006224 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6225 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006226 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6227 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6228 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006229 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6230 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006231 TmpInst.addOperand(Inst.getOperand(1)); // lane
6232 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6233 TmpInst.addOperand(Inst.getOperand(5));
6234 Inst = TmpInst;
6235 return true;
6236 }
Jim Grosbach3a678af2012-01-23 21:53:26 +00006237
6238 case ARM::VLD3LNdAsm_8:
6239 case ARM::VLD3LNdAsm_16:
6240 case ARM::VLD3LNdAsm_32:
6241 case ARM::VLD3LNqAsm_16:
6242 case ARM::VLD3LNqAsm_32: {
6243 MCInst TmpInst;
6244 // Shuffle the operands around so the lane index operand is in the
6245 // right place.
6246 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006247 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006248 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6249 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6250 Spacing));
6251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006252 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006253 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6254 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6255 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6257 Spacing));
6258 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006259 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006260 TmpInst.addOperand(Inst.getOperand(1)); // lane
6261 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6262 TmpInst.addOperand(Inst.getOperand(5));
6263 Inst = TmpInst;
6264 return true;
6265 }
6266
Jim Grosbache983a132012-01-24 18:37:25 +00006267 case ARM::VLD4LNdAsm_8:
6268 case ARM::VLD4LNdAsm_16:
6269 case ARM::VLD4LNdAsm_32:
6270 case ARM::VLD4LNqAsm_16:
6271 case ARM::VLD4LNqAsm_32: {
6272 MCInst TmpInst;
6273 // Shuffle the operands around so the lane index operand is in the
6274 // right place.
6275 unsigned Spacing;
6276 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6277 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6278 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6279 Spacing));
6280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6281 Spacing * 2));
6282 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6283 Spacing * 3));
6284 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6285 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6286 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6287 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6288 Spacing));
6289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6290 Spacing * 2));
6291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6292 Spacing * 3));
6293 TmpInst.addOperand(Inst.getOperand(1)); // lane
6294 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6295 TmpInst.addOperand(Inst.getOperand(5));
6296 Inst = TmpInst;
6297 return true;
6298 }
6299
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00006300 // VLD3DUP single 3-element structure to all lanes instructions.
6301 case ARM::VLD3DUPdAsm_8:
6302 case ARM::VLD3DUPdAsm_16:
6303 case ARM::VLD3DUPdAsm_32:
6304 case ARM::VLD3DUPqAsm_8:
6305 case ARM::VLD3DUPqAsm_16:
6306 case ARM::VLD3DUPqAsm_32: {
6307 MCInst TmpInst;
6308 unsigned Spacing;
6309 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6310 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6311 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6312 Spacing));
6313 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6314 Spacing * 2));
6315 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6316 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6317 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6318 TmpInst.addOperand(Inst.getOperand(4));
6319 Inst = TmpInst;
6320 return true;
6321 }
6322
6323 case ARM::VLD3DUPdWB_fixed_Asm_8:
6324 case ARM::VLD3DUPdWB_fixed_Asm_16:
6325 case ARM::VLD3DUPdWB_fixed_Asm_32:
6326 case ARM::VLD3DUPqWB_fixed_Asm_8:
6327 case ARM::VLD3DUPqWB_fixed_Asm_16:
6328 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6329 MCInst TmpInst;
6330 unsigned Spacing;
6331 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6332 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6334 Spacing));
6335 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6336 Spacing * 2));
6337 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6338 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6339 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6340 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6341 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6342 TmpInst.addOperand(Inst.getOperand(4));
6343 Inst = TmpInst;
6344 return true;
6345 }
6346
6347 case ARM::VLD3DUPdWB_register_Asm_8:
6348 case ARM::VLD3DUPdWB_register_Asm_16:
6349 case ARM::VLD3DUPdWB_register_Asm_32:
6350 case ARM::VLD3DUPqWB_register_Asm_8:
6351 case ARM::VLD3DUPqWB_register_Asm_16:
6352 case ARM::VLD3DUPqWB_register_Asm_32: {
6353 MCInst TmpInst;
6354 unsigned Spacing;
6355 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6356 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6357 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6358 Spacing));
6359 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6360 Spacing * 2));
6361 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6362 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6363 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6364 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6365 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6366 TmpInst.addOperand(Inst.getOperand(5));
6367 Inst = TmpInst;
6368 return true;
6369 }
6370
Jim Grosbachc387fc62012-01-23 23:20:46 +00006371 // VLD3 multiple 3-element structure instructions.
6372 case ARM::VLD3dAsm_8:
6373 case ARM::VLD3dAsm_16:
6374 case ARM::VLD3dAsm_32:
6375 case ARM::VLD3qAsm_8:
6376 case ARM::VLD3qAsm_16:
6377 case ARM::VLD3qAsm_32: {
6378 MCInst TmpInst;
6379 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006380 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006381 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6382 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6383 Spacing));
6384 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6385 Spacing * 2));
6386 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6387 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6388 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6389 TmpInst.addOperand(Inst.getOperand(4));
6390 Inst = TmpInst;
6391 return true;
6392 }
6393
6394 case ARM::VLD3dWB_fixed_Asm_8:
6395 case ARM::VLD3dWB_fixed_Asm_16:
6396 case ARM::VLD3dWB_fixed_Asm_32:
6397 case ARM::VLD3qWB_fixed_Asm_8:
6398 case ARM::VLD3qWB_fixed_Asm_16:
6399 case ARM::VLD3qWB_fixed_Asm_32: {
6400 MCInst TmpInst;
6401 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006402 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006403 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6405 Spacing));
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6407 Spacing * 2));
6408 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6409 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6410 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6411 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6412 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6413 TmpInst.addOperand(Inst.getOperand(4));
6414 Inst = TmpInst;
6415 return true;
6416 }
6417
6418 case ARM::VLD3dWB_register_Asm_8:
6419 case ARM::VLD3dWB_register_Asm_16:
6420 case ARM::VLD3dWB_register_Asm_32:
6421 case ARM::VLD3qWB_register_Asm_8:
6422 case ARM::VLD3qWB_register_Asm_16:
6423 case ARM::VLD3qWB_register_Asm_32: {
6424 MCInst TmpInst;
6425 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006426 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006427 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6429 Spacing));
6430 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6431 Spacing * 2));
6432 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6433 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6434 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6435 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6436 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6437 TmpInst.addOperand(Inst.getOperand(5));
6438 Inst = TmpInst;
6439 return true;
6440 }
6441
Jim Grosbacha57a36a2012-01-25 00:01:08 +00006442 // VLD4DUP single 3-element structure to all lanes instructions.
6443 case ARM::VLD4DUPdAsm_8:
6444 case ARM::VLD4DUPdAsm_16:
6445 case ARM::VLD4DUPdAsm_32:
6446 case ARM::VLD4DUPqAsm_8:
6447 case ARM::VLD4DUPqAsm_16:
6448 case ARM::VLD4DUPqAsm_32: {
6449 MCInst TmpInst;
6450 unsigned Spacing;
6451 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6452 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6453 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6454 Spacing));
6455 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6456 Spacing * 2));
6457 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6458 Spacing * 3));
6459 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6460 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6461 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6462 TmpInst.addOperand(Inst.getOperand(4));
6463 Inst = TmpInst;
6464 return true;
6465 }
6466
6467 case ARM::VLD4DUPdWB_fixed_Asm_8:
6468 case ARM::VLD4DUPdWB_fixed_Asm_16:
6469 case ARM::VLD4DUPdWB_fixed_Asm_32:
6470 case ARM::VLD4DUPqWB_fixed_Asm_8:
6471 case ARM::VLD4DUPqWB_fixed_Asm_16:
6472 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6473 MCInst TmpInst;
6474 unsigned Spacing;
6475 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6476 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6477 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6478 Spacing));
6479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6480 Spacing * 2));
6481 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6482 Spacing * 3));
6483 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6484 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6485 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6486 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6487 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6488 TmpInst.addOperand(Inst.getOperand(4));
6489 Inst = TmpInst;
6490 return true;
6491 }
6492
6493 case ARM::VLD4DUPdWB_register_Asm_8:
6494 case ARM::VLD4DUPdWB_register_Asm_16:
6495 case ARM::VLD4DUPdWB_register_Asm_32:
6496 case ARM::VLD4DUPqWB_register_Asm_8:
6497 case ARM::VLD4DUPqWB_register_Asm_16:
6498 case ARM::VLD4DUPqWB_register_Asm_32: {
6499 MCInst TmpInst;
6500 unsigned Spacing;
6501 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6502 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6504 Spacing));
6505 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6506 Spacing * 2));
6507 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6508 Spacing * 3));
6509 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6510 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6511 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6512 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6513 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6514 TmpInst.addOperand(Inst.getOperand(5));
6515 Inst = TmpInst;
6516 return true;
6517 }
6518
6519 // VLD4 multiple 4-element structure instructions.
Jim Grosbach8abe7e32012-01-24 00:43:17 +00006520 case ARM::VLD4dAsm_8:
6521 case ARM::VLD4dAsm_16:
6522 case ARM::VLD4dAsm_32:
6523 case ARM::VLD4qAsm_8:
6524 case ARM::VLD4qAsm_16:
6525 case ARM::VLD4qAsm_32: {
6526 MCInst TmpInst;
6527 unsigned Spacing;
6528 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6529 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6531 Spacing));
6532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6533 Spacing * 2));
6534 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6535 Spacing * 3));
6536 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6537 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6538 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6539 TmpInst.addOperand(Inst.getOperand(4));
6540 Inst = TmpInst;
6541 return true;
6542 }
6543
6544 case ARM::VLD4dWB_fixed_Asm_8:
6545 case ARM::VLD4dWB_fixed_Asm_16:
6546 case ARM::VLD4dWB_fixed_Asm_32:
6547 case ARM::VLD4qWB_fixed_Asm_8:
6548 case ARM::VLD4qWB_fixed_Asm_16:
6549 case ARM::VLD4qWB_fixed_Asm_32: {
6550 MCInst TmpInst;
6551 unsigned Spacing;
6552 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6553 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6555 Spacing));
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6557 Spacing * 2));
6558 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6559 Spacing * 3));
6560 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6561 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6562 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6563 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6564 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6565 TmpInst.addOperand(Inst.getOperand(4));
6566 Inst = TmpInst;
6567 return true;
6568 }
6569
6570 case ARM::VLD4dWB_register_Asm_8:
6571 case ARM::VLD4dWB_register_Asm_16:
6572 case ARM::VLD4dWB_register_Asm_32:
6573 case ARM::VLD4qWB_register_Asm_8:
6574 case ARM::VLD4qWB_register_Asm_16:
6575 case ARM::VLD4qWB_register_Asm_32: {
6576 MCInst TmpInst;
6577 unsigned Spacing;
6578 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6579 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6581 Spacing));
6582 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6583 Spacing * 2));
6584 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6585 Spacing * 3));
6586 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6587 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6588 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6589 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6590 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6591 TmpInst.addOperand(Inst.getOperand(5));
6592 Inst = TmpInst;
6593 return true;
6594 }
6595
Jim Grosbachd7433e22012-01-23 23:45:44 +00006596 // VST3 multiple 3-element structure instructions.
6597 case ARM::VST3dAsm_8:
6598 case ARM::VST3dAsm_16:
6599 case ARM::VST3dAsm_32:
6600 case ARM::VST3qAsm_8:
6601 case ARM::VST3qAsm_16:
6602 case ARM::VST3qAsm_32: {
6603 MCInst TmpInst;
6604 unsigned Spacing;
6605 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6606 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6607 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6608 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6609 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6610 Spacing));
6611 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6612 Spacing * 2));
6613 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6614 TmpInst.addOperand(Inst.getOperand(4));
6615 Inst = TmpInst;
6616 return true;
6617 }
6618
6619 case ARM::VST3dWB_fixed_Asm_8:
6620 case ARM::VST3dWB_fixed_Asm_16:
6621 case ARM::VST3dWB_fixed_Asm_32:
6622 case ARM::VST3qWB_fixed_Asm_8:
6623 case ARM::VST3qWB_fixed_Asm_16:
6624 case ARM::VST3qWB_fixed_Asm_32: {
6625 MCInst TmpInst;
6626 unsigned Spacing;
6627 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6628 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6629 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6630 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6631 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6632 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6633 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6634 Spacing));
6635 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6636 Spacing * 2));
6637 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6638 TmpInst.addOperand(Inst.getOperand(4));
6639 Inst = TmpInst;
6640 return true;
6641 }
6642
6643 case ARM::VST3dWB_register_Asm_8:
6644 case ARM::VST3dWB_register_Asm_16:
6645 case ARM::VST3dWB_register_Asm_32:
6646 case ARM::VST3qWB_register_Asm_8:
6647 case ARM::VST3qWB_register_Asm_16:
6648 case ARM::VST3qWB_register_Asm_32: {
6649 MCInst TmpInst;
6650 unsigned Spacing;
6651 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6652 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6653 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6654 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6655 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6656 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6658 Spacing));
6659 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6660 Spacing * 2));
6661 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6662 TmpInst.addOperand(Inst.getOperand(5));
6663 Inst = TmpInst;
6664 return true;
6665 }
6666
Jim Grosbach539aab72012-01-24 00:58:13 +00006667 // VST4 multiple 3-element structure instructions.
6668 case ARM::VST4dAsm_8:
6669 case ARM::VST4dAsm_16:
6670 case ARM::VST4dAsm_32:
6671 case ARM::VST4qAsm_8:
6672 case ARM::VST4qAsm_16:
6673 case ARM::VST4qAsm_32: {
6674 MCInst TmpInst;
6675 unsigned Spacing;
6676 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6677 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6678 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6679 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6680 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6681 Spacing));
6682 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6683 Spacing * 2));
6684 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6685 Spacing * 3));
6686 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6687 TmpInst.addOperand(Inst.getOperand(4));
6688 Inst = TmpInst;
6689 return true;
6690 }
6691
6692 case ARM::VST4dWB_fixed_Asm_8:
6693 case ARM::VST4dWB_fixed_Asm_16:
6694 case ARM::VST4dWB_fixed_Asm_32:
6695 case ARM::VST4qWB_fixed_Asm_8:
6696 case ARM::VST4qWB_fixed_Asm_16:
6697 case ARM::VST4qWB_fixed_Asm_32: {
6698 MCInst TmpInst;
6699 unsigned Spacing;
6700 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6701 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6702 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6703 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6704 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6705 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6706 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6707 Spacing));
6708 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6709 Spacing * 2));
6710 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6711 Spacing * 3));
6712 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6713 TmpInst.addOperand(Inst.getOperand(4));
6714 Inst = TmpInst;
6715 return true;
6716 }
6717
6718 case ARM::VST4dWB_register_Asm_8:
6719 case ARM::VST4dWB_register_Asm_16:
6720 case ARM::VST4dWB_register_Asm_32:
6721 case ARM::VST4qWB_register_Asm_8:
6722 case ARM::VST4qWB_register_Asm_16:
6723 case ARM::VST4qWB_register_Asm_32: {
6724 MCInst TmpInst;
6725 unsigned Spacing;
6726 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6727 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6728 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6729 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6730 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6731 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6733 Spacing));
6734 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6735 Spacing * 2));
6736 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6737 Spacing * 3));
6738 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6739 TmpInst.addOperand(Inst.getOperand(5));
6740 Inst = TmpInst;
6741 return true;
6742 }
6743
Jim Grosbacha5378eb2012-04-11 00:15:16 +00006744 // Handle encoding choice for the shift-immediate instructions.
6745 case ARM::t2LSLri:
6746 case ARM::t2LSRri:
6747 case ARM::t2ASRri: {
6748 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6749 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6750 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6751 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6752 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6753 unsigned NewOpc;
6754 switch (Inst.getOpcode()) {
6755 default: llvm_unreachable("unexpected opcode");
6756 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6757 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6758 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6759 }
6760 // The Thumb1 operands aren't in the same order. Awesome, eh?
6761 MCInst TmpInst;
6762 TmpInst.setOpcode(NewOpc);
6763 TmpInst.addOperand(Inst.getOperand(0));
6764 TmpInst.addOperand(Inst.getOperand(5));
6765 TmpInst.addOperand(Inst.getOperand(1));
6766 TmpInst.addOperand(Inst.getOperand(2));
6767 TmpInst.addOperand(Inst.getOperand(3));
6768 TmpInst.addOperand(Inst.getOperand(4));
6769 Inst = TmpInst;
6770 return true;
6771 }
6772 return false;
6773 }
6774
Jim Grosbach863d2af2011-12-13 22:45:11 +00006775 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00006776 case ARM::t2MOVsr:
6777 case ARM::t2MOVSsr: {
6778 // Which instruction to expand to depends on the CCOut operand and
6779 // whether we're in an IT block if the register operands are low
6780 // registers.
6781 bool isNarrow = false;
6782 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6783 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6784 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6785 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6786 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6787 isNarrow = true;
6788 MCInst TmpInst;
6789 unsigned newOpc;
6790 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6791 default: llvm_unreachable("unexpected opcode!");
6792 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6793 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6794 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6795 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6796 }
6797 TmpInst.setOpcode(newOpc);
6798 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6799 if (isNarrow)
6800 TmpInst.addOperand(MCOperand::CreateReg(
6801 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6802 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6803 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6804 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6805 TmpInst.addOperand(Inst.getOperand(5));
6806 if (!isNarrow)
6807 TmpInst.addOperand(MCOperand::CreateReg(
6808 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6809 Inst = TmpInst;
6810 return true;
6811 }
Jim Grosbach863d2af2011-12-13 22:45:11 +00006812 case ARM::t2MOVsi:
6813 case ARM::t2MOVSsi: {
6814 // Which instruction to expand to depends on the CCOut operand and
6815 // whether we're in an IT block if the register operands are low
6816 // registers.
6817 bool isNarrow = false;
6818 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6819 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6820 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6821 isNarrow = true;
6822 MCInst TmpInst;
6823 unsigned newOpc;
6824 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6825 default: llvm_unreachable("unexpected opcode!");
6826 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6827 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6828 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6829 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach520dc782011-12-21 21:04:19 +00006830 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006831 }
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006832 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6833 if (Amount == 32) Amount = 0;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006834 TmpInst.setOpcode(newOpc);
6835 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6836 if (isNarrow)
6837 TmpInst.addOperand(MCOperand::CreateReg(
6838 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6839 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach520dc782011-12-21 21:04:19 +00006840 if (newOpc != ARM::t2RRX)
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006841 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach863d2af2011-12-13 22:45:11 +00006842 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6843 TmpInst.addOperand(Inst.getOperand(4));
6844 if (!isNarrow)
6845 TmpInst.addOperand(MCOperand::CreateReg(
6846 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6847 Inst = TmpInst;
6848 return true;
6849 }
6850 // Handle the ARM mode MOV complex aliases.
Jim Grosbach23f22072011-11-16 18:31:45 +00006851 case ARM::ASRr:
6852 case ARM::LSRr:
6853 case ARM::LSLr:
6854 case ARM::RORr: {
6855 ARM_AM::ShiftOpc ShiftTy;
6856 switch(Inst.getOpcode()) {
6857 default: llvm_unreachable("unexpected opcode!");
6858 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6859 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6860 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6861 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6862 }
Jim Grosbach23f22072011-11-16 18:31:45 +00006863 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6864 MCInst TmpInst;
6865 TmpInst.setOpcode(ARM::MOVsr);
6866 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6867 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6868 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6869 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6870 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6871 TmpInst.addOperand(Inst.getOperand(4));
6872 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6873 Inst = TmpInst;
6874 return true;
6875 }
Jim Grosbachee10ff82011-11-10 19:18:01 +00006876 case ARM::ASRi:
6877 case ARM::LSRi:
6878 case ARM::LSLi:
6879 case ARM::RORi: {
6880 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006881 switch(Inst.getOpcode()) {
6882 default: llvm_unreachable("unexpected opcode!");
6883 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6884 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6885 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6886 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6887 }
6888 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach48b368b2011-11-16 19:05:59 +00006889 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachee10ff82011-11-10 19:18:01 +00006890 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonb56e4112012-04-25 18:00:18 +00006891 // A shift by 32 should be encoded as 0 when permitted
6892 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6893 Amt = 0;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006894 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006895 MCInst TmpInst;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006896 TmpInst.setOpcode(Opc);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006897 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6898 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachee10ff82011-11-10 19:18:01 +00006899 if (Opc == ARM::MOVsi)
6900 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach71810ab2011-11-10 16:44:55 +00006901 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6902 TmpInst.addOperand(Inst.getOperand(4));
6903 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6904 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006905 return true;
Jim Grosbach71810ab2011-11-10 16:44:55 +00006906 }
Jim Grosbach48b368b2011-11-16 19:05:59 +00006907 case ARM::RRXi: {
6908 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6909 MCInst TmpInst;
6910 TmpInst.setOpcode(ARM::MOVsi);
6911 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6912 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6913 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6914 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6915 TmpInst.addOperand(Inst.getOperand(3));
6916 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6917 Inst = TmpInst;
6918 return true;
6919 }
Jim Grosbach0352b462011-11-10 23:58:34 +00006920 case ARM::t2LDMIA_UPD: {
6921 // If this is a load of a single register, then we should use
6922 // a post-indexed LDR instruction instead, per the ARM ARM.
6923 if (Inst.getNumOperands() != 5)
6924 return false;
6925 MCInst TmpInst;
6926 TmpInst.setOpcode(ARM::t2LDR_POST);
6927 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6928 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6929 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6930 TmpInst.addOperand(MCOperand::CreateImm(4));
6931 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6932 TmpInst.addOperand(Inst.getOperand(3));
6933 Inst = TmpInst;
6934 return true;
6935 }
6936 case ARM::t2STMDB_UPD: {
6937 // If this is a store of a single register, then we should use
6938 // a pre-indexed STR instruction instead, per the ARM ARM.
6939 if (Inst.getNumOperands() != 5)
6940 return false;
6941 MCInst TmpInst;
6942 TmpInst.setOpcode(ARM::t2STR_PRE);
6943 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6944 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6945 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6946 TmpInst.addOperand(MCOperand::CreateImm(-4));
6947 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6948 TmpInst.addOperand(Inst.getOperand(3));
6949 Inst = TmpInst;
6950 return true;
6951 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00006952 case ARM::LDMIA_UPD:
6953 // If this is a load of a single register via a 'pop', then we should use
6954 // a post-indexed LDR instruction instead, per the ARM ARM.
6955 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6956 Inst.getNumOperands() == 5) {
6957 MCInst TmpInst;
6958 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6959 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6960 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6961 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6962 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6963 TmpInst.addOperand(MCOperand::CreateImm(4));
6964 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6965 TmpInst.addOperand(Inst.getOperand(3));
6966 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006967 return true;
Jim Grosbachf8fce712011-08-11 17:35:48 +00006968 }
6969 break;
Jim Grosbachf6713912011-08-11 18:07:11 +00006970 case ARM::STMDB_UPD:
6971 // If this is a store of a single register via a 'push', then we should use
6972 // a pre-indexed STR instruction instead, per the ARM ARM.
6973 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6974 Inst.getNumOperands() == 5) {
6975 MCInst TmpInst;
6976 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6977 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6978 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6979 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6980 TmpInst.addOperand(MCOperand::CreateImm(-4));
6981 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6982 TmpInst.addOperand(Inst.getOperand(3));
6983 Inst = TmpInst;
6984 }
6985 break;
Jim Grosbachda847862011-12-05 21:06:26 +00006986 case ARM::t2ADDri12:
6987 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6988 // mnemonic was used (not "addw"), encoding T3 is preferred.
6989 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6990 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6991 break;
6992 Inst.setOpcode(ARM::t2ADDri);
6993 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6994 break;
6995 case ARM::t2SUBri12:
6996 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6997 // mnemonic was used (not "subw"), encoding T3 is preferred.
6998 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6999 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7000 break;
7001 Inst.setOpcode(ARM::t2SUBri);
7002 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7003 break;
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007004 case ARM::tADDi8:
Jim Grosbach0f3abd82011-08-31 17:07:33 +00007005 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7006 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7007 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7008 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007009 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007010 Inst.setOpcode(ARM::tADDi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007011 return true;
7012 }
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007013 break;
Jim Grosbachf67e8552011-09-16 22:58:42 +00007014 case ARM::tSUBi8:
7015 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7016 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7017 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7018 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007019 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachf67e8552011-09-16 22:58:42 +00007020 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007021 return true;
7022 }
Jim Grosbachf67e8552011-09-16 22:58:42 +00007023 break;
Jim Grosbach2d30d942012-03-30 17:20:40 +00007024 case ARM::t2ADDri:
7025 case ARM::t2SUBri: {
7026 // If the destination and first source operand are the same, and
7027 // the flags are compatible with the current IT status, use encoding T2
7028 // instead of T3. For compatibility with the system 'as'. Make sure the
7029 // wide encoding wasn't explicit.
7030 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach8f1148b2012-03-30 18:39:43 +00007031 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbach2d30d942012-03-30 17:20:40 +00007032 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7033 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7034 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7035 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7036 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7037 break;
7038 MCInst TmpInst;
7039 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7040 ARM::tADDi8 : ARM::tSUBi8);
7041 TmpInst.addOperand(Inst.getOperand(0));
7042 TmpInst.addOperand(Inst.getOperand(5));
7043 TmpInst.addOperand(Inst.getOperand(0));
7044 TmpInst.addOperand(Inst.getOperand(2));
7045 TmpInst.addOperand(Inst.getOperand(3));
7046 TmpInst.addOperand(Inst.getOperand(4));
7047 Inst = TmpInst;
7048 return true;
7049 }
Jim Grosbach927b9df2011-12-05 22:16:39 +00007050 case ARM::t2ADDrr: {
7051 // If the destination and first source operand are the same, and
7052 // there's no setting of the flags, use encoding T2 instead of T3.
7053 // Note that this is only for ADD, not SUB. This mirrors the system
7054 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7055 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7056 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbach713c7022011-12-05 22:27:04 +00007057 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7058 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbach927b9df2011-12-05 22:16:39 +00007059 break;
7060 MCInst TmpInst;
7061 TmpInst.setOpcode(ARM::tADDhirr);
7062 TmpInst.addOperand(Inst.getOperand(0));
7063 TmpInst.addOperand(Inst.getOperand(0));
7064 TmpInst.addOperand(Inst.getOperand(2));
7065 TmpInst.addOperand(Inst.getOperand(3));
7066 TmpInst.addOperand(Inst.getOperand(4));
7067 Inst = TmpInst;
7068 return true;
7069 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00007070 case ARM::tADDrSP: {
7071 // If the non-SP source operand and the destination operand are not the
7072 // same, we need to use the 32-bit encoding if it's available.
7073 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7074 Inst.setOpcode(ARM::t2ADDrr);
7075 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7076 return true;
7077 }
7078 break;
7079 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007080 case ARM::tB:
7081 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007082 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007083 Inst.setOpcode(ARM::tBcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007084 return true;
7085 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007086 break;
7087 case ARM::t2B:
7088 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007089 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007090 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007091 return true;
7092 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007093 break;
Jim Grosbachc0755102011-08-31 21:17:31 +00007094 case ARM::t2Bcc:
Jim Grosbacha1109882011-09-02 23:22:08 +00007095 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007096 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbachc0755102011-08-31 21:17:31 +00007097 Inst.setOpcode(ARM::t2B);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007098 return true;
7099 }
Jim Grosbachc0755102011-08-31 21:17:31 +00007100 break;
Jim Grosbach395b4532011-08-17 22:57:40 +00007101 case ARM::tBcc:
7102 // If the conditional is AL, we really want tB.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007103 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbach395b4532011-08-17 22:57:40 +00007104 Inst.setOpcode(ARM::tB);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007105 return true;
7106 }
Jim Grosbach3ce23d32011-08-18 16:08:39 +00007107 break;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007108 case ARM::tLDMIA: {
7109 // If the register list contains any high registers, or if the writeback
7110 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7111 // instead if we're in Thumb2. Otherwise, this should have generated
7112 // an error in validateInstruction().
7113 unsigned Rn = Inst.getOperand(0).getReg();
7114 bool hasWritebackToken =
7115 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7116 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7117 bool listContainsBase;
7118 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7119 (!listContainsBase && !hasWritebackToken) ||
7120 (listContainsBase && hasWritebackToken)) {
7121 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7122 assert (isThumbTwo());
7123 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7124 // If we're switching to the updating version, we need to insert
7125 // the writeback tied operand.
7126 if (hasWritebackToken)
7127 Inst.insert(Inst.begin(),
7128 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007129 return true;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007130 }
7131 break;
7132 }
Jim Grosbach8213c962011-09-16 20:50:13 +00007133 case ARM::tSTMIA_UPD: {
7134 // If the register list contains any high registers, we need to use
7135 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7136 // should have generated an error in validateInstruction().
7137 unsigned Rn = Inst.getOperand(0).getReg();
7138 bool listContainsBase;
7139 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7140 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7141 assert (isThumbTwo());
7142 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007143 return true;
Jim Grosbach8213c962011-09-16 20:50:13 +00007144 }
7145 break;
7146 }
Jim Grosbach54026372011-11-10 23:17:11 +00007147 case ARM::tPOP: {
7148 bool listContainsBase;
7149 // If the register list contains any high registers, we need to use
7150 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7151 // should have generated an error in validateInstruction().
7152 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007153 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007154 assert (isThumbTwo());
7155 Inst.setOpcode(ARM::t2LDMIA_UPD);
7156 // Add the base register and writeback operands.
7157 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7158 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007159 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007160 }
7161 case ARM::tPUSH: {
7162 bool listContainsBase;
7163 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007164 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007165 assert (isThumbTwo());
7166 Inst.setOpcode(ARM::t2STMDB_UPD);
7167 // Add the base register and writeback operands.
7168 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7169 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007170 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007171 }
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007172 case ARM::t2MOVi: {
7173 // If we can use the 16-bit encoding and the user didn't explicitly
7174 // request the 32-bit variant, transform it here.
7175 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbachc0164f82012-03-30 16:31:31 +00007176 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbachc2d31642011-09-14 19:12:11 +00007177 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7178 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7179 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007180 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7181 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7182 // The operands aren't in the same order for tMOVi8...
7183 MCInst TmpInst;
7184 TmpInst.setOpcode(ARM::tMOVi8);
7185 TmpInst.addOperand(Inst.getOperand(0));
7186 TmpInst.addOperand(Inst.getOperand(4));
7187 TmpInst.addOperand(Inst.getOperand(1));
7188 TmpInst.addOperand(Inst.getOperand(2));
7189 TmpInst.addOperand(Inst.getOperand(3));
7190 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007191 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007192 }
7193 break;
7194 }
7195 case ARM::t2MOVr: {
7196 // If we can use the 16-bit encoding and the user didn't explicitly
7197 // request the 32-bit variant, transform it here.
7198 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7199 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7200 Inst.getOperand(2).getImm() == ARMCC::AL &&
7201 Inst.getOperand(4).getReg() == ARM::CPSR &&
7202 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7203 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7204 // The operands aren't the same for tMOV[S]r... (no cc_out)
7205 MCInst TmpInst;
7206 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7207 TmpInst.addOperand(Inst.getOperand(0));
7208 TmpInst.addOperand(Inst.getOperand(1));
7209 TmpInst.addOperand(Inst.getOperand(2));
7210 TmpInst.addOperand(Inst.getOperand(3));
7211 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007212 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007213 }
7214 break;
7215 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007216 case ARM::t2SXTH:
Jim Grosbach50f1c372011-09-20 00:46:54 +00007217 case ARM::t2SXTB:
7218 case ARM::t2UXTH:
7219 case ARM::t2UXTB: {
Jim Grosbach326efe52011-09-19 20:29:33 +00007220 // If we can use the 16-bit encoding and the user didn't explicitly
7221 // request the 32-bit variant, transform it here.
7222 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7223 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7224 Inst.getOperand(2).getImm() == 0 &&
7225 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7226 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbach50f1c372011-09-20 00:46:54 +00007227 unsigned NewOpc;
7228 switch (Inst.getOpcode()) {
7229 default: llvm_unreachable("Illegal opcode!");
7230 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7231 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7232 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7233 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7234 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007235 // The operands aren't the same for thumb1 (no rotate operand).
7236 MCInst TmpInst;
7237 TmpInst.setOpcode(NewOpc);
7238 TmpInst.addOperand(Inst.getOperand(0));
7239 TmpInst.addOperand(Inst.getOperand(1));
7240 TmpInst.addOperand(Inst.getOperand(3));
7241 TmpInst.addOperand(Inst.getOperand(4));
7242 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007243 return true;
Jim Grosbach326efe52011-09-19 20:29:33 +00007244 }
7245 break;
7246 }
Jim Grosbach04b5d932011-12-20 00:59:38 +00007247 case ARM::MOVsi: {
7248 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonb56e4112012-04-25 18:00:18 +00007249 // rrx shifts and asr/lsr of #32 is encoded as 0
7250 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7251 return false;
Jim Grosbach04b5d932011-12-20 00:59:38 +00007252 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7253 // Shifting by zero is accepted as a vanilla 'MOVr'
7254 MCInst TmpInst;
7255 TmpInst.setOpcode(ARM::MOVr);
7256 TmpInst.addOperand(Inst.getOperand(0));
7257 TmpInst.addOperand(Inst.getOperand(1));
7258 TmpInst.addOperand(Inst.getOperand(3));
7259 TmpInst.addOperand(Inst.getOperand(4));
7260 TmpInst.addOperand(Inst.getOperand(5));
7261 Inst = TmpInst;
7262 return true;
7263 }
7264 return false;
7265 }
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007266 case ARM::ANDrsi:
7267 case ARM::ORRrsi:
7268 case ARM::EORrsi:
7269 case ARM::BICrsi:
7270 case ARM::SUBrsi:
7271 case ARM::ADDrsi: {
7272 unsigned newOpc;
7273 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7274 if (SOpc == ARM_AM::rrx) return false;
7275 switch (Inst.getOpcode()) {
Craig Topperbc219812012-02-07 02:50:20 +00007276 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007277 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7278 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7279 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7280 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7281 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7282 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7283 }
7284 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton8ed97ef2012-07-09 16:31:14 +00007285 // The exception is for right shifts, where 0 == 32
7286 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7287 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007288 MCInst TmpInst;
7289 TmpInst.setOpcode(newOpc);
7290 TmpInst.addOperand(Inst.getOperand(0));
7291 TmpInst.addOperand(Inst.getOperand(1));
7292 TmpInst.addOperand(Inst.getOperand(2));
7293 TmpInst.addOperand(Inst.getOperand(4));
7294 TmpInst.addOperand(Inst.getOperand(5));
7295 TmpInst.addOperand(Inst.getOperand(6));
7296 Inst = TmpInst;
7297 return true;
7298 }
7299 return false;
7300 }
Jim Grosbach74423e32012-01-25 19:52:01 +00007301 case ARM::ITasm:
Jim Grosbach89df9962011-08-26 21:43:41 +00007302 case ARM::t2IT: {
7303 // The mask bits for all but the first condition are represented as
7304 // the low bit of the condition code value implies 't'. We currently
7305 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Barton4d2f0772012-04-27 08:42:59 +00007306 // of the condition code is zero.
Jim Grosbach89df9962011-08-26 21:43:41 +00007307 MCOperand &MO = Inst.getOperand(1);
7308 unsigned Mask = MO.getImm();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007309 unsigned OrigMask = Mask;
7310 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach89df9962011-08-26 21:43:41 +00007311 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach89df9962011-08-26 21:43:41 +00007312 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7313 for (unsigned i = 3; i != TZ; --i)
7314 Mask ^= 1 << i;
Richard Barton4d2f0772012-04-27 08:42:59 +00007315 }
Jim Grosbach89df9962011-08-26 21:43:41 +00007316 MO.setImm(Mask);
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007317
7318 // Set up the IT block state according to the IT instruction we just
7319 // matched.
7320 assert(!inITBlock() && "nested IT blocks?!");
7321 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7322 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7323 ITState.CurPosition = 0;
7324 ITState.FirstCond = true;
Jim Grosbach89df9962011-08-26 21:43:41 +00007325 break;
7326 }
Richard Barton2b6652f2012-07-09 16:12:24 +00007327 case ARM::t2LSLrr:
7328 case ARM::t2LSRrr:
7329 case ARM::t2ASRrr:
7330 case ARM::t2SBCrr:
7331 case ARM::t2RORrr:
7332 case ARM::t2BICrr:
7333 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007334 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007335 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7336 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7337 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton874b8632012-07-09 18:30:56 +00007338 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7339 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007340 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7341 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7342 unsigned NewOpc;
7343 switch (Inst.getOpcode()) {
7344 default: llvm_unreachable("unexpected opcode");
7345 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7346 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7347 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7348 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7349 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7350 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7351 }
7352 MCInst TmpInst;
7353 TmpInst.setOpcode(NewOpc);
7354 TmpInst.addOperand(Inst.getOperand(0));
7355 TmpInst.addOperand(Inst.getOperand(5));
7356 TmpInst.addOperand(Inst.getOperand(1));
7357 TmpInst.addOperand(Inst.getOperand(2));
7358 TmpInst.addOperand(Inst.getOperand(3));
7359 TmpInst.addOperand(Inst.getOperand(4));
7360 Inst = TmpInst;
7361 return true;
7362 }
7363 return false;
7364 }
7365 case ARM::t2ANDrr:
7366 case ARM::t2EORrr:
7367 case ARM::t2ADCrr:
7368 case ARM::t2ORRrr:
7369 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007370 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007371 // These instructions are special in that they are commutable, so shorter encodings
7372 // are available more often.
7373 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7374 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7375 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7376 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton874b8632012-07-09 18:30:56 +00007377 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7378 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007379 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7380 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7381 unsigned NewOpc;
7382 switch (Inst.getOpcode()) {
7383 default: llvm_unreachable("unexpected opcode");
7384 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7385 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7386 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7387 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7388 }
7389 MCInst TmpInst;
7390 TmpInst.setOpcode(NewOpc);
7391 TmpInst.addOperand(Inst.getOperand(0));
7392 TmpInst.addOperand(Inst.getOperand(5));
7393 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7394 TmpInst.addOperand(Inst.getOperand(1));
7395 TmpInst.addOperand(Inst.getOperand(2));
7396 } else {
7397 TmpInst.addOperand(Inst.getOperand(2));
7398 TmpInst.addOperand(Inst.getOperand(1));
7399 }
7400 TmpInst.addOperand(Inst.getOperand(3));
7401 TmpInst.addOperand(Inst.getOperand(4));
7402 Inst = TmpInst;
7403 return true;
7404 }
7405 return false;
7406 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00007407 }
Jim Grosbach83ec8772011-11-10 23:42:14 +00007408 return false;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007409}
7410
Jim Grosbach47a0d522011-08-16 20:45:50 +00007411unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7412 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7413 // suffix depending on whether they're in an IT block or not.
Jim Grosbach194bd892011-08-16 22:20:01 +00007414 unsigned Opc = Inst.getOpcode();
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00007415 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach47a0d522011-08-16 20:45:50 +00007416 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7417 assert(MCID.hasOptionalDef() &&
7418 "optionally flag setting instruction missing optional def operand");
7419 assert(MCID.NumOperands == Inst.getNumOperands() &&
7420 "operand count mismatch!");
7421 // Find the optional-def operand (cc_out).
7422 unsigned OpNo;
7423 for (OpNo = 0;
7424 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7425 ++OpNo)
7426 ;
7427 // If we're parsing Thumb1, reject it completely.
7428 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7429 return Match_MnemonicFail;
7430 // If we're parsing Thumb2, which form is legal depends on whether we're
7431 // in an IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007432 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7433 !inITBlock())
Jim Grosbach47a0d522011-08-16 20:45:50 +00007434 return Match_RequiresITBlock;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007435 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7436 inITBlock())
7437 return Match_RequiresNotITBlock;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007438 }
Jim Grosbach194bd892011-08-16 22:20:01 +00007439 // Some high-register supporting Thumb1 encodings only allow both registers
7440 // to be from r0-r7 when in Thumb2.
7441 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7442 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7443 isARMLowRegister(Inst.getOperand(2).getReg()))
7444 return Match_RequiresThumb2;
7445 // Others only require ARMv6 or later.
Jim Grosbach4ec6e882011-08-19 20:46:54 +00007446 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbach194bd892011-08-16 22:20:01 +00007447 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7448 isARMLowRegister(Inst.getOperand(1).getReg()))
7449 return Match_RequiresV6;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007450 return Match_Success;
7451}
7452
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007453static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007454bool ARMAsmParser::
7455MatchAndEmitInstruction(SMLoc IDLoc,
7456 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7457 MCStreamer &Out) {
7458 MCInst Inst;
Chad Rosier3a86e132012-09-03 02:06:46 +00007459 unsigned Kind;
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007460 unsigned ErrorInfo;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007461 unsigned MatchResult;
Chad Rosier3a86e132012-09-03 02:06:46 +00007462
Chad Rosierc4d25602012-09-03 03:16:09 +00007463 MatchResult = MatchInstructionImpl(Operands, Kind, Inst, ErrorInfo);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007464 switch (MatchResult) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007465 default: break;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007466 case Match_Success:
Jim Grosbach189610f2011-07-26 18:25:39 +00007467 // Context sensitive operand constraints aren't handled by the matcher,
7468 // so check them here.
Jim Grosbacha1109882011-09-02 23:22:08 +00007469 if (validateInstruction(Inst, Operands)) {
7470 // Still progress the IT block, otherwise one wrong condition causes
7471 // nasty cascading errors.
7472 forwardITPosition();
Jim Grosbach189610f2011-07-26 18:25:39 +00007473 return true;
Jim Grosbacha1109882011-09-02 23:22:08 +00007474 }
Jim Grosbach189610f2011-07-26 18:25:39 +00007475
Jim Grosbachf8fce712011-08-11 17:35:48 +00007476 // Some instructions need post-processing to, for example, tweak which
Jim Grosbach83ec8772011-11-10 23:42:14 +00007477 // encoding is selected. Loop on it while changes happen so the
7478 // individual transformations can chain off each other. E.g.,
7479 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7480 while (processInstruction(Inst, Operands))
7481 ;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007482
Jim Grosbacha1109882011-09-02 23:22:08 +00007483 // Only move forward at the very end so that everything in validate
7484 // and process gets a consistent answer about whether we're in an IT
7485 // block.
7486 forwardITPosition();
7487
Jim Grosbach74423e32012-01-25 19:52:01 +00007488 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7489 // doesn't actually encode.
7490 if (Inst.getOpcode() == ARM::ITasm)
7491 return false;
7492
Jim Grosbach42e6bd32012-01-26 23:20:15 +00007493 Inst.setLoc(IDLoc);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007494 Out.EmitInstruction(Inst);
7495 return false;
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007496 case Match_MissingFeature: {
7497 assert(ErrorInfo && "Unknown missing feature!");
7498 // Special case the error message for the very common case where only
7499 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7500 std::string Msg = "instruction requires:";
7501 unsigned Mask = 1;
7502 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7503 if (ErrorInfo & Mask) {
7504 Msg += " ";
7505 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7506 }
7507 Mask <<= 1;
7508 }
7509 return Error(IDLoc, Msg);
7510 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007511 case Match_InvalidOperand: {
7512 SMLoc ErrorLoc = IDLoc;
7513 if (ErrorInfo != ~0U) {
7514 if (ErrorInfo >= Operands.size())
7515 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00007516
Chris Lattnere73d4f82010-10-28 21:41:58 +00007517 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7518 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7519 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007520
Chris Lattnere73d4f82010-10-28 21:41:58 +00007521 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007522 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007523 case Match_MnemonicFail:
Benjamin Kramer362a05a2012-04-15 17:04:27 +00007524 return Error(IDLoc, "invalid instruction",
7525 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007526 case Match_RequiresNotITBlock:
7527 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach47a0d522011-08-16 20:45:50 +00007528 case Match_RequiresITBlock:
7529 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbach194bd892011-08-16 22:20:01 +00007530 case Match_RequiresV6:
7531 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7532 case Match_RequiresThumb2:
7533 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach70c9bf32012-06-22 23:56:48 +00007534 case Match_ImmRange0_15: {
7535 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7536 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7537 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7538 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007539 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007540
Eric Christopherc223e2b2010-10-29 09:26:59 +00007541 llvm_unreachable("Implement any new match types added!");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007542}
7543
Jim Grosbach1355cf12011-07-26 17:10:22 +00007544/// parseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007545bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7546 StringRef IDVal = DirectiveID.getIdentifier();
7547 if (IDVal == ".word")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007548 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007549 else if (IDVal == ".thumb")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007550 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach9a70df92011-12-07 18:04:19 +00007551 else if (IDVal == ".arm")
7552 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007553 else if (IDVal == ".thumb_func")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007554 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007555 else if (IDVal == ".code")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007556 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007557 else if (IDVal == ".syntax")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007558 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbacha39cda72011-12-14 02:16:11 +00007559 else if (IDVal == ".unreq")
7560 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kimd7c9e082011-12-20 17:38:12 +00007561 else if (IDVal == ".arch")
7562 return parseDirectiveArch(DirectiveID.getLoc());
7563 else if (IDVal == ".eabi_attribute")
7564 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007565 return true;
7566}
7567
Jim Grosbach1355cf12011-07-26 17:10:22 +00007568/// parseDirectiveWord
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007569/// ::= .word [ expression (, expression)* ]
Jim Grosbach1355cf12011-07-26 17:10:22 +00007570bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007571 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7572 for (;;) {
7573 const MCExpr *Value;
7574 if (getParser().ParseExpression(Value))
7575 return true;
7576
Chris Lattneraaec2052010-01-19 19:46:13 +00007577 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007578
7579 if (getLexer().is(AsmToken::EndOfStatement))
7580 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00007581
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007582 // FIXME: Improve diagnostic.
7583 if (getLexer().isNot(AsmToken::Comma))
7584 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007585 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007586 }
7587 }
7588
Sean Callananb9a25b72010-01-19 20:27:46 +00007589 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007590 return false;
7591}
7592
Jim Grosbach1355cf12011-07-26 17:10:22 +00007593/// parseDirectiveThumb
Kevin Enderby515d5092009-10-15 20:48:48 +00007594/// ::= .thumb
Jim Grosbach1355cf12011-07-26 17:10:22 +00007595bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby515d5092009-10-15 20:48:48 +00007596 if (getLexer().isNot(AsmToken::EndOfStatement))
7597 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007598 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007599
Jim Grosbach9a70df92011-12-07 18:04:19 +00007600 if (!isThumb())
7601 SwitchMode();
7602 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7603 return false;
7604}
7605
7606/// parseDirectiveARM
7607/// ::= .arm
7608bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7609 if (getLexer().isNot(AsmToken::EndOfStatement))
7610 return Error(L, "unexpected token in directive");
7611 Parser.Lex();
7612
7613 if (isThumb())
7614 SwitchMode();
7615 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby515d5092009-10-15 20:48:48 +00007616 return false;
7617}
7618
Jim Grosbach1355cf12011-07-26 17:10:22 +00007619/// parseDirectiveThumbFunc
Kevin Enderby515d5092009-10-15 20:48:48 +00007620/// ::= .thumbfunc symbol_name
Jim Grosbach1355cf12011-07-26 17:10:22 +00007621bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00007622 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7623 bool isMachO = MAI.hasSubsectionsViaSymbols();
7624 StringRef Name;
Jim Grosbachde4d8392011-12-21 22:30:16 +00007625 bool needFuncName = true;
Rafael Espindola64695402011-05-16 16:17:21 +00007626
Jim Grosbachde4d8392011-12-21 22:30:16 +00007627 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindola64695402011-05-16 16:17:21 +00007628 // ELF doesn't
7629 if (isMachO) {
7630 const AsmToken &Tok = Parser.getTok();
Jim Grosbachde4d8392011-12-21 22:30:16 +00007631 if (Tok.isNot(AsmToken::EndOfStatement)) {
7632 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7633 return Error(L, "unexpected token in .thumb_func directive");
7634 Name = Tok.getIdentifier();
7635 Parser.Lex(); // Consume the identifier token.
7636 needFuncName = false;
7637 }
Rafael Espindola64695402011-05-16 16:17:21 +00007638 }
7639
Jim Grosbachde4d8392011-12-21 22:30:16 +00007640 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby515d5092009-10-15 20:48:48 +00007641 return Error(L, "unexpected token in directive");
Jim Grosbachde4d8392011-12-21 22:30:16 +00007642
7643 // Eat the end of statement and any blank lines that follow.
7644 while (getLexer().is(AsmToken::EndOfStatement))
7645 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007646
Rafael Espindola64695402011-05-16 16:17:21 +00007647 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbachde4d8392011-12-21 22:30:16 +00007648 // We really should be checking the next symbol definition even if there's
7649 // stuff in between.
7650 if (needFuncName) {
Jim Grosbachd475f862011-11-10 20:48:53 +00007651 Name = Parser.getTok().getIdentifier();
Rafael Espindola64695402011-05-16 16:17:21 +00007652 }
7653
Jim Grosbach642fc9c2010-11-05 22:33:53 +00007654 // Mark symbol as a thumb symbol.
7655 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7656 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00007657 return false;
7658}
7659
Jim Grosbach1355cf12011-07-26 17:10:22 +00007660/// parseDirectiveSyntax
Kevin Enderby515d5092009-10-15 20:48:48 +00007661/// ::= .syntax unified | divided
Jim Grosbach1355cf12011-07-26 17:10:22 +00007662bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007663 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007664 if (Tok.isNot(AsmToken::Identifier))
7665 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00007666 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00007667 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00007668 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007669 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00007670 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00007671 else
7672 return Error(L, "unrecognized syntax mode in .syntax directive");
7673
7674 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007675 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007676 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007677
7678 // TODO tell the MC streamer the mode
7679 // getParser().getStreamer().Emit???();
7680 return false;
7681}
7682
Jim Grosbach1355cf12011-07-26 17:10:22 +00007683/// parseDirectiveCode
Kevin Enderby515d5092009-10-15 20:48:48 +00007684/// ::= .code 16 | 32
Jim Grosbach1355cf12011-07-26 17:10:22 +00007685bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007686 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007687 if (Tok.isNot(AsmToken::Integer))
7688 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00007689 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00007690 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00007691 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007692 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00007693 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007694 else
7695 return Error(L, "invalid operand to .code directive");
7696
7697 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007698 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007699 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007700
Evan Cheng32869202011-07-08 22:36:29 +00007701 if (Val == 16) {
Jim Grosbach98447da2011-09-06 18:46:23 +00007702 if (!isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007703 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007704 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng32869202011-07-08 22:36:29 +00007705 } else {
Jim Grosbach98447da2011-09-06 18:46:23 +00007706 if (isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007707 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007708 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Chengeb0caa12011-07-08 22:49:55 +00007709 }
Jim Grosbach2a301702010-11-05 22:40:53 +00007710
Kevin Enderby515d5092009-10-15 20:48:48 +00007711 return false;
7712}
7713
Jim Grosbacha39cda72011-12-14 02:16:11 +00007714/// parseDirectiveReq
7715/// ::= name .req registername
7716bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7717 Parser.Lex(); // Eat the '.req' token.
7718 unsigned Reg;
7719 SMLoc SRegLoc, ERegLoc;
7720 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7721 Parser.EatToEndOfStatement();
7722 return Error(SRegLoc, "register name expected");
7723 }
7724
7725 // Shouldn't be anything else.
7726 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7727 Parser.EatToEndOfStatement();
7728 return Error(Parser.getTok().getLoc(),
7729 "unexpected input in .req directive.");
7730 }
7731
7732 Parser.Lex(); // Consume the EndOfStatement
7733
7734 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7735 return Error(SRegLoc, "redefinition of '" + Name +
7736 "' does not match original.");
7737
7738 return false;
7739}
7740
7741/// parseDirectiveUneq
7742/// ::= .unreq registername
7743bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7744 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7745 Parser.EatToEndOfStatement();
7746 return Error(L, "unexpected input in .unreq directive.");
7747 }
7748 RegisterReqs.erase(Parser.getTok().getIdentifier());
7749 Parser.Lex(); // Eat the identifier.
7750 return false;
7751}
7752
Jason W Kimd7c9e082011-12-20 17:38:12 +00007753/// parseDirectiveArch
7754/// ::= .arch token
7755bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7756 return true;
7757}
7758
7759/// parseDirectiveEabiAttr
7760/// ::= .eabi_attribute int, int
7761bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7762 return true;
7763}
7764
Sean Callanan90b70972010-04-07 20:29:34 +00007765extern "C" void LLVMInitializeARMAsmLexer();
7766
Kevin Enderby9c41fa82009-10-30 22:55:57 +00007767/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007768extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng94b95502011-07-26 00:24:13 +00007769 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7770 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00007771 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007772}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007773
Chris Lattner0692ee62010-09-06 19:11:01 +00007774#define GET_REGISTER_MATCHER
Craig Topper8030e1a2012-04-25 06:56:34 +00007775#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner0692ee62010-09-06 19:11:01 +00007776#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007777#include "ARMGenAsmMatcher.inc"