blob: 8fe504fb2bb5e9210d860bdab281c2e0d59f68f3 [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
10#include "ARM.h"
Bill Wendling92b5a2e2010-11-03 01:49:29 +000011#include "ARMAddressingModes.h"
Evan Cheng75972122011-01-13 07:58:56 +000012#include "ARMMCExpr.h"
Evan Chengb72d2a92011-01-11 21:46:47 +000013#include "ARMBaseRegisterInfo.h"
Daniel Dunbar3483aca2010-08-11 05:24:50 +000014#include "ARMSubtarget.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000015#include "llvm/MC/MCParser/MCAsmLexer.h"
16#include "llvm/MC/MCParser/MCAsmParser.h"
17#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
Rafael Espindola64695402011-05-16 16:17:21 +000018#include "llvm/MC/MCAsmInfo.h"
Jim Grosbach642fc9c2010-11-05 22:33:53 +000019#include "llvm/MC/MCContext.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000020#include "llvm/MC/MCStreamer.h"
21#include "llvm/MC/MCExpr.h"
22#include "llvm/MC/MCInst.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000023#include "llvm/Target/TargetRegistry.h"
24#include "llvm/Target/TargetAsmParser.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000025#include "llvm/Support/SourceMgr.h"
Daniel Dunbarfa315de2010-08-11 06:37:12 +000026#include "llvm/Support/raw_ostream.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000027#include "llvm/ADT/SmallVector.h"
Owen Anderson0c9f2502011-01-13 22:50:36 +000028#include "llvm/ADT/StringExtras.h"
Daniel Dunbar345a9a62010-08-11 06:37:20 +000029#include "llvm/ADT/StringSwitch.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000030#include "llvm/ADT/Twine.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000031using namespace llvm;
32
Chris Lattner3a697562010-10-28 17:20:03 +000033namespace {
Bill Wendling146018f2010-11-06 21:42:12 +000034
35class ARMOperand;
Jim Grosbach16c74252010-10-29 14:46:02 +000036
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000037class ARMAsmParser : public TargetAsmParser {
38 MCAsmParser &Parser;
Daniel Dunbard73ada72010-07-19 00:33:49 +000039 TargetMachine &TM;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000040
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000041 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000042 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
43
44 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000045 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
46
Chris Lattnere5658fa2010-10-30 04:09:10 +000047 int TryParseRegister();
Roman Divackybf755322011-01-27 17:14:22 +000048 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Bill Wendling50d0f582010-11-18 23:43:05 +000049 bool TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Owen Anderson00828302011-03-18 22:50:18 +000050 bool TryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Bill Wendling50d0f582010-11-18 23:43:05 +000051 bool ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +000052 bool ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &,
53 ARMII::AddrMode AddrMode);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +000054 bool ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
Evan Cheng75972122011-01-13 07:58:56 +000055 bool ParsePrefix(ARMMCExpr::VariantKind &RefKind);
Jason W Kim9081b4b2011-01-11 23:53:41 +000056 const MCExpr *ApplyPrefixToExpr(const MCExpr *E,
57 MCSymbolRefExpr::VariantKind Variant);
58
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000059
Kevin Enderby9c41fa82009-10-30 22:55:57 +000060 bool ParseMemoryOffsetReg(bool &Negative,
61 bool &OffsetRegShifted,
Owen Anderson00828302011-03-18 22:50:18 +000062 enum ARM_AM::ShiftOpc &ShiftType,
Kevin Enderby9c41fa82009-10-30 22:55:57 +000063 const MCExpr *&ShiftAmount,
64 const MCExpr *&Offset,
65 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +000066 int &OffsetRegNum,
67 SMLoc &E);
Owen Anderson00828302011-03-18 22:50:18 +000068 bool ParseShift(enum ARM_AM::ShiftOpc &St,
69 const MCExpr *&ShiftAmount, SMLoc &E);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000070 bool ParseDirectiveWord(unsigned Size, SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000071 bool ParseDirectiveThumb(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000072 bool ParseDirectiveThumbFunc(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000073 bool ParseDirectiveCode(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000074 bool ParseDirectiveSyntax(SMLoc L);
75
Chris Lattner7036f8b2010-09-29 01:42:58 +000076 bool MatchAndEmitInstruction(SMLoc IDLoc,
Chris Lattner7c51a312010-09-29 01:50:45 +000077 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chris Lattnerfa42fad2010-10-28 21:28:01 +000078 MCStreamer &Out);
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +000079 void GetMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
80 bool &CanAcceptPredicationCode);
Jim Grosbach16c74252010-10-29 14:46:02 +000081
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000082 /// @name Auto-generated Match Functions
83 /// {
Daniel Dunbar3483aca2010-08-11 05:24:50 +000084
Chris Lattner0692ee62010-09-06 19:11:01 +000085#define GET_ASSEMBLER_HEADER
86#include "ARMGenAsmMatcher.inc"
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000087
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000088 /// }
89
Jim Grosbachf922c472011-02-12 01:34:40 +000090 OperandMatchResultTy tryParseCoprocNumOperand(
91 SmallVectorImpl<MCParsedAsmOperand*>&);
92 OperandMatchResultTy tryParseCoprocRegOperand(
93 SmallVectorImpl<MCParsedAsmOperand*>&);
94 OperandMatchResultTy tryParseMemBarrierOptOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +000095 SmallVectorImpl<MCParsedAsmOperand*>&);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +000096 OperandMatchResultTy tryParseProcIFlagsOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +000097 SmallVectorImpl<MCParsedAsmOperand*>&);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +000098 OperandMatchResultTy tryParseMSRMaskOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +000099 SmallVectorImpl<MCParsedAsmOperand*>&);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000100 OperandMatchResultTy tryParseMemMode2Operand(
101 SmallVectorImpl<MCParsedAsmOperand*>&);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000102 OperandMatchResultTy tryParseMemMode3Operand(
103 SmallVectorImpl<MCParsedAsmOperand*>&);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000104
105 // Asm Match Converter Methods
106 bool CvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
107 const SmallVectorImpl<MCParsedAsmOperand*> &);
108 bool CvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
109 const SmallVectorImpl<MCParsedAsmOperand*> &);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000110 bool CvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
111 const SmallVectorImpl<MCParsedAsmOperand*> &);
112 bool CvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
113 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachf922c472011-02-12 01:34:40 +0000114
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000115public:
Daniel Dunbard73ada72010-07-19 00:33:49 +0000116 ARMAsmParser(const Target &T, MCAsmParser &_Parser, TargetMachine &_TM)
Jim Grosbach833c93c2010-11-01 16:59:54 +0000117 : TargetAsmParser(T), Parser(_Parser), TM(_TM) {
Sean Callananf6d91092011-04-18 20:20:44 +0000118 MCAsmParserExtension::Initialize(_Parser);
Jim Grosbach833c93c2010-11-01 16:59:54 +0000119 // Initialize the set of available features.
120 setAvailableFeatures(ComputeAvailableFeatures(
121 &TM.getSubtarget<ARMSubtarget>()));
122 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000123
Benjamin Kramer38e59892010-07-14 22:38:02 +0000124 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Chris Lattner98986712010-01-14 22:21:20 +0000125 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000126 virtual bool ParseDirective(AsmToken DirectiveID);
127};
Jim Grosbach16c74252010-10-29 14:46:02 +0000128} // end anonymous namespace
129
Chris Lattner3a697562010-10-28 17:20:03 +0000130namespace {
131
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000132/// ARMOperand - Instances of this class represent a parsed ARM machine
133/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000134class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000135 enum KindTy {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000136 CondCode,
Jim Grosbachd67641b2010-12-06 18:21:12 +0000137 CCOut,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000138 CoprocNum,
139 CoprocReg,
Kevin Enderbycfe07242009-10-13 22:19:02 +0000140 Immediate,
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000141 MemBarrierOpt,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000142 Memory,
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000143 MSRMask,
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000144 ProcIFlags,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000145 Register,
Bill Wendling8d5acb72010-11-06 19:56:04 +0000146 RegisterList,
Bill Wendling0f630752010-11-17 04:32:08 +0000147 DPRRegisterList,
148 SPRRegisterList,
Owen Anderson00828302011-03-18 22:50:18 +0000149 Shifter,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000150 Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000151 } Kind;
152
Sean Callanan76264762010-04-02 22:27:05 +0000153 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000154 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000155
156 union {
157 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000158 ARMCC::CondCodes Val;
159 } CC;
160
161 struct {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000162 ARM_MB::MemBOpt Val;
163 } MBOpt;
164
165 struct {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000166 unsigned Val;
167 } Cop;
168
169 struct {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000170 ARM_PROC::IFlags Val;
171 } IFlags;
172
173 struct {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000174 unsigned Val;
175 } MMask;
176
177 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000178 const char *Data;
179 unsigned Length;
180 } Tok;
181
182 struct {
183 unsigned RegNum;
184 } Reg;
185
Bill Wendling8155e5b2010-11-06 22:19:43 +0000186 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000187 const MCExpr *Val;
188 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000189
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000190 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000191 struct {
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000192 ARMII::AddrMode AddrMode;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000193 unsigned BaseRegNum;
Daniel Dunbar2637dc92011-01-18 05:55:15 +0000194 union {
195 unsigned RegNum; ///< Offset register num, when OffsetIsReg.
196 const MCExpr *Value; ///< Offset value, when !OffsetIsReg.
197 } Offset;
Bill Wendling146018f2010-11-06 21:42:12 +0000198 const MCExpr *ShiftAmount; // used when OffsetRegShifted is true
Owen Anderson00828302011-03-18 22:50:18 +0000199 enum ARM_AM::ShiftOpc ShiftType; // used when OffsetRegShifted is true
Bill Wendling146018f2010-11-06 21:42:12 +0000200 unsigned OffsetRegShifted : 1; // only used when OffsetIsReg is true
Bill Wendling50d0f582010-11-18 23:43:05 +0000201 unsigned Preindexed : 1;
202 unsigned Postindexed : 1;
203 unsigned OffsetIsReg : 1;
204 unsigned Negative : 1; // only used when OffsetIsReg is true
205 unsigned Writeback : 1;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000206 } Mem;
Owen Anderson00828302011-03-18 22:50:18 +0000207
208 struct {
209 ARM_AM::ShiftOpc ShiftTy;
210 unsigned RegNum;
211 } Shift;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000212 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000213
Bill Wendling146018f2010-11-06 21:42:12 +0000214 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
215public:
Sean Callanan76264762010-04-02 22:27:05 +0000216 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
217 Kind = o.Kind;
218 StartLoc = o.StartLoc;
219 EndLoc = o.EndLoc;
220 switch (Kind) {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000221 case CondCode:
222 CC = o.CC;
223 break;
Sean Callanan76264762010-04-02 22:27:05 +0000224 case Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000225 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000226 break;
Jim Grosbachd67641b2010-12-06 18:21:12 +0000227 case CCOut:
Sean Callanan76264762010-04-02 22:27:05 +0000228 case Register:
229 Reg = o.Reg;
230 break;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000231 case RegisterList:
Bill Wendling0f630752010-11-17 04:32:08 +0000232 case DPRRegisterList:
233 case SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000234 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000235 break;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000236 case CoprocNum:
237 case CoprocReg:
238 Cop = o.Cop;
239 break;
Sean Callanan76264762010-04-02 22:27:05 +0000240 case Immediate:
241 Imm = o.Imm;
242 break;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000243 case MemBarrierOpt:
244 MBOpt = o.MBOpt;
245 break;
Sean Callanan76264762010-04-02 22:27:05 +0000246 case Memory:
247 Mem = o.Mem;
248 break;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000249 case MSRMask:
250 MMask = o.MMask;
251 break;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000252 case ProcIFlags:
253 IFlags = o.IFlags;
Owen Anderson00828302011-03-18 22:50:18 +0000254 break;
255 case Shifter:
256 Shift = o.Shift;
257 break;
Sean Callanan76264762010-04-02 22:27:05 +0000258 }
259 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000260
Sean Callanan76264762010-04-02 22:27:05 +0000261 /// getStartLoc - Get the location of the first token of this operand.
262 SMLoc getStartLoc() const { return StartLoc; }
263 /// getEndLoc - Get the location of the last token of this operand.
264 SMLoc getEndLoc() const { return EndLoc; }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000265
Daniel Dunbar8462b302010-08-11 06:36:53 +0000266 ARMCC::CondCodes getCondCode() const {
267 assert(Kind == CondCode && "Invalid access!");
268 return CC.Val;
269 }
270
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000271 unsigned getCoproc() const {
272 assert((Kind == CoprocNum || Kind == CoprocReg) && "Invalid access!");
273 return Cop.Val;
274 }
275
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000276 StringRef getToken() const {
277 assert(Kind == Token && "Invalid access!");
278 return StringRef(Tok.Data, Tok.Length);
279 }
280
281 unsigned getReg() const {
Benjamin Kramer6aa49432010-12-07 15:50:35 +0000282 assert((Kind == Register || Kind == CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000283 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000284 }
285
Bill Wendling5fa22a12010-11-09 23:28:44 +0000286 const SmallVectorImpl<unsigned> &getRegList() const {
Bill Wendling0f630752010-11-17 04:32:08 +0000287 assert((Kind == RegisterList || Kind == DPRRegisterList ||
288 Kind == SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000289 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000290 }
291
Kevin Enderbycfe07242009-10-13 22:19:02 +0000292 const MCExpr *getImm() const {
293 assert(Kind == Immediate && "Invalid access!");
294 return Imm.Val;
295 }
296
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000297 ARM_MB::MemBOpt getMemBarrierOpt() const {
298 assert(Kind == MemBarrierOpt && "Invalid access!");
299 return MBOpt.Val;
300 }
301
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000302 ARM_PROC::IFlags getProcIFlags() const {
303 assert(Kind == ProcIFlags && "Invalid access!");
304 return IFlags.Val;
305 }
306
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000307 unsigned getMSRMask() const {
308 assert(Kind == MSRMask && "Invalid access!");
309 return MMask.Val;
310 }
311
Daniel Dunbar6ec56202011-01-18 05:55:21 +0000312 /// @name Memory Operand Accessors
313 /// @{
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000314 ARMII::AddrMode getMemAddrMode() const {
315 return Mem.AddrMode;
316 }
Daniel Dunbar6ec56202011-01-18 05:55:21 +0000317 unsigned getMemBaseRegNum() const {
318 return Mem.BaseRegNum;
319 }
320 unsigned getMemOffsetRegNum() const {
321 assert(Mem.OffsetIsReg && "Invalid access!");
322 return Mem.Offset.RegNum;
323 }
324 const MCExpr *getMemOffset() const {
325 assert(!Mem.OffsetIsReg && "Invalid access!");
326 return Mem.Offset.Value;
327 }
328 unsigned getMemOffsetRegShifted() const {
329 assert(Mem.OffsetIsReg && "Invalid access!");
330 return Mem.OffsetRegShifted;
331 }
332 const MCExpr *getMemShiftAmount() const {
333 assert(Mem.OffsetIsReg && Mem.OffsetRegShifted && "Invalid access!");
334 return Mem.ShiftAmount;
335 }
Owen Anderson00828302011-03-18 22:50:18 +0000336 enum ARM_AM::ShiftOpc getMemShiftType() const {
Daniel Dunbar6ec56202011-01-18 05:55:21 +0000337 assert(Mem.OffsetIsReg && Mem.OffsetRegShifted && "Invalid access!");
338 return Mem.ShiftType;
339 }
340 bool getMemPreindexed() const { return Mem.Preindexed; }
341 bool getMemPostindexed() const { return Mem.Postindexed; }
342 bool getMemOffsetIsReg() const { return Mem.OffsetIsReg; }
343 bool getMemNegative() const { return Mem.Negative; }
344 bool getMemWriteback() const { return Mem.Writeback; }
345
346 /// @}
347
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000348 bool isCoprocNum() const { return Kind == CoprocNum; }
349 bool isCoprocReg() const { return Kind == CoprocReg; }
Daniel Dunbar8462b302010-08-11 06:36:53 +0000350 bool isCondCode() const { return Kind == CondCode; }
Jim Grosbachd67641b2010-12-06 18:21:12 +0000351 bool isCCOut() const { return Kind == CCOut; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000352 bool isImm() const { return Kind == Immediate; }
Bill Wendlingb32e7842010-11-08 00:32:40 +0000353 bool isReg() const { return Kind == Register; }
Bill Wendling8d5acb72010-11-06 19:56:04 +0000354 bool isRegList() const { return Kind == RegisterList; }
Bill Wendling0f630752010-11-17 04:32:08 +0000355 bool isDPRRegList() const { return Kind == DPRRegisterList; }
356 bool isSPRRegList() const { return Kind == SPRRegisterList; }
Chris Lattner14b93852010-10-29 00:27:31 +0000357 bool isToken() const { return Kind == Token; }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000358 bool isMemBarrierOpt() const { return Kind == MemBarrierOpt; }
Chris Lattner14b93852010-10-29 00:27:31 +0000359 bool isMemory() const { return Kind == Memory; }
Owen Anderson00828302011-03-18 22:50:18 +0000360 bool isShifter() const { return Kind == Shifter; }
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000361 bool isMemMode2() const {
362 if (getMemAddrMode() != ARMII::AddrMode2)
363 return false;
364
365 if (getMemOffsetIsReg())
366 return true;
367
368 if (getMemNegative() &&
369 !(getMemPostindexed() || getMemPreindexed()))
370 return false;
371
372 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
373 if (!CE) return false;
374 int64_t Value = CE->getValue();
375
376 // The offset must be in the range 0-4095 (imm12).
377 if (Value > 4095 || Value < -4095)
378 return false;
379
380 return true;
381 }
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000382 bool isMemMode3() const {
383 if (getMemAddrMode() != ARMII::AddrMode3)
384 return false;
385
386 if (getMemOffsetIsReg()) {
387 if (getMemOffsetRegShifted())
388 return false; // No shift with offset reg allowed
389 return true;
390 }
391
392 if (getMemNegative() &&
393 !(getMemPostindexed() || getMemPreindexed()))
394 return false;
395
396 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
397 if (!CE) return false;
398 int64_t Value = CE->getValue();
399
400 // The offset must be in the range 0-255 (imm8).
401 if (Value > 255 || Value < -255)
402 return false;
403
404 return true;
405 }
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000406 bool isMemMode5() const {
Daniel Dunbar4b462672011-01-18 05:55:27 +0000407 if (!isMemory() || getMemOffsetIsReg() || getMemWriteback() ||
408 getMemNegative())
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000409 return false;
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000410
Daniel Dunbar4b462672011-01-18 05:55:27 +0000411 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000412 if (!CE) return false;
413
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000414 // The offset must be a multiple of 4 in the range 0-1020.
415 int64_t Value = CE->getValue();
416 return ((Value & 0x3) == 0 && Value <= 1020 && Value >= -1020);
417 }
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000418 bool isMemMode7() const {
419 if (!isMemory() ||
420 getMemPreindexed() ||
421 getMemPostindexed() ||
422 getMemOffsetIsReg() ||
423 getMemNegative() ||
424 getMemWriteback())
425 return false;
426
427 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
428 if (!CE) return false;
429
430 if (CE->getValue())
431 return false;
432
433 return true;
434 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000435 bool isMemModeRegThumb() const {
Daniel Dunbar4b462672011-01-18 05:55:27 +0000436 if (!isMemory() || !getMemOffsetIsReg() || getMemWriteback())
Bill Wendlingf4caf692010-12-14 03:36:38 +0000437 return false;
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000438 return true;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000439 }
440 bool isMemModeImmThumb() const {
Daniel Dunbar4b462672011-01-18 05:55:27 +0000441 if (!isMemory() || getMemOffsetIsReg() || getMemWriteback())
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000442 return false;
443
Daniel Dunbar4b462672011-01-18 05:55:27 +0000444 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000445 if (!CE) return false;
446
447 // The offset must be a multiple of 4 in the range 0-124.
448 uint64_t Value = CE->getValue();
449 return ((Value & 0x3) == 0 && Value <= 124);
450 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000451 bool isMSRMask() const { return Kind == MSRMask; }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000452 bool isProcIFlags() const { return Kind == ProcIFlags; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000453
454 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +0000455 // Add as immediates when possible. Null MCExpr = 0.
456 if (Expr == 0)
457 Inst.addOperand(MCOperand::CreateImm(0));
458 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000459 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
460 else
461 Inst.addOperand(MCOperand::CreateExpr(Expr));
462 }
463
Daniel Dunbar8462b302010-08-11 06:36:53 +0000464 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000465 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000466 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +0000467 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
468 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +0000469 }
470
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000471 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
472 assert(N == 1 && "Invalid number of operands!");
473 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
474 }
475
476 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
477 assert(N == 1 && "Invalid number of operands!");
478 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
479 }
480
Jim Grosbachd67641b2010-12-06 18:21:12 +0000481 void addCCOutOperands(MCInst &Inst, unsigned N) const {
482 assert(N == 1 && "Invalid number of operands!");
483 Inst.addOperand(MCOperand::CreateReg(getReg()));
484 }
485
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000486 void addRegOperands(MCInst &Inst, unsigned N) const {
487 assert(N == 1 && "Invalid number of operands!");
488 Inst.addOperand(MCOperand::CreateReg(getReg()));
489 }
490
Owen Anderson00828302011-03-18 22:50:18 +0000491 void addShifterOperands(MCInst &Inst, unsigned N) const {
492 assert(N == 1 && "Invalid number of operands!");
493 Inst.addOperand(MCOperand::CreateImm(
494 ARM_AM::getSORegOpc(Shift.ShiftTy, 0)));
495 }
496
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000497 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +0000498 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +0000499 const SmallVectorImpl<unsigned> &RegList = getRegList();
500 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000501 I = RegList.begin(), E = RegList.end(); I != E; ++I)
502 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000503 }
504
Bill Wendling0f630752010-11-17 04:32:08 +0000505 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
506 addRegListOperands(Inst, N);
507 }
508
509 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
510 addRegListOperands(Inst, N);
511 }
512
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000513 void addImmOperands(MCInst &Inst, unsigned N) const {
514 assert(N == 1 && "Invalid number of operands!");
515 addExpr(Inst, getImm());
516 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000517
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000518 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
519 assert(N == 1 && "Invalid number of operands!");
520 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
521 }
522
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000523 void addMemMode7Operands(MCInst &Inst, unsigned N) const {
524 assert(N == 1 && isMemMode7() && "Invalid number of operands!");
525 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
526
527 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
Matt Beaumont-Gay1866af42011-03-24 22:05:48 +0000528 (void)CE;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000529 assert((CE || CE->getValue() == 0) &&
530 "No offset operand support in mode 7");
531 }
532
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000533 void addMemMode2Operands(MCInst &Inst, unsigned N) const {
534 assert(isMemMode2() && "Invalid mode or number of operands!");
535 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
536 unsigned IdxMode = (getMemPreindexed() | getMemPostindexed() << 1);
537
538 if (getMemOffsetIsReg()) {
539 Inst.addOperand(MCOperand::CreateReg(getMemOffsetRegNum()));
540
541 ARM_AM::AddrOpc AMOpc = getMemNegative() ? ARM_AM::sub : ARM_AM::add;
542 ARM_AM::ShiftOpc ShOpc = ARM_AM::no_shift;
543 int64_t ShiftAmount = 0;
544
545 if (getMemOffsetRegShifted()) {
546 ShOpc = getMemShiftType();
547 const MCConstantExpr *CE =
548 dyn_cast<MCConstantExpr>(getMemShiftAmount());
549 ShiftAmount = CE->getValue();
550 }
551
552 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM2Opc(AMOpc, ShiftAmount,
553 ShOpc, IdxMode)));
554 return;
555 }
556
557 // Create a operand placeholder to always yield the same number of operands.
558 Inst.addOperand(MCOperand::CreateReg(0));
559
560 // FIXME: #-0 is encoded differently than #0. Does the parser preserve
561 // the difference?
562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
563 assert(CE && "Non-constant mode 2 offset operand!");
564 int64_t Offset = CE->getValue();
565
566 if (Offset >= 0)
567 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM2Opc(ARM_AM::add,
568 Offset, ARM_AM::no_shift, IdxMode)));
569 else
570 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM2Opc(ARM_AM::sub,
571 -Offset, ARM_AM::no_shift, IdxMode)));
572 }
573
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000574 void addMemMode3Operands(MCInst &Inst, unsigned N) const {
575 assert(isMemMode3() && "Invalid mode or number of operands!");
576 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
577 unsigned IdxMode = (getMemPreindexed() | getMemPostindexed() << 1);
578
579 if (getMemOffsetIsReg()) {
580 Inst.addOperand(MCOperand::CreateReg(getMemOffsetRegNum()));
581
582 ARM_AM::AddrOpc AMOpc = getMemNegative() ? ARM_AM::sub : ARM_AM::add;
583 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM3Opc(AMOpc, 0,
584 IdxMode)));
585 return;
586 }
587
588 // Create a operand placeholder to always yield the same number of operands.
589 Inst.addOperand(MCOperand::CreateReg(0));
590
591 // FIXME: #-0 is encoded differently than #0. Does the parser preserve
592 // the difference?
593 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
594 assert(CE && "Non-constant mode 3 offset operand!");
595 int64_t Offset = CE->getValue();
596
597 if (Offset >= 0)
598 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM3Opc(ARM_AM::add,
599 Offset, IdxMode)));
600 else
601 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM3Opc(ARM_AM::sub,
602 -Offset, IdxMode)));
603 }
604
Chris Lattner14b93852010-10-29 00:27:31 +0000605 void addMemMode5Operands(MCInst &Inst, unsigned N) const {
606 assert(N == 2 && isMemMode5() && "Invalid number of operands!");
Jim Grosbach16c74252010-10-29 14:46:02 +0000607
Daniel Dunbar4b462672011-01-18 05:55:27 +0000608 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
609 assert(!getMemOffsetIsReg() && "Invalid mode 5 operand");
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000610
Jim Grosbach80eb2332010-10-29 17:41:25 +0000611 // FIXME: #-0 is encoded differently than #0. Does the parser preserve
612 // the difference?
Daniel Dunbar4b462672011-01-18 05:55:27 +0000613 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000614 assert(CE && "Non-constant mode 5 offset operand!");
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000615
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000616 // The MCInst offset operand doesn't include the low two bits (like
617 // the instruction encoding).
618 int64_t Offset = CE->getValue() / 4;
619 if (Offset >= 0)
620 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add,
621 Offset)));
622 else
623 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub,
624 -Offset)));
Chris Lattner14b93852010-10-29 00:27:31 +0000625 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000626
Bill Wendlingf4caf692010-12-14 03:36:38 +0000627 void addMemModeRegThumbOperands(MCInst &Inst, unsigned N) const {
628 assert(N == 2 && isMemModeRegThumb() && "Invalid number of operands!");
Daniel Dunbar4b462672011-01-18 05:55:27 +0000629 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
630 Inst.addOperand(MCOperand::CreateReg(getMemOffsetRegNum()));
Bill Wendlingf4caf692010-12-14 03:36:38 +0000631 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000632
Bill Wendlingf4caf692010-12-14 03:36:38 +0000633 void addMemModeImmThumbOperands(MCInst &Inst, unsigned N) const {
634 assert(N == 2 && isMemModeImmThumb() && "Invalid number of operands!");
Daniel Dunbar4b462672011-01-18 05:55:27 +0000635 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
636 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000637 assert(CE && "Non-constant mode offset operand!");
638 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000639 }
640
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000641 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
642 assert(N == 1 && "Invalid number of operands!");
643 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
644 }
645
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000646 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
647 assert(N == 1 && "Invalid number of operands!");
648 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
649 }
650
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000651 virtual void dump(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +0000652
Chris Lattner3a697562010-10-28 17:20:03 +0000653 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
654 ARMOperand *Op = new ARMOperand(CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000655 Op->CC.Val = CC;
656 Op->StartLoc = S;
657 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000658 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000659 }
660
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000661 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
662 ARMOperand *Op = new ARMOperand(CoprocNum);
663 Op->Cop.Val = CopVal;
664 Op->StartLoc = S;
665 Op->EndLoc = S;
666 return Op;
667 }
668
669 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
670 ARMOperand *Op = new ARMOperand(CoprocReg);
671 Op->Cop.Val = CopVal;
672 Op->StartLoc = S;
673 Op->EndLoc = S;
674 return Op;
675 }
676
Jim Grosbachd67641b2010-12-06 18:21:12 +0000677 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
678 ARMOperand *Op = new ARMOperand(CCOut);
679 Op->Reg.RegNum = RegNum;
680 Op->StartLoc = S;
681 Op->EndLoc = S;
682 return Op;
683 }
684
Chris Lattner3a697562010-10-28 17:20:03 +0000685 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
686 ARMOperand *Op = new ARMOperand(Token);
Sean Callanan76264762010-04-02 22:27:05 +0000687 Op->Tok.Data = Str.data();
688 Op->Tok.Length = Str.size();
689 Op->StartLoc = S;
690 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000691 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000692 }
693
Bill Wendling50d0f582010-11-18 23:43:05 +0000694 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Chris Lattner3a697562010-10-28 17:20:03 +0000695 ARMOperand *Op = new ARMOperand(Register);
Sean Callanan76264762010-04-02 22:27:05 +0000696 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +0000697 Op->StartLoc = S;
698 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000699 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000700 }
701
Owen Anderson00828302011-03-18 22:50:18 +0000702 static ARMOperand *CreateShifter(ARM_AM::ShiftOpc ShTy,
703 SMLoc S, SMLoc E) {
704 ARMOperand *Op = new ARMOperand(Shifter);
705 Op->Shift.ShiftTy = ShTy;
706 Op->StartLoc = S;
707 Op->EndLoc = E;
708 return Op;
709 }
710
Bill Wendling7729e062010-11-09 22:44:22 +0000711 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +0000712 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000713 SMLoc StartLoc, SMLoc EndLoc) {
Bill Wendling0f630752010-11-17 04:32:08 +0000714 KindTy Kind = RegisterList;
715
716 if (ARM::DPRRegClass.contains(Regs.front().first))
717 Kind = DPRRegisterList;
718 else if (ARM::SPRRegClass.contains(Regs.front().first))
719 Kind = SPRRegisterList;
720
721 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +0000722 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000723 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +0000724 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +0000725 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000726 Op->StartLoc = StartLoc;
727 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000728 return Op;
729 }
730
Chris Lattner3a697562010-10-28 17:20:03 +0000731 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
732 ARMOperand *Op = new ARMOperand(Immediate);
Sean Callanan76264762010-04-02 22:27:05 +0000733 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +0000734 Op->StartLoc = S;
735 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000736 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +0000737 }
738
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000739 static ARMOperand *CreateMem(ARMII::AddrMode AddrMode, unsigned BaseRegNum,
740 bool OffsetIsReg, const MCExpr *Offset,
741 int OffsetRegNum, bool OffsetRegShifted,
Owen Anderson00828302011-03-18 22:50:18 +0000742 enum ARM_AM::ShiftOpc ShiftType,
Chris Lattner3a697562010-10-28 17:20:03 +0000743 const MCExpr *ShiftAmount, bool Preindexed,
744 bool Postindexed, bool Negative, bool Writeback,
745 SMLoc S, SMLoc E) {
Daniel Dunbar023835d2011-01-18 05:34:05 +0000746 assert((OffsetRegNum == -1 || OffsetIsReg) &&
747 "OffsetRegNum must imply OffsetIsReg!");
748 assert((!OffsetRegShifted || OffsetIsReg) &&
749 "OffsetRegShifted must imply OffsetIsReg!");
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000750 assert((Offset || OffsetIsReg) &&
751 "Offset must exists unless register offset is used!");
Daniel Dunbar023835d2011-01-18 05:34:05 +0000752 assert((!ShiftAmount || (OffsetIsReg && OffsetRegShifted)) &&
753 "Cannot have shift amount without shifted register offset!");
754 assert((!Offset || !OffsetIsReg) &&
755 "Cannot have expression offset and register offset!");
756
Chris Lattner3a697562010-10-28 17:20:03 +0000757 ARMOperand *Op = new ARMOperand(Memory);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000758 Op->Mem.AddrMode = AddrMode;
Sean Callanan76264762010-04-02 22:27:05 +0000759 Op->Mem.BaseRegNum = BaseRegNum;
760 Op->Mem.OffsetIsReg = OffsetIsReg;
Daniel Dunbar2637dc92011-01-18 05:55:15 +0000761 if (OffsetIsReg)
762 Op->Mem.Offset.RegNum = OffsetRegNum;
763 else
764 Op->Mem.Offset.Value = Offset;
Sean Callanan76264762010-04-02 22:27:05 +0000765 Op->Mem.OffsetRegShifted = OffsetRegShifted;
766 Op->Mem.ShiftType = ShiftType;
767 Op->Mem.ShiftAmount = ShiftAmount;
768 Op->Mem.Preindexed = Preindexed;
769 Op->Mem.Postindexed = Postindexed;
770 Op->Mem.Negative = Negative;
771 Op->Mem.Writeback = Writeback;
Jim Grosbach16c74252010-10-29 14:46:02 +0000772
Sean Callanan76264762010-04-02 22:27:05 +0000773 Op->StartLoc = S;
774 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000775 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000776 }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000777
778 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
779 ARMOperand *Op = new ARMOperand(MemBarrierOpt);
780 Op->MBOpt.Val = Opt;
781 Op->StartLoc = S;
782 Op->EndLoc = S;
783 return Op;
784 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000785
786 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
787 ARMOperand *Op = new ARMOperand(ProcIFlags);
788 Op->IFlags.Val = IFlags;
789 Op->StartLoc = S;
790 Op->EndLoc = S;
791 return Op;
792 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000793
794 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
795 ARMOperand *Op = new ARMOperand(MSRMask);
796 Op->MMask.Val = MMask;
797 Op->StartLoc = S;
798 Op->EndLoc = S;
799 return Op;
800 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000801};
802
803} // end anonymous namespace.
804
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000805void ARMOperand::dump(raw_ostream &OS) const {
806 switch (Kind) {
807 case CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000808 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000809 break;
Jim Grosbachd67641b2010-12-06 18:21:12 +0000810 case CCOut:
811 OS << "<ccout " << getReg() << ">";
812 break;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000813 case CoprocNum:
814 OS << "<coprocessor number: " << getCoproc() << ">";
815 break;
816 case CoprocReg:
817 OS << "<coprocessor register: " << getCoproc() << ">";
818 break;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000819 case MSRMask:
820 OS << "<mask: " << getMSRMask() << ">";
821 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000822 case Immediate:
823 getImm()->print(OS);
824 break;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000825 case MemBarrierOpt:
826 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
827 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000828 case Memory:
Daniel Dunbar6ec56202011-01-18 05:55:21 +0000829 OS << "<memory "
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000830 << "am:" << ARMII::AddrModeToString(getMemAddrMode())
831 << " base:" << getMemBaseRegNum();
Daniel Dunbar6ec56202011-01-18 05:55:21 +0000832 if (getMemOffsetIsReg()) {
833 OS << " offset:<register " << getMemOffsetRegNum();
834 if (getMemOffsetRegShifted()) {
835 OS << " offset-shift-type:" << getMemShiftType();
836 OS << " offset-shift-amount:" << *getMemShiftAmount();
837 }
838 } else {
839 OS << " offset:" << *getMemOffset();
840 }
841 if (getMemOffsetIsReg())
842 OS << " (offset-is-reg)";
843 if (getMemPreindexed())
844 OS << " (pre-indexed)";
845 if (getMemPostindexed())
846 OS << " (post-indexed)";
847 if (getMemNegative())
848 OS << " (negative)";
849 if (getMemWriteback())
850 OS << " (writeback)";
851 OS << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000852 break;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000853 case ProcIFlags: {
854 OS << "<ARM_PROC::";
855 unsigned IFlags = getProcIFlags();
856 for (int i=2; i >= 0; --i)
857 if (IFlags & (1 << i))
858 OS << ARM_PROC::IFlagsToString(1 << i);
859 OS << ">";
860 break;
861 }
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000862 case Register:
Bill Wendling50d0f582010-11-18 23:43:05 +0000863 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000864 break;
Owen Anderson00828302011-03-18 22:50:18 +0000865 case Shifter:
866 OS << "<shifter " << getShiftOpcStr(Shift.ShiftTy) << ">";
867 break;
Bill Wendling0f630752010-11-17 04:32:08 +0000868 case RegisterList:
869 case DPRRegisterList:
870 case SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +0000871 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000872
Bill Wendling5fa22a12010-11-09 23:28:44 +0000873 const SmallVectorImpl<unsigned> &RegList = getRegList();
874 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000875 I = RegList.begin(), E = RegList.end(); I != E; ) {
876 OS << *I;
877 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000878 }
879
880 OS << ">";
881 break;
882 }
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000883 case Token:
884 OS << "'" << getToken() << "'";
885 break;
886 }
887}
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000888
889/// @name Auto-generated Match Functions
890/// {
891
892static unsigned MatchRegisterName(StringRef Name);
893
894/// }
895
Bob Wilson69df7232011-02-03 21:46:10 +0000896bool ARMAsmParser::ParseRegister(unsigned &RegNo,
897 SMLoc &StartLoc, SMLoc &EndLoc) {
Roman Divackybf755322011-01-27 17:14:22 +0000898 RegNo = TryParseRegister();
899
900 return (RegNo == (unsigned)-1);
901}
902
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000903/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +0000904/// and if it is a register name the token is eaten and the register number is
905/// returned. Otherwise return -1.
906///
907int ARMAsmParser::TryParseRegister() {
908 const AsmToken &Tok = Parser.getTok();
909 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
Jim Grosbachd4462a52010-11-01 16:44:21 +0000910
Chris Lattnere5658fa2010-10-30 04:09:10 +0000911 // FIXME: Validate register for the current architecture; we have to do
912 // validation later, so maybe there is no need for this here.
Owen Anderson0c9f2502011-01-13 22:50:36 +0000913 std::string upperCase = Tok.getString().str();
914 std::string lowerCase = LowercaseString(upperCase);
915 unsigned RegNum = MatchRegisterName(lowerCase);
916 if (!RegNum) {
917 RegNum = StringSwitch<unsigned>(lowerCase)
918 .Case("r13", ARM::SP)
919 .Case("r14", ARM::LR)
920 .Case("r15", ARM::PC)
921 .Case("ip", ARM::R12)
922 .Default(0);
923 }
924 if (!RegNum) return -1;
Bob Wilson69df7232011-02-03 21:46:10 +0000925
Chris Lattnere5658fa2010-10-30 04:09:10 +0000926 Parser.Lex(); // Eat identifier token.
927 return RegNum;
928}
Jim Grosbachd4462a52010-11-01 16:44:21 +0000929
Owen Anderson00828302011-03-18 22:50:18 +0000930/// Try to parse a register name. The token must be an Identifier when called,
931/// and if it is a register name the token is eaten and the register number is
932/// returned. Otherwise return -1.
933///
934bool ARMAsmParser::TryParseShiftRegister(
935 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
936 SMLoc S = Parser.getTok().getLoc();
937 const AsmToken &Tok = Parser.getTok();
938 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
939
940 std::string upperCase = Tok.getString().str();
941 std::string lowerCase = LowercaseString(upperCase);
942 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
943 .Case("lsl", ARM_AM::lsl)
944 .Case("lsr", ARM_AM::lsr)
945 .Case("asr", ARM_AM::asr)
946 .Case("ror", ARM_AM::ror)
947 .Case("rrx", ARM_AM::rrx)
948 .Default(ARM_AM::no_shift);
949
950 if (ShiftTy == ARM_AM::no_shift)
951 return true;
952
953 Parser.Lex(); // Eat shift-type operand;
954 int RegNum = TryParseRegister();
955 if (RegNum == -1)
956 return Error(Parser.getTok().getLoc(), "register expected");
957
958 Operands.push_back(ARMOperand::CreateReg(RegNum,S, Parser.getTok().getLoc()));
959 Operands.push_back(ARMOperand::CreateShifter(ShiftTy,
960 S, Parser.getTok().getLoc()));
961
962 return false;
963}
964
965
Bill Wendling50d0f582010-11-18 23:43:05 +0000966/// Try to parse a register name. The token must be an Identifier when called.
967/// If it's a register, an AsmOperand is created. Another AsmOperand is created
968/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +0000969///
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000970/// TODO this is likely to change to allow different register types and or to
971/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +0000972bool ARMAsmParser::
973TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +0000974 SMLoc S = Parser.getTok().getLoc();
975 int RegNo = TryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +0000976 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +0000977 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +0000978
Bill Wendling50d0f582010-11-18 23:43:05 +0000979 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000980
Chris Lattnere5658fa2010-10-30 04:09:10 +0000981 const AsmToken &ExclaimTok = Parser.getTok();
982 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +0000983 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
984 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +0000985 Parser.Lex(); // Eat exclaim token
Kevin Enderby99e6d4e2009-10-07 18:01:35 +0000986 }
987
Bill Wendling50d0f582010-11-18 23:43:05 +0000988 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000989}
990
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000991/// MatchCoprocessorOperandName - Try to parse an coprocessor related
992/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
993/// "c5", ...
994static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000995 // Use the same layout as the tablegen'erated register name matcher. Ugly,
996 // but efficient.
997 switch (Name.size()) {
998 default: break;
999 case 2:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001000 if (Name[0] != CoprocOp)
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001001 return -1;
1002 switch (Name[1]) {
1003 default: return -1;
1004 case '0': return 0;
1005 case '1': return 1;
1006 case '2': return 2;
1007 case '3': return 3;
1008 case '4': return 4;
1009 case '5': return 5;
1010 case '6': return 6;
1011 case '7': return 7;
1012 case '8': return 8;
1013 case '9': return 9;
1014 }
1015 break;
1016 case 3:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001017 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001018 return -1;
1019 switch (Name[2]) {
1020 default: return -1;
1021 case '0': return 10;
1022 case '1': return 11;
1023 case '2': return 12;
1024 case '3': return 13;
1025 case '4': return 14;
1026 case '5': return 15;
1027 }
1028 break;
1029 }
1030
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001031 return -1;
1032}
1033
Jim Grosbachf922c472011-02-12 01:34:40 +00001034/// tryParseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001035/// token must be an Identifier when called, and if it is a coprocessor
1036/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00001037ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1038tryParseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001039 SMLoc S = Parser.getTok().getLoc();
1040 const AsmToken &Tok = Parser.getTok();
1041 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1042
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001043 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001044 if (Num == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00001045 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001046
1047 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001048 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00001049 return MatchOperand_Success;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001050}
1051
Jim Grosbachf922c472011-02-12 01:34:40 +00001052/// tryParseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001053/// token must be an Identifier when called, and if it is a coprocessor
1054/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00001055ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1056tryParseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001057 SMLoc S = Parser.getTok().getLoc();
1058 const AsmToken &Tok = Parser.getTok();
1059 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1060
1061 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
1062 if (Reg == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00001063 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001064
1065 Parser.Lex(); // Eat identifier token.
1066 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00001067 return MatchOperand_Success;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001068}
1069
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001070/// Parse a register list, return it if successful else return null. The first
1071/// token must be a '{' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00001072bool ARMAsmParser::
1073ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +00001074 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00001075 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +00001076 SMLoc S = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001077
Bill Wendling7729e062010-11-09 22:44:22 +00001078 // Read the rest of the registers in the list.
1079 unsigned PrevRegNum = 0;
Bill Wendling5fa22a12010-11-09 23:28:44 +00001080 SmallVector<std::pair<unsigned, SMLoc>, 32> Registers;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001081
Bill Wendling7729e062010-11-09 22:44:22 +00001082 do {
Bill Wendlinge7176102010-11-06 22:36:58 +00001083 bool IsRange = Parser.getTok().is(AsmToken::Minus);
Bill Wendling7729e062010-11-09 22:44:22 +00001084 Parser.Lex(); // Eat non-identifier token.
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001085
Sean Callanan18b83232010-01-19 21:44:56 +00001086 const AsmToken &RegTok = Parser.getTok();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001087 SMLoc RegLoc = RegTok.getLoc();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001088 if (RegTok.isNot(AsmToken::Identifier)) {
1089 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001090 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001091 }
Bill Wendlinge7176102010-11-06 22:36:58 +00001092
Bill Wendling1d6a2652010-11-06 10:40:24 +00001093 int RegNum = TryParseRegister();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001094 if (RegNum == -1) {
1095 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001096 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001097 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001098
Bill Wendlinge7176102010-11-06 22:36:58 +00001099 if (IsRange) {
1100 int Reg = PrevRegNum;
1101 do {
1102 ++Reg;
1103 Registers.push_back(std::make_pair(Reg, RegLoc));
1104 } while (Reg != RegNum);
1105 } else {
1106 Registers.push_back(std::make_pair(RegNum, RegLoc));
1107 }
1108
1109 PrevRegNum = RegNum;
Bill Wendling7729e062010-11-09 22:44:22 +00001110 } while (Parser.getTok().is(AsmToken::Comma) ||
1111 Parser.getTok().is(AsmToken::Minus));
Bill Wendlinge7176102010-11-06 22:36:58 +00001112
1113 // Process the right curly brace of the list.
Sean Callanan18b83232010-01-19 21:44:56 +00001114 const AsmToken &RCurlyTok = Parser.getTok();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001115 if (RCurlyTok.isNot(AsmToken::RCurly)) {
1116 Error(RCurlyTok.getLoc(), "'}' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001117 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001118 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001119
Bill Wendlinge7176102010-11-06 22:36:58 +00001120 SMLoc E = RCurlyTok.getLoc();
1121 Parser.Lex(); // Eat right curly brace token.
Jim Grosbach03f44a02010-11-29 23:18:01 +00001122
Bill Wendlinge7176102010-11-06 22:36:58 +00001123 // Verify the register list.
Bill Wendling5fa22a12010-11-09 23:28:44 +00001124 SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendlinge7176102010-11-06 22:36:58 +00001125 RI = Registers.begin(), RE = Registers.end();
1126
Bill Wendling7caebff2011-01-12 21:20:59 +00001127 unsigned HighRegNum = getARMRegisterNumbering(RI->first);
Bill Wendling8e8b18b2010-11-09 23:45:59 +00001128 bool EmittedWarning = false;
1129
Bill Wendling7caebff2011-01-12 21:20:59 +00001130 DenseMap<unsigned, bool> RegMap;
1131 RegMap[HighRegNum] = true;
1132
Bill Wendlinge7176102010-11-06 22:36:58 +00001133 for (++RI; RI != RE; ++RI) {
Bill Wendling7729e062010-11-09 22:44:22 +00001134 const std::pair<unsigned, SMLoc> &RegInfo = *RI;
Bill Wendling7caebff2011-01-12 21:20:59 +00001135 unsigned Reg = getARMRegisterNumbering(RegInfo.first);
Bill Wendlinge7176102010-11-06 22:36:58 +00001136
Bill Wendling8e8b18b2010-11-09 23:45:59 +00001137 if (RegMap[Reg]) {
Bill Wendlinge7176102010-11-06 22:36:58 +00001138 Error(RegInfo.second, "register duplicated in register list");
Bill Wendling50d0f582010-11-18 23:43:05 +00001139 return true;
Bill Wendlinge7176102010-11-06 22:36:58 +00001140 }
1141
Bill Wendling8e8b18b2010-11-09 23:45:59 +00001142 if (!EmittedWarning && Reg < HighRegNum)
Bill Wendlinge7176102010-11-06 22:36:58 +00001143 Warning(RegInfo.second,
1144 "register not in ascending order in register list");
1145
Bill Wendling8e8b18b2010-11-09 23:45:59 +00001146 RegMap[Reg] = true;
1147 HighRegNum = std::max(Reg, HighRegNum);
Bill Wendlinge7176102010-11-06 22:36:58 +00001148 }
1149
Bill Wendling50d0f582010-11-18 23:43:05 +00001150 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
1151 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001152}
1153
Jim Grosbachf922c472011-02-12 01:34:40 +00001154/// tryParseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
1155ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1156tryParseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001157 SMLoc S = Parser.getTok().getLoc();
1158 const AsmToken &Tok = Parser.getTok();
1159 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1160 StringRef OptStr = Tok.getString();
1161
1162 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()))
1163 .Case("sy", ARM_MB::SY)
1164 .Case("st", ARM_MB::ST)
1165 .Case("ish", ARM_MB::ISH)
1166 .Case("ishst", ARM_MB::ISHST)
1167 .Case("nsh", ARM_MB::NSH)
1168 .Case("nshst", ARM_MB::NSHST)
1169 .Case("osh", ARM_MB::OSH)
1170 .Case("oshst", ARM_MB::OSHST)
1171 .Default(~0U);
1172
1173 if (Opt == ~0U)
Jim Grosbachf922c472011-02-12 01:34:40 +00001174 return MatchOperand_NoMatch;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001175
1176 Parser.Lex(); // Eat identifier token.
1177 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00001178 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001179}
1180
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +00001181/// tryParseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001182ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1183tryParseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1184 SMLoc S = Parser.getTok().getLoc();
1185 const AsmToken &Tok = Parser.getTok();
1186 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1187 StringRef IFlagsStr = Tok.getString();
1188
1189 unsigned IFlags = 0;
1190 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
1191 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
1192 .Case("a", ARM_PROC::A)
1193 .Case("i", ARM_PROC::I)
1194 .Case("f", ARM_PROC::F)
1195 .Default(~0U);
1196
1197 // If some specific iflag is already set, it means that some letter is
1198 // present more than once, this is not acceptable.
1199 if (Flag == ~0U || (IFlags & Flag))
1200 return MatchOperand_NoMatch;
1201
1202 IFlags |= Flag;
1203 }
1204
1205 Parser.Lex(); // Eat identifier token.
1206 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
1207 return MatchOperand_Success;
1208}
1209
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001210/// tryParseMSRMaskOperand - Try to parse mask flags from MSR instruction.
1211ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1212tryParseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1213 SMLoc S = Parser.getTok().getLoc();
1214 const AsmToken &Tok = Parser.getTok();
1215 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1216 StringRef Mask = Tok.getString();
1217
1218 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
1219 size_t Start = 0, Next = Mask.find('_');
1220 StringRef Flags = "";
1221 StringRef SpecReg = Mask.slice(Start, Next);
1222 if (Next != StringRef::npos)
1223 Flags = Mask.slice(Next+1, Mask.size());
1224
1225 // FlagsVal contains the complete mask:
1226 // 3-0: Mask
1227 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
1228 unsigned FlagsVal = 0;
1229
1230 if (SpecReg == "apsr") {
1231 FlagsVal = StringSwitch<unsigned>(Flags)
1232 .Case("nzcvq", 0x8) // same as CPSR_c
1233 .Case("g", 0x4) // same as CPSR_s
1234 .Case("nzcvqg", 0xc) // same as CPSR_fs
1235 .Default(~0U);
1236
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00001237 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001238 if (!Flags.empty())
1239 return MatchOperand_NoMatch;
1240 else
1241 FlagsVal = 0; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00001242 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001243 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00001244 if (Flags == "all") // cpsr_all is an alias for cpsr_fc
1245 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001246 for (int i = 0, e = Flags.size(); i != e; ++i) {
1247 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
1248 .Case("c", 1)
1249 .Case("x", 2)
1250 .Case("s", 4)
1251 .Case("f", 8)
1252 .Default(~0U);
1253
1254 // If some specific flag is already set, it means that some letter is
1255 // present more than once, this is not acceptable.
1256 if (FlagsVal == ~0U || (FlagsVal & Flag))
1257 return MatchOperand_NoMatch;
1258 FlagsVal |= Flag;
1259 }
1260 } else // No match for special register.
1261 return MatchOperand_NoMatch;
1262
1263 // Special register without flags are equivalent to "fc" flags.
1264 if (!FlagsVal)
1265 FlagsVal = 0x9;
1266
1267 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
1268 if (SpecReg == "spsr")
1269 FlagsVal |= 16;
1270
1271 Parser.Lex(); // Eat identifier token.
1272 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
1273 return MatchOperand_Success;
1274}
1275
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001276/// tryParseMemMode2Operand - Try to parse memory addressing mode 2 operand.
1277ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1278tryParseMemMode2Operand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Matt Beaumont-Gaye3662cc2011-04-01 00:06:01 +00001279 assert(Parser.getTok().is(AsmToken::LBrac) && "Token is not a \"[\"");
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001280
1281 if (ParseMemory(Operands, ARMII::AddrMode2))
1282 return MatchOperand_NoMatch;
1283
1284 return MatchOperand_Success;
1285}
1286
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001287/// tryParseMemMode3Operand - Try to parse memory addressing mode 3 operand.
1288ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1289tryParseMemMode3Operand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1290 assert(Parser.getTok().is(AsmToken::LBrac) && "Token is not a \"[\"");
1291
1292 if (ParseMemory(Operands, ARMII::AddrMode3))
1293 return MatchOperand_NoMatch;
1294
1295 return MatchOperand_Success;
1296}
1297
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001298/// CvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
1299/// Needed here because the Asm Gen Matcher can't handle properly tied operands
1300/// when they refer multiple MIOperands inside a single one.
1301bool ARMAsmParser::
1302CvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
1303 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1304 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
1305
1306 // Create a writeback register dummy placeholder.
1307 Inst.addOperand(MCOperand::CreateImm(0));
1308
1309 ((ARMOperand*)Operands[3])->addMemMode2Operands(Inst, 3);
1310 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
1311 return true;
1312}
1313
1314/// CvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
1315/// Needed here because the Asm Gen Matcher can't handle properly tied operands
1316/// when they refer multiple MIOperands inside a single one.
1317bool ARMAsmParser::
1318CvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
1319 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1320 // Create a writeback register dummy placeholder.
1321 Inst.addOperand(MCOperand::CreateImm(0));
1322 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
1323 ((ARMOperand*)Operands[3])->addMemMode2Operands(Inst, 3);
1324 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
1325 return true;
1326}
1327
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001328/// CvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
1329/// Needed here because the Asm Gen Matcher can't handle properly tied operands
1330/// when they refer multiple MIOperands inside a single one.
1331bool ARMAsmParser::
1332CvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
1333 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1334 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
1335
1336 // Create a writeback register dummy placeholder.
1337 Inst.addOperand(MCOperand::CreateImm(0));
1338
1339 ((ARMOperand*)Operands[3])->addMemMode3Operands(Inst, 3);
1340 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
1341 return true;
1342}
1343
1344/// CvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
1345/// Needed here because the Asm Gen Matcher can't handle properly tied operands
1346/// when they refer multiple MIOperands inside a single one.
1347bool ARMAsmParser::
1348CvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
1349 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1350 // Create a writeback register dummy placeholder.
1351 Inst.addOperand(MCOperand::CreateImm(0));
1352 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
1353 ((ARMOperand*)Operands[3])->addMemMode3Operands(Inst, 3);
1354 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
1355 return true;
1356}
1357
Bill Wendlinge7176102010-11-06 22:36:58 +00001358/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001359/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00001360///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001361/// TODO Only preindexing and postindexing addressing are started, unindexed
1362/// with option, etc are still to do.
Bill Wendling50d0f582010-11-18 23:43:05 +00001363bool ARMAsmParser::
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001364ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
1365 ARMII::AddrMode AddrMode = ARMII::AddrModeNone) {
Sean Callanan76264762010-04-02 22:27:05 +00001366 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00001367 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00001368 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00001369 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00001370 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001371
Sean Callanan18b83232010-01-19 21:44:56 +00001372 const AsmToken &BaseRegTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +00001373 if (BaseRegTok.isNot(AsmToken::Identifier)) {
1374 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001375 return true;
Chris Lattner550276e2010-10-28 20:52:15 +00001376 }
Chris Lattnere5658fa2010-10-30 04:09:10 +00001377 int BaseRegNum = TryParseRegister();
1378 if (BaseRegNum == -1) {
Chris Lattner550276e2010-10-28 20:52:15 +00001379 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001380 return true;
Chris Lattner550276e2010-10-28 20:52:15 +00001381 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001382
Daniel Dunbar05710932011-01-18 05:34:17 +00001383 // The next token must either be a comma or a closing bracket.
1384 const AsmToken &Tok = Parser.getTok();
1385 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
1386 return true;
1387
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001388 bool Preindexed = false;
1389 bool Postindexed = false;
1390 bool OffsetIsReg = false;
1391 bool Negative = false;
1392 bool Writeback = false;
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001393 ARMOperand *WBOp = 0;
1394 int OffsetRegNum = -1;
1395 bool OffsetRegShifted = false;
Owen Anderson00828302011-03-18 22:50:18 +00001396 enum ARM_AM::ShiftOpc ShiftType = ARM_AM::lsl;
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001397 const MCExpr *ShiftAmount = 0;
1398 const MCExpr *Offset = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001399
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001400 // First look for preindexed address forms, that is after the "[Rn" we now
1401 // have to see if the next token is a comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001402 if (Tok.is(AsmToken::Comma)) {
1403 Preindexed = true;
Sean Callananb9a25b72010-01-19 20:27:46 +00001404 Parser.Lex(); // Eat comma token.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001405
Chris Lattner550276e2010-10-28 20:52:15 +00001406 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType, ShiftAmount,
1407 Offset, OffsetIsReg, OffsetRegNum, E))
Bill Wendling50d0f582010-11-18 23:43:05 +00001408 return true;
Sean Callanan18b83232010-01-19 21:44:56 +00001409 const AsmToken &RBracTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +00001410 if (RBracTok.isNot(AsmToken::RBrac)) {
1411 Error(RBracTok.getLoc(), "']' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001412 return true;
Chris Lattner550276e2010-10-28 20:52:15 +00001413 }
Sean Callanan76264762010-04-02 22:27:05 +00001414 E = RBracTok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00001415 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001416
Sean Callanan18b83232010-01-19 21:44:56 +00001417 const AsmToken &ExclaimTok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001418 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001419 // None of addrmode3 instruction uses "!"
1420 if (AddrMode == ARMII::AddrMode3)
1421 return true;
1422
Bill Wendling50d0f582010-11-18 23:43:05 +00001423 WBOp = ARMOperand::CreateToken(ExclaimTok.getString(),
1424 ExclaimTok.getLoc());
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001425 Writeback = true;
Sean Callananb9a25b72010-01-19 20:27:46 +00001426 Parser.Lex(); // Eat exclaim token
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001427 } else { // In addressing mode 2, pre-indexed mode always end with "!"
1428 if (AddrMode == ARMII::AddrMode2)
1429 Preindexed = false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001430 }
Daniel Dunbar05710932011-01-18 05:34:17 +00001431 } else {
1432 // The "[Rn" we have so far was not followed by a comma.
1433
Jim Grosbach80eb2332010-10-29 17:41:25 +00001434 // If there's anything other than the right brace, this is a post indexing
1435 // addressing form.
Sean Callanan76264762010-04-02 22:27:05 +00001436 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00001437 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001438
Sean Callanan18b83232010-01-19 21:44:56 +00001439 const AsmToken &NextTok = Parser.getTok();
Jim Grosbach03f44a02010-11-29 23:18:01 +00001440
Kevin Enderbye2a98dd2009-10-15 21:42:45 +00001441 if (NextTok.isNot(AsmToken::EndOfStatement)) {
Jim Grosbach80eb2332010-10-29 17:41:25 +00001442 Postindexed = true;
1443 Writeback = true;
Bill Wendling50d0f582010-11-18 23:43:05 +00001444
Chris Lattner550276e2010-10-28 20:52:15 +00001445 if (NextTok.isNot(AsmToken::Comma)) {
1446 Error(NextTok.getLoc(), "',' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001447 return true;
Chris Lattner550276e2010-10-28 20:52:15 +00001448 }
Bill Wendling50d0f582010-11-18 23:43:05 +00001449
Sean Callananb9a25b72010-01-19 20:27:46 +00001450 Parser.Lex(); // Eat comma token.
Bill Wendling50d0f582010-11-18 23:43:05 +00001451
Chris Lattner550276e2010-10-28 20:52:15 +00001452 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType,
Jim Grosbach16c74252010-10-29 14:46:02 +00001453 ShiftAmount, Offset, OffsetIsReg, OffsetRegNum,
Chris Lattner550276e2010-10-28 20:52:15 +00001454 E))
Bill Wendling50d0f582010-11-18 23:43:05 +00001455 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001456 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001457 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001458
1459 // Force Offset to exist if used.
1460 if (!OffsetIsReg) {
1461 if (!Offset)
1462 Offset = MCConstantExpr::Create(0, getContext());
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001463 } else {
1464 if (AddrMode == ARMII::AddrMode3 && OffsetRegShifted) {
1465 Error(E, "shift amount not supported");
1466 return true;
1467 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001468 }
1469
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001470 Operands.push_back(ARMOperand::CreateMem(AddrMode, BaseRegNum, OffsetIsReg,
1471 Offset, OffsetRegNum, OffsetRegShifted,
1472 ShiftType, ShiftAmount, Preindexed,
1473 Postindexed, Negative, Writeback, S, E));
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001474 if (WBOp)
1475 Operands.push_back(WBOp);
1476
1477 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001478}
1479
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001480/// Parse the offset of a memory operand after we have seen "[Rn," or "[Rn],"
1481/// we will parse the following (were +/- means that a plus or minus is
1482/// optional):
1483/// +/-Rm
1484/// +/-Rm, shift
1485/// #offset
1486/// we return false on success or an error otherwise.
1487bool ARMAsmParser::ParseMemoryOffsetReg(bool &Negative,
Sean Callanan76264762010-04-02 22:27:05 +00001488 bool &OffsetRegShifted,
Owen Anderson00828302011-03-18 22:50:18 +00001489 enum ARM_AM::ShiftOpc &ShiftType,
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001490 const MCExpr *&ShiftAmount,
1491 const MCExpr *&Offset,
1492 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +00001493 int &OffsetRegNum,
1494 SMLoc &E) {
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001495 Negative = false;
1496 OffsetRegShifted = false;
1497 OffsetIsReg = false;
1498 OffsetRegNum = -1;
Sean Callanan18b83232010-01-19 21:44:56 +00001499 const AsmToken &NextTok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +00001500 E = NextTok.getLoc();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001501 if (NextTok.is(AsmToken::Plus))
Sean Callananb9a25b72010-01-19 20:27:46 +00001502 Parser.Lex(); // Eat plus token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001503 else if (NextTok.is(AsmToken::Minus)) {
1504 Negative = true;
Sean Callananb9a25b72010-01-19 20:27:46 +00001505 Parser.Lex(); // Eat minus token
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001506 }
1507 // See if there is a register following the "[Rn," or "[Rn]," we have so far.
Sean Callanan18b83232010-01-19 21:44:56 +00001508 const AsmToken &OffsetRegTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001509 if (OffsetRegTok.is(AsmToken::Identifier)) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00001510 SMLoc CurLoc = OffsetRegTok.getLoc();
1511 OffsetRegNum = TryParseRegister();
1512 if (OffsetRegNum != -1) {
Chris Lattner550276e2010-10-28 20:52:15 +00001513 OffsetIsReg = true;
Chris Lattnere5658fa2010-10-30 04:09:10 +00001514 E = CurLoc;
Sean Callanan76264762010-04-02 22:27:05 +00001515 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001516 }
Jim Grosbachd4462a52010-11-01 16:44:21 +00001517
Bill Wendling12f40e92010-11-06 10:51:53 +00001518 // If we parsed a register as the offset then there can be a shift after that.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001519 if (OffsetRegNum != -1) {
1520 // Look for a comma then a shift
Sean Callanan18b83232010-01-19 21:44:56 +00001521 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001522 if (Tok.is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00001523 Parser.Lex(); // Eat comma token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001524
Sean Callanan18b83232010-01-19 21:44:56 +00001525 const AsmToken &Tok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +00001526 if (ParseShift(ShiftType, ShiftAmount, E))
Duncan Sands34727662010-07-12 08:16:59 +00001527 return Error(Tok.getLoc(), "shift expected");
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001528 OffsetRegShifted = true;
1529 }
1530 }
1531 else { // the "[Rn," or "[Rn,]" we have so far was not followed by "Rm"
1532 // Look for #offset following the "[Rn," or "[Rn],"
Sean Callanan18b83232010-01-19 21:44:56 +00001533 const AsmToken &HashTok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001534 if (HashTok.isNot(AsmToken::Hash))
1535 return Error(HashTok.getLoc(), "'#' expected");
Jim Grosbach16c74252010-10-29 14:46:02 +00001536
Sean Callananb9a25b72010-01-19 20:27:46 +00001537 Parser.Lex(); // Eat hash token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001538
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001539 if (getParser().ParseExpression(Offset))
1540 return true;
Sean Callanan76264762010-04-02 22:27:05 +00001541 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001542 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001543 return false;
1544}
1545
1546/// ParseShift as one of these two:
1547/// ( lsl | lsr | asr | ror ) , # shift_amount
1548/// rrx
1549/// and returns true if it parses a shift otherwise it returns false.
Owen Anderson00828302011-03-18 22:50:18 +00001550bool ARMAsmParser::ParseShift(ARM_AM::ShiftOpc &St,
1551 const MCExpr *&ShiftAmount, SMLoc &E) {
Sean Callanan18b83232010-01-19 21:44:56 +00001552 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001553 if (Tok.isNot(AsmToken::Identifier))
1554 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00001555 StringRef ShiftName = Tok.getString();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001556 if (ShiftName == "lsl" || ShiftName == "LSL")
Owen Anderson00828302011-03-18 22:50:18 +00001557 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001558 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00001559 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001560 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00001561 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001562 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00001563 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001564 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00001565 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001566 else
1567 return true;
Sean Callananb9a25b72010-01-19 20:27:46 +00001568 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001569
1570 // Rrx stands alone.
Owen Anderson00828302011-03-18 22:50:18 +00001571 if (St == ARM_AM::rrx)
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001572 return false;
1573
1574 // Otherwise, there must be a '#' and a shift amount.
Sean Callanan18b83232010-01-19 21:44:56 +00001575 const AsmToken &HashTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001576 if (HashTok.isNot(AsmToken::Hash))
1577 return Error(HashTok.getLoc(), "'#' expected");
Sean Callananb9a25b72010-01-19 20:27:46 +00001578 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001579
1580 if (getParser().ParseExpression(ShiftAmount))
1581 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001582
1583 return false;
1584}
1585
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001586/// Parse a arm instruction operand. For now this parses the operand regardless
1587/// of the mnemonic.
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001588bool ARMAsmParser::ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001589 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00001590 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001591
1592 // Check if the current operand has a custom associated parser, if so, try to
1593 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00001594 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
1595 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001596 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00001597 // If there wasn't a custom match, try the generic matcher below. Otherwise,
1598 // there was a match, but an error occurred, in which case, just return that
1599 // the operand parsing failed.
1600 if (ResTy == MatchOperand_ParseFail)
1601 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001602
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001603 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00001604 default:
1605 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00001606 return true;
Kevin Enderby67b212e2011-01-13 20:32:36 +00001607 case AsmToken::Identifier:
Bill Wendling50d0f582010-11-18 23:43:05 +00001608 if (!TryParseRegisterWithWriteBack(Operands))
1609 return false;
Owen Anderson00828302011-03-18 22:50:18 +00001610 if (!TryParseShiftRegister(Operands))
1611 return false;
1612
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001613
1614 // Fall though for the Identifier case that is not a register or a
1615 // special name.
Kevin Enderby67b212e2011-01-13 20:32:36 +00001616 case AsmToken::Integer: // things like 1f and 2b as a branch targets
1617 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00001618 // This was not a register so parse other operands that start with an
1619 // identifier (like labels) as expressions and create them as immediates.
1620 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00001621 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00001622 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00001623 return true;
Sean Callanan76264762010-04-02 22:27:05 +00001624 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00001625 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
1626 return false;
1627 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001628 case AsmToken::LBrac:
Bill Wendling50d0f582010-11-18 23:43:05 +00001629 return ParseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001630 case AsmToken::LCurly:
Bill Wendling50d0f582010-11-18 23:43:05 +00001631 return ParseRegisterList(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001632 case AsmToken::Hash:
Kevin Enderby079469f2009-10-13 23:33:38 +00001633 // #42 -> immediate.
1634 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
Sean Callanan76264762010-04-02 22:27:05 +00001635 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00001636 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001637 const MCExpr *ImmVal;
1638 if (getParser().ParseExpression(ImmVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00001639 return true;
Sean Callanan76264762010-04-02 22:27:05 +00001640 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00001641 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
1642 return false;
Jason W Kim9081b4b2011-01-11 23:53:41 +00001643 case AsmToken::Colon: {
1644 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00001645 // FIXME: Check it's an expression prefix,
1646 // e.g. (FOO - :lower16:BAR) isn't legal.
1647 ARMMCExpr::VariantKind RefKind;
Jason W Kim9081b4b2011-01-11 23:53:41 +00001648 if (ParsePrefix(RefKind))
1649 return true;
1650
Evan Cheng75972122011-01-13 07:58:56 +00001651 const MCExpr *SubExprVal;
1652 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00001653 return true;
1654
Evan Cheng75972122011-01-13 07:58:56 +00001655 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
1656 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00001657 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00001658 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00001659 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001660 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00001661 }
1662}
1663
Evan Cheng75972122011-01-13 07:58:56 +00001664// ParsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
1665// :lower16: and :upper16:.
1666bool ARMAsmParser::ParsePrefix(ARMMCExpr::VariantKind &RefKind) {
1667 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00001668
1669 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00001670 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00001671 Parser.Lex(); // Eat ':'
1672
1673 if (getLexer().isNot(AsmToken::Identifier)) {
1674 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
1675 return true;
1676 }
1677
1678 StringRef IDVal = Parser.getTok().getIdentifier();
1679 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00001680 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00001681 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00001682 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00001683 } else {
1684 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
1685 return true;
1686 }
1687 Parser.Lex();
1688
1689 if (getLexer().isNot(AsmToken::Colon)) {
1690 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
1691 return true;
1692 }
1693 Parser.Lex(); // Eat the last ':'
1694 return false;
1695}
1696
1697const MCExpr *
1698ARMAsmParser::ApplyPrefixToExpr(const MCExpr *E,
1699 MCSymbolRefExpr::VariantKind Variant) {
1700 // Recurse over the given expression, rebuilding it to apply the given variant
1701 // to the leftmost symbol.
1702 if (Variant == MCSymbolRefExpr::VK_None)
1703 return E;
1704
1705 switch (E->getKind()) {
1706 case MCExpr::Target:
1707 llvm_unreachable("Can't handle target expr yet");
1708 case MCExpr::Constant:
1709 llvm_unreachable("Can't handle lower16/upper16 of constant yet");
1710
1711 case MCExpr::SymbolRef: {
1712 const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E);
1713
1714 if (SRE->getKind() != MCSymbolRefExpr::VK_None)
1715 return 0;
1716
1717 return MCSymbolRefExpr::Create(&SRE->getSymbol(), Variant, getContext());
1718 }
1719
1720 case MCExpr::Unary:
1721 llvm_unreachable("Can't handle unary expressions yet");
1722
1723 case MCExpr::Binary: {
1724 const MCBinaryExpr *BE = cast<MCBinaryExpr>(E);
1725 const MCExpr *LHS = ApplyPrefixToExpr(BE->getLHS(), Variant);
1726 const MCExpr *RHS = BE->getRHS();
1727 if (!LHS)
1728 return 0;
1729
1730 return MCBinaryExpr::Create(BE->getOpcode(), LHS, RHS, getContext());
1731 }
1732 }
1733
1734 assert(0 && "Invalid expression kind!");
1735 return 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001736}
1737
Daniel Dunbar352e1482011-01-11 15:59:50 +00001738/// \brief Given a mnemonic, split out possible predication code and carry
1739/// setting letters to form a canonical mnemonic and flags.
1740//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001741// FIXME: Would be nice to autogen this.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001742static StringRef SplitMnemonic(StringRef Mnemonic,
1743 unsigned &PredicationCode,
1744 bool &CarrySetting,
1745 unsigned &ProcessorIMod) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00001746 PredicationCode = ARMCC::AL;
1747 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001748 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00001749
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001750 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00001751 //
1752 // FIXME: Would be nice to autogen this.
Daniel Dunbar8ab11122011-01-10 21:01:03 +00001753 if (Mnemonic == "teq" || Mnemonic == "vceq" ||
1754 Mnemonic == "movs" ||
1755 Mnemonic == "svc" ||
1756 (Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
1757 Mnemonic == "vmls" || Mnemonic == "vnmls") ||
1758 Mnemonic == "vacge" || Mnemonic == "vcge" ||
1759 Mnemonic == "vclt" ||
1760 Mnemonic == "vacgt" || Mnemonic == "vcgt" ||
1761 Mnemonic == "vcle" ||
1762 (Mnemonic == "smlal" || Mnemonic == "umaal" || Mnemonic == "umlal" ||
1763 Mnemonic == "vabal" || Mnemonic == "vmlal" || Mnemonic == "vpadal" ||
Jim Grosbachd1f0bbe2011-06-27 20:59:10 +00001764 Mnemonic == "vqdmlal" || Mnemonic == "bics"))
Daniel Dunbar352e1482011-01-11 15:59:50 +00001765 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00001766
Daniel Dunbar352e1482011-01-11 15:59:50 +00001767 // First, split out any predication code.
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001768 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001769 .Case("eq", ARMCC::EQ)
1770 .Case("ne", ARMCC::NE)
1771 .Case("hs", ARMCC::HS)
Jim Grosbach660a9ec2011-06-27 20:40:29 +00001772 .Case("cs", ARMCC::HS)
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001773 .Case("lo", ARMCC::LO)
Jim Grosbach660a9ec2011-06-27 20:40:29 +00001774 .Case("cc", ARMCC::LO)
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001775 .Case("mi", ARMCC::MI)
1776 .Case("pl", ARMCC::PL)
1777 .Case("vs", ARMCC::VS)
1778 .Case("vc", ARMCC::VC)
1779 .Case("hi", ARMCC::HI)
1780 .Case("ls", ARMCC::LS)
1781 .Case("ge", ARMCC::GE)
1782 .Case("lt", ARMCC::LT)
1783 .Case("gt", ARMCC::GT)
1784 .Case("le", ARMCC::LE)
1785 .Case("al", ARMCC::AL)
1786 .Default(~0U);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001787 if (CC != ~0U) {
1788 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
Daniel Dunbar352e1482011-01-11 15:59:50 +00001789 PredicationCode = CC;
Bill Wendling52925b62010-10-29 23:50:21 +00001790 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001791
Daniel Dunbar352e1482011-01-11 15:59:50 +00001792 // Next, determine if we have a carry setting bit. We explicitly ignore all
1793 // the instructions we know end in 's'.
1794 if (Mnemonic.endswith("s") &&
1795 !(Mnemonic == "asrs" || Mnemonic == "cps" || Mnemonic == "mls" ||
1796 Mnemonic == "movs" || Mnemonic == "mrs" || Mnemonic == "smmls" ||
1797 Mnemonic == "vabs" || Mnemonic == "vcls" || Mnemonic == "vmls" ||
1798 Mnemonic == "vmrs" || Mnemonic == "vnmls" || Mnemonic == "vqabs" ||
1799 Mnemonic == "vrecps" || Mnemonic == "vrsqrts")) {
1800 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
1801 CarrySetting = true;
1802 }
1803
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001804 // The "cps" instruction can have a interrupt mode operand which is glued into
1805 // the mnemonic. Check if this is the case, split it and parse the imod op
1806 if (Mnemonic.startswith("cps")) {
1807 // Split out any imod code.
1808 unsigned IMod =
1809 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
1810 .Case("ie", ARM_PROC::IE)
1811 .Case("id", ARM_PROC::ID)
1812 .Default(~0U);
1813 if (IMod != ~0U) {
1814 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
1815 ProcessorIMod = IMod;
1816 }
1817 }
1818
Daniel Dunbar352e1482011-01-11 15:59:50 +00001819 return Mnemonic;
1820}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001821
1822/// \brief Given a canonical mnemonic, determine if the instruction ever allows
1823/// inclusion of carry set or predication code operands.
1824//
1825// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00001826void ARMAsmParser::
1827GetMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
1828 bool &CanAcceptPredicationCode) {
Jim Grosbachdf8fe992011-06-27 21:38:03 +00001829 bool isThumbOne = TM.getSubtarget<ARMSubtarget>().isThumb1Only();
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00001830 bool isThumb = TM.getSubtarget<ARMSubtarget>().isThumb();
1831
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001832 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
1833 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
1834 Mnemonic == "smull" || Mnemonic == "add" || Mnemonic == "adc" ||
1835 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Bruno Cardoso Lopesbe64b392011-05-27 23:46:09 +00001836 Mnemonic == "umlal" || Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001837 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
1838 Mnemonic == "sbc" || Mnemonic == "mla" || Mnemonic == "umull" ||
Bruno Cardoso Lopesbe64b392011-05-27 23:46:09 +00001839 Mnemonic == "eor" || Mnemonic == "smlal" ||
Jim Grosbachdf8fe992011-06-27 21:38:03 +00001840 (Mnemonic == "mov" && !isThumbOne)) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001841 CanAcceptCarrySet = true;
1842 } else {
1843 CanAcceptCarrySet = false;
1844 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001845
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001846 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
1847 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
1848 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
1849 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Bruno Cardoso Lopese47f3752011-01-20 19:18:32 +00001850 Mnemonic == "dsb" || Mnemonic == "movs" || Mnemonic == "isb" ||
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001851 Mnemonic == "clrex" || Mnemonic.startswith("cps")) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001852 CanAcceptPredicationCode = false;
1853 } else {
1854 CanAcceptPredicationCode = true;
1855 }
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001856
1857 if (isThumb)
1858 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Bruno Cardoso Lopesbe64b392011-05-27 23:46:09 +00001859 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp" ||
Jim Grosbachdf8fe992011-06-27 21:38:03 +00001860 (Mnemonic == "mov" && isThumbOne))
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001861 CanAcceptPredicationCode = false;
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001862}
1863
1864/// Parse an arm instruction mnemonic followed by its operands.
1865bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
1866 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1867 // Create the leading tokens for the mnemonic, split by '.' characters.
1868 size_t Start = 0, Next = Name.find('.');
1869 StringRef Head = Name.slice(Start, Next);
1870
Daniel Dunbar352e1482011-01-11 15:59:50 +00001871 // Split out the predication code and carry setting flag from the mnemonic.
1872 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001873 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00001874 bool CarrySetting;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001875 Head = SplitMnemonic(Head, PredicationCode, CarrySetting,
1876 ProcessorIMod);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001877
Chris Lattner3a697562010-10-28 17:20:03 +00001878 Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
Bill Wendling9717fa92010-11-21 10:56:05 +00001879
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001880 // Next, add the CCOut and ConditionCode operands, if needed.
1881 //
1882 // For mnemonics which can ever incorporate a carry setting bit or predication
1883 // code, our matching model involves us always generating CCOut and
1884 // ConditionCode operands to match the mnemonic "as written" and then we let
1885 // the matcher deal with finding the right instruction or generating an
1886 // appropriate error.
1887 bool CanAcceptCarrySet, CanAcceptPredicationCode;
1888 GetMnemonicAcceptInfo(Head, CanAcceptCarrySet, CanAcceptPredicationCode);
1889
1890 // Add the carry setting operand, if necessary.
1891 //
1892 // FIXME: It would be awesome if we could somehow invent a location such that
1893 // match errors on this operand would print a nice diagnostic about how the
1894 // 's' character in the mnemonic resulted in a CCOut operand.
1895 if (CanAcceptCarrySet) {
1896 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
1897 NameLoc));
1898 } else {
1899 // This mnemonic can't ever accept a carry set, but the user wrote one (or
1900 // misspelled another mnemonic).
1901
1902 // FIXME: Issue a nice error.
1903 }
1904
1905 // Add the predication code operand, if necessary.
1906 if (CanAcceptPredicationCode) {
1907 Operands.push_back(ARMOperand::CreateCondCode(
1908 ARMCC::CondCodes(PredicationCode), NameLoc));
1909 } else {
1910 // This mnemonic can't ever accept a predication code, but the user wrote
1911 // one (or misspelled another mnemonic).
1912
1913 // FIXME: Issue a nice error.
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001914 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001915
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001916 // Add the processor imod operand, if necessary.
1917 if (ProcessorIMod) {
1918 Operands.push_back(ARMOperand::CreateImm(
1919 MCConstantExpr::Create(ProcessorIMod, getContext()),
1920 NameLoc, NameLoc));
1921 } else {
1922 // This mnemonic can't ever accept a imod, but the user wrote
1923 // one (or misspelled another mnemonic).
1924
1925 // FIXME: Issue a nice error.
1926 }
1927
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001928 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00001929 while (Next != StringRef::npos) {
1930 Start = Next;
1931 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001932 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001933
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001934 Operands.push_back(ARMOperand::CreateToken(ExtraToken, NameLoc));
Daniel Dunbar5747b132010-08-11 06:37:16 +00001935 }
1936
1937 // Read the remaining operands.
1938 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001939 // Read the first operand.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001940 if (ParseOperand(Operands, Head)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00001941 Parser.EatToEndOfStatement();
1942 return true;
1943 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001944
1945 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00001946 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001947
1948 // Parse and remember the operand.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001949 if (ParseOperand(Operands, Head)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00001950 Parser.EatToEndOfStatement();
1951 return true;
1952 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001953 }
1954 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001955
Chris Lattnercbf8a982010-09-11 16:18:25 +00001956 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1957 Parser.EatToEndOfStatement();
Chris Lattner34e53142010-09-08 05:10:46 +00001958 return TokError("unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00001959 }
Bill Wendling146018f2010-11-06 21:42:12 +00001960
Chris Lattner34e53142010-09-08 05:10:46 +00001961 Parser.Lex(); // Consume the EndOfStatement
Chris Lattner98986712010-01-14 22:21:20 +00001962 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001963}
1964
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001965bool ARMAsmParser::
1966MatchAndEmitInstruction(SMLoc IDLoc,
1967 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
1968 MCStreamer &Out) {
1969 MCInst Inst;
1970 unsigned ErrorInfo;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001971 MatchResultTy MatchResult, MatchResult2;
1972 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1973 if (MatchResult != Match_Success) {
1974 // If we get a Match_InvalidOperand it might be some arithmetic instruction
1975 // that does not update the condition codes. So try adding a CCOut operand
1976 // with a value of reg0.
1977 if (MatchResult == Match_InvalidOperand) {
1978 Operands.insert(Operands.begin() + 1,
1979 ARMOperand::CreateCCOut(0,
1980 ((ARMOperand*)Operands[0])->getStartLoc()));
1981 MatchResult2 = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1982 if (MatchResult2 == Match_Success)
1983 MatchResult = Match_Success;
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001984 else {
1985 ARMOperand *CCOut = ((ARMOperand*)Operands[1]);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001986 Operands.erase(Operands.begin() + 1);
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001987 delete CCOut;
1988 }
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001989 }
1990 // If we get a Match_MnemonicFail it might be some arithmetic instruction
1991 // that updates the condition codes if it ends in 's'. So see if the
1992 // mnemonic ends in 's' and if so try removing the 's' and adding a CCOut
1993 // operand with a value of CPSR.
1994 else if(MatchResult == Match_MnemonicFail) {
1995 // Get the instruction mnemonic, which is the first token.
1996 StringRef Mnemonic = ((ARMOperand*)Operands[0])->getToken();
1997 if (Mnemonic.substr(Mnemonic.size()-1) == "s") {
1998 // removed the 's' from the mnemonic for matching.
1999 StringRef MnemonicNoS = Mnemonic.slice(0, Mnemonic.size() - 1);
2000 SMLoc NameLoc = ((ARMOperand*)Operands[0])->getStartLoc();
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00002001 ARMOperand *OldMnemonic = ((ARMOperand*)Operands[0]);
2002 Operands.erase(Operands.begin());
2003 delete OldMnemonic;
2004 Operands.insert(Operands.begin(),
Kevin Enderby193c3ac2010-12-09 19:19:43 +00002005 ARMOperand::CreateToken(MnemonicNoS, NameLoc));
2006 Operands.insert(Operands.begin() + 1,
2007 ARMOperand::CreateCCOut(ARM::CPSR, NameLoc));
2008 MatchResult2 = MatchInstructionImpl(Operands, Inst, ErrorInfo);
2009 if (MatchResult2 == Match_Success)
2010 MatchResult = Match_Success;
2011 else {
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00002012 ARMOperand *OldMnemonic = ((ARMOperand*)Operands[0]);
2013 Operands.erase(Operands.begin());
2014 delete OldMnemonic;
2015 Operands.insert(Operands.begin(),
Kevin Enderby193c3ac2010-12-09 19:19:43 +00002016 ARMOperand::CreateToken(Mnemonic, NameLoc));
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00002017 ARMOperand *CCOut = ((ARMOperand*)Operands[1]);
2018 Operands.erase(Operands.begin() + 1);
2019 delete CCOut;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00002020 }
2021 }
2022 }
2023 }
2024 switch (MatchResult) {
Chris Lattnere73d4f82010-10-28 21:41:58 +00002025 case Match_Success:
Chris Lattnerfa42fad2010-10-28 21:28:01 +00002026 Out.EmitInstruction(Inst);
2027 return false;
Chris Lattnere73d4f82010-10-28 21:41:58 +00002028 case Match_MissingFeature:
2029 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
2030 return true;
2031 case Match_InvalidOperand: {
2032 SMLoc ErrorLoc = IDLoc;
2033 if (ErrorInfo != ~0U) {
2034 if (ErrorInfo >= Operands.size())
2035 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00002036
Chris Lattnere73d4f82010-10-28 21:41:58 +00002037 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
2038 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
2039 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002040
Chris Lattnere73d4f82010-10-28 21:41:58 +00002041 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00002042 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00002043 case Match_MnemonicFail:
2044 return Error(IDLoc, "unrecognized instruction mnemonic");
Daniel Dunbarb4129152011-02-04 17:12:23 +00002045 case Match_ConversionFail:
2046 return Error(IDLoc, "unable to convert operands to instruction");
Chris Lattnere73d4f82010-10-28 21:41:58 +00002047 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002048
Eric Christopherc223e2b2010-10-29 09:26:59 +00002049 llvm_unreachable("Implement any new match types added!");
Bill Wendling146018f2010-11-06 21:42:12 +00002050 return true;
Chris Lattnerfa42fad2010-10-28 21:28:01 +00002051}
2052
Kevin Enderby515d5092009-10-15 20:48:48 +00002053/// ParseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002054bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
2055 StringRef IDVal = DirectiveID.getIdentifier();
2056 if (IDVal == ".word")
2057 return ParseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00002058 else if (IDVal == ".thumb")
2059 return ParseDirectiveThumb(DirectiveID.getLoc());
2060 else if (IDVal == ".thumb_func")
2061 return ParseDirectiveThumbFunc(DirectiveID.getLoc());
2062 else if (IDVal == ".code")
2063 return ParseDirectiveCode(DirectiveID.getLoc());
2064 else if (IDVal == ".syntax")
2065 return ParseDirectiveSyntax(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002066 return true;
2067}
2068
2069/// ParseDirectiveWord
2070/// ::= .word [ expression (, expression)* ]
2071bool ARMAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
2072 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2073 for (;;) {
2074 const MCExpr *Value;
2075 if (getParser().ParseExpression(Value))
2076 return true;
2077
Chris Lattneraaec2052010-01-19 19:46:13 +00002078 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002079
2080 if (getLexer().is(AsmToken::EndOfStatement))
2081 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00002082
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002083 // FIXME: Improve diagnostic.
2084 if (getLexer().isNot(AsmToken::Comma))
2085 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00002086 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002087 }
2088 }
2089
Sean Callananb9a25b72010-01-19 20:27:46 +00002090 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002091 return false;
2092}
2093
Kevin Enderby515d5092009-10-15 20:48:48 +00002094/// ParseDirectiveThumb
2095/// ::= .thumb
2096bool ARMAsmParser::ParseDirectiveThumb(SMLoc L) {
2097 if (getLexer().isNot(AsmToken::EndOfStatement))
2098 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00002099 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00002100
2101 // TODO: set thumb mode
2102 // TODO: tell the MC streamer the mode
2103 // getParser().getStreamer().Emit???();
2104 return false;
2105}
2106
2107/// ParseDirectiveThumbFunc
2108/// ::= .thumbfunc symbol_name
2109bool ARMAsmParser::ParseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00002110 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
2111 bool isMachO = MAI.hasSubsectionsViaSymbols();
2112 StringRef Name;
2113
2114 // Darwin asm has function name after .thumb_func direction
2115 // ELF doesn't
2116 if (isMachO) {
2117 const AsmToken &Tok = Parser.getTok();
2118 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
2119 return Error(L, "unexpected token in .thumb_func directive");
2120 Name = Tok.getString();
2121 Parser.Lex(); // Consume the identifier token.
2122 }
2123
Kevin Enderby515d5092009-10-15 20:48:48 +00002124 if (getLexer().isNot(AsmToken::EndOfStatement))
2125 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00002126 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00002127
Rafael Espindola64695402011-05-16 16:17:21 +00002128 // FIXME: assuming function name will be the line following .thumb_func
2129 if (!isMachO) {
2130 Name = Parser.getTok().getString();
2131 }
2132
Jim Grosbach642fc9c2010-11-05 22:33:53 +00002133 // Mark symbol as a thumb symbol.
2134 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
2135 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00002136 return false;
2137}
2138
2139/// ParseDirectiveSyntax
2140/// ::= .syntax unified | divided
2141bool ARMAsmParser::ParseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00002142 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00002143 if (Tok.isNot(AsmToken::Identifier))
2144 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00002145 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00002146 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00002147 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00002148 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00002149 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00002150 else
2151 return Error(L, "unrecognized syntax mode in .syntax directive");
2152
2153 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00002154 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00002155 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00002156
2157 // TODO tell the MC streamer the mode
2158 // getParser().getStreamer().Emit???();
2159 return false;
2160}
2161
2162/// ParseDirectiveCode
2163/// ::= .code 16 | 32
2164bool ARMAsmParser::ParseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00002165 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00002166 if (Tok.isNot(AsmToken::Integer))
2167 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00002168 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00002169 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00002170 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00002171 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00002172 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00002173 else
2174 return Error(L, "invalid operand to .code directive");
2175
2176 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00002177 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00002178 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00002179
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00002180 // FIXME: We need to be able switch subtargets at this point so that
2181 // MatchInstructionImpl() will work when it gets the AvailableFeatures which
2182 // includes Feature_IsThumb or not to match the right instructions. This is
2183 // blocked on the FIXME in llvm-mc.cpp when creating the TargetMachine.
2184 if (Val == 16){
2185 assert(TM.getSubtarget<ARMSubtarget>().isThumb() &&
2186 "switching between arm/thumb not yet suppported via .code 16)");
Jim Grosbach2a301702010-11-05 22:40:53 +00002187 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00002188 }
2189 else{
2190 assert(!TM.getSubtarget<ARMSubtarget>().isThumb() &&
2191 "switching between thumb/arm not yet suppported via .code 32)");
Jim Grosbach2a301702010-11-05 22:40:53 +00002192 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00002193 }
Jim Grosbach2a301702010-11-05 22:40:53 +00002194
Kevin Enderby515d5092009-10-15 20:48:48 +00002195 return false;
2196}
2197
Sean Callanan90b70972010-04-07 20:29:34 +00002198extern "C" void LLVMInitializeARMAsmLexer();
2199
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002200/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002201extern "C" void LLVMInitializeARMAsmParser() {
2202 RegisterAsmParser<ARMAsmParser> X(TheARMTarget);
2203 RegisterAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00002204 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002205}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002206
Chris Lattner0692ee62010-09-06 19:11:01 +00002207#define GET_REGISTER_MATCHER
2208#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002209#include "ARMGenAsmMatcher.inc"