blob: d97f8a5b769660b7cec29ca1c58691a8a552d001 [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"
Evan Chengebdeeab2011-07-08 01:53:10 +000023#include "llvm/MC/MCSubtargetInfo.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000024#include "llvm/Target/TargetRegistry.h"
25#include "llvm/Target/TargetAsmParser.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000026#include "llvm/Support/SourceMgr.h"
Daniel Dunbarfa315de2010-08-11 06:37:12 +000027#include "llvm/Support/raw_ostream.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000028#include "llvm/ADT/SmallVector.h"
Owen Anderson0c9f2502011-01-13 22:50:36 +000029#include "llvm/ADT/StringExtras.h"
Daniel Dunbar345a9a62010-08-11 06:37:20 +000030#include "llvm/ADT/StringSwitch.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000031#include "llvm/ADT/Twine.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000032
33#define GET_SUBTARGETINFO_ENUM
34#include "ARMGenSubtargetInfo.inc"
35
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000036using namespace llvm;
37
Chris Lattner3a697562010-10-28 17:20:03 +000038namespace {
Bill Wendling146018f2010-11-06 21:42:12 +000039
40class ARMOperand;
Jim Grosbach16c74252010-10-29 14:46:02 +000041
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000042class ARMAsmParser : public TargetAsmParser {
43 MCAsmParser &Parser;
Evan Cheng480cee52011-07-08 19:33:14 +000044 const MCSubtargetInfo *STI;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000045
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000046 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000047 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
48
49 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000050 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
51
Chris Lattnere5658fa2010-10-30 04:09:10 +000052 int TryParseRegister();
Roman Divackybf755322011-01-27 17:14:22 +000053 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Bill Wendling50d0f582010-11-18 23:43:05 +000054 bool TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Owen Anderson00828302011-03-18 22:50:18 +000055 bool TryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Bill Wendling50d0f582010-11-18 23:43:05 +000056 bool ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +000057 bool ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &,
58 ARMII::AddrMode AddrMode);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +000059 bool ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
Evan Cheng75972122011-01-13 07:58:56 +000060 bool ParsePrefix(ARMMCExpr::VariantKind &RefKind);
Jason W Kim9081b4b2011-01-11 23:53:41 +000061 const MCExpr *ApplyPrefixToExpr(const MCExpr *E,
62 MCSymbolRefExpr::VariantKind Variant);
63
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000064
Kevin Enderby9c41fa82009-10-30 22:55:57 +000065 bool ParseMemoryOffsetReg(bool &Negative,
66 bool &OffsetRegShifted,
Owen Anderson00828302011-03-18 22:50:18 +000067 enum ARM_AM::ShiftOpc &ShiftType,
Kevin Enderby9c41fa82009-10-30 22:55:57 +000068 const MCExpr *&ShiftAmount,
69 const MCExpr *&Offset,
70 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +000071 int &OffsetRegNum,
72 SMLoc &E);
Owen Anderson00828302011-03-18 22:50:18 +000073 bool ParseShift(enum ARM_AM::ShiftOpc &St,
74 const MCExpr *&ShiftAmount, SMLoc &E);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000075 bool ParseDirectiveWord(unsigned Size, SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000076 bool ParseDirectiveThumb(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000077 bool ParseDirectiveThumbFunc(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000078 bool ParseDirectiveCode(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000079 bool ParseDirectiveSyntax(SMLoc L);
80
Chris Lattner7036f8b2010-09-29 01:42:58 +000081 bool MatchAndEmitInstruction(SMLoc IDLoc,
Chris Lattner7c51a312010-09-29 01:50:45 +000082 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chris Lattnerfa42fad2010-10-28 21:28:01 +000083 MCStreamer &Out);
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +000084 void GetMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
85 bool &CanAcceptPredicationCode);
Jim Grosbach16c74252010-10-29 14:46:02 +000086
Evan Chengebdeeab2011-07-08 01:53:10 +000087 bool isThumb() const {
88 // FIXME: Can tablegen auto-generate this?
89 return (STI->getFeatureBits() & ARM::ModeThumb) != 0;
90 }
91
92 bool isThumbOne() const {
93 return isThumb() && (STI->getFeatureBits() & ARM::FeatureThumb2) == 0;
94 }
95
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000096 /// @name Auto-generated Match Functions
97 /// {
Daniel Dunbar3483aca2010-08-11 05:24:50 +000098
Chris Lattner0692ee62010-09-06 19:11:01 +000099#define GET_ASSEMBLER_HEADER
100#include "ARMGenAsmMatcher.inc"
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000101
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000102 /// }
103
Jim Grosbachf922c472011-02-12 01:34:40 +0000104 OperandMatchResultTy tryParseCoprocNumOperand(
105 SmallVectorImpl<MCParsedAsmOperand*>&);
106 OperandMatchResultTy tryParseCoprocRegOperand(
107 SmallVectorImpl<MCParsedAsmOperand*>&);
108 OperandMatchResultTy tryParseMemBarrierOptOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000109 SmallVectorImpl<MCParsedAsmOperand*>&);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000110 OperandMatchResultTy tryParseProcIFlagsOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000111 SmallVectorImpl<MCParsedAsmOperand*>&);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000112 OperandMatchResultTy tryParseMSRMaskOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000113 SmallVectorImpl<MCParsedAsmOperand*>&);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000114 OperandMatchResultTy tryParseMemMode2Operand(
115 SmallVectorImpl<MCParsedAsmOperand*>&);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000116 OperandMatchResultTy tryParseMemMode3Operand(
117 SmallVectorImpl<MCParsedAsmOperand*>&);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000118
119 // Asm Match Converter Methods
120 bool CvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
121 const SmallVectorImpl<MCParsedAsmOperand*> &);
122 bool CvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
123 const SmallVectorImpl<MCParsedAsmOperand*> &);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000124 bool CvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
125 const SmallVectorImpl<MCParsedAsmOperand*> &);
126 bool CvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
127 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachf922c472011-02-12 01:34:40 +0000128
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000129public:
Evan Cheng480cee52011-07-08 19:33:14 +0000130 ARMAsmParser(StringRef TT, StringRef CPU, StringRef FS, MCAsmParser &_Parser)
131 : TargetAsmParser(), Parser(_Parser) {
Evan Chengebdeeab2011-07-08 01:53:10 +0000132 STI = ARM_MC::createARMMCSubtargetInfo(TT, CPU, FS);
133
134 MCAsmParserExtension::Initialize(_Parser);
135 // Initialize the set of available features.
136 setAvailableFeatures(ComputeAvailableFeatures(STI->getFeatureBits()));
137 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000138
Benjamin Kramer38e59892010-07-14 22:38:02 +0000139 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Chris Lattner98986712010-01-14 22:21:20 +0000140 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000141 virtual bool ParseDirective(AsmToken DirectiveID);
142};
Jim Grosbach16c74252010-10-29 14:46:02 +0000143} // end anonymous namespace
144
Chris Lattner3a697562010-10-28 17:20:03 +0000145namespace {
146
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000147/// ARMOperand - Instances of this class represent a parsed ARM machine
148/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000149class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000150 enum KindTy {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000151 CondCode,
Jim Grosbachd67641b2010-12-06 18:21:12 +0000152 CCOut,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000153 CoprocNum,
154 CoprocReg,
Kevin Enderbycfe07242009-10-13 22:19:02 +0000155 Immediate,
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000156 MemBarrierOpt,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000157 Memory,
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000158 MSRMask,
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000159 ProcIFlags,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000160 Register,
Bill Wendling8d5acb72010-11-06 19:56:04 +0000161 RegisterList,
Bill Wendling0f630752010-11-17 04:32:08 +0000162 DPRRegisterList,
163 SPRRegisterList,
Owen Anderson00828302011-03-18 22:50:18 +0000164 Shifter,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000165 Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000166 } Kind;
167
Sean Callanan76264762010-04-02 22:27:05 +0000168 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000169 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000170
171 union {
172 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000173 ARMCC::CondCodes Val;
174 } CC;
175
176 struct {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000177 ARM_MB::MemBOpt Val;
178 } MBOpt;
179
180 struct {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000181 unsigned Val;
182 } Cop;
183
184 struct {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000185 ARM_PROC::IFlags Val;
186 } IFlags;
187
188 struct {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000189 unsigned Val;
190 } MMask;
191
192 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000193 const char *Data;
194 unsigned Length;
195 } Tok;
196
197 struct {
198 unsigned RegNum;
199 } Reg;
200
Bill Wendling8155e5b2010-11-06 22:19:43 +0000201 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000202 const MCExpr *Val;
203 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000204
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000205 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000206 struct {
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000207 ARMII::AddrMode AddrMode;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000208 unsigned BaseRegNum;
Daniel Dunbar2637dc92011-01-18 05:55:15 +0000209 union {
210 unsigned RegNum; ///< Offset register num, when OffsetIsReg.
211 const MCExpr *Value; ///< Offset value, when !OffsetIsReg.
212 } Offset;
Bill Wendling146018f2010-11-06 21:42:12 +0000213 const MCExpr *ShiftAmount; // used when OffsetRegShifted is true
Owen Anderson00828302011-03-18 22:50:18 +0000214 enum ARM_AM::ShiftOpc ShiftType; // used when OffsetRegShifted is true
Bill Wendling146018f2010-11-06 21:42:12 +0000215 unsigned OffsetRegShifted : 1; // only used when OffsetIsReg is true
Bill Wendling50d0f582010-11-18 23:43:05 +0000216 unsigned Preindexed : 1;
217 unsigned Postindexed : 1;
218 unsigned OffsetIsReg : 1;
219 unsigned Negative : 1; // only used when OffsetIsReg is true
220 unsigned Writeback : 1;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000221 } Mem;
Owen Anderson00828302011-03-18 22:50:18 +0000222
223 struct {
224 ARM_AM::ShiftOpc ShiftTy;
225 unsigned RegNum;
226 } Shift;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000227 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000228
Bill Wendling146018f2010-11-06 21:42:12 +0000229 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
230public:
Sean Callanan76264762010-04-02 22:27:05 +0000231 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
232 Kind = o.Kind;
233 StartLoc = o.StartLoc;
234 EndLoc = o.EndLoc;
235 switch (Kind) {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000236 case CondCode:
237 CC = o.CC;
238 break;
Sean Callanan76264762010-04-02 22:27:05 +0000239 case Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000240 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000241 break;
Jim Grosbachd67641b2010-12-06 18:21:12 +0000242 case CCOut:
Sean Callanan76264762010-04-02 22:27:05 +0000243 case Register:
244 Reg = o.Reg;
245 break;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000246 case RegisterList:
Bill Wendling0f630752010-11-17 04:32:08 +0000247 case DPRRegisterList:
248 case SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000249 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000250 break;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000251 case CoprocNum:
252 case CoprocReg:
253 Cop = o.Cop;
254 break;
Sean Callanan76264762010-04-02 22:27:05 +0000255 case Immediate:
256 Imm = o.Imm;
257 break;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000258 case MemBarrierOpt:
259 MBOpt = o.MBOpt;
260 break;
Sean Callanan76264762010-04-02 22:27:05 +0000261 case Memory:
262 Mem = o.Mem;
263 break;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000264 case MSRMask:
265 MMask = o.MMask;
266 break;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000267 case ProcIFlags:
268 IFlags = o.IFlags;
Owen Anderson00828302011-03-18 22:50:18 +0000269 break;
270 case Shifter:
271 Shift = o.Shift;
272 break;
Sean Callanan76264762010-04-02 22:27:05 +0000273 }
274 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000275
Sean Callanan76264762010-04-02 22:27:05 +0000276 /// getStartLoc - Get the location of the first token of this operand.
277 SMLoc getStartLoc() const { return StartLoc; }
278 /// getEndLoc - Get the location of the last token of this operand.
279 SMLoc getEndLoc() const { return EndLoc; }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000280
Daniel Dunbar8462b302010-08-11 06:36:53 +0000281 ARMCC::CondCodes getCondCode() const {
282 assert(Kind == CondCode && "Invalid access!");
283 return CC.Val;
284 }
285
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000286 unsigned getCoproc() const {
287 assert((Kind == CoprocNum || Kind == CoprocReg) && "Invalid access!");
288 return Cop.Val;
289 }
290
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000291 StringRef getToken() const {
292 assert(Kind == Token && "Invalid access!");
293 return StringRef(Tok.Data, Tok.Length);
294 }
295
296 unsigned getReg() const {
Benjamin Kramer6aa49432010-12-07 15:50:35 +0000297 assert((Kind == Register || Kind == CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000298 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000299 }
300
Bill Wendling5fa22a12010-11-09 23:28:44 +0000301 const SmallVectorImpl<unsigned> &getRegList() const {
Bill Wendling0f630752010-11-17 04:32:08 +0000302 assert((Kind == RegisterList || Kind == DPRRegisterList ||
303 Kind == SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000304 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000305 }
306
Kevin Enderbycfe07242009-10-13 22:19:02 +0000307 const MCExpr *getImm() const {
308 assert(Kind == Immediate && "Invalid access!");
309 return Imm.Val;
310 }
311
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000312 ARM_MB::MemBOpt getMemBarrierOpt() const {
313 assert(Kind == MemBarrierOpt && "Invalid access!");
314 return MBOpt.Val;
315 }
316
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000317 ARM_PROC::IFlags getProcIFlags() const {
318 assert(Kind == ProcIFlags && "Invalid access!");
319 return IFlags.Val;
320 }
321
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000322 unsigned getMSRMask() const {
323 assert(Kind == MSRMask && "Invalid access!");
324 return MMask.Val;
325 }
326
Daniel Dunbar6ec56202011-01-18 05:55:21 +0000327 /// @name Memory Operand Accessors
328 /// @{
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000329 ARMII::AddrMode getMemAddrMode() const {
330 return Mem.AddrMode;
331 }
Daniel Dunbar6ec56202011-01-18 05:55:21 +0000332 unsigned getMemBaseRegNum() const {
333 return Mem.BaseRegNum;
334 }
335 unsigned getMemOffsetRegNum() const {
336 assert(Mem.OffsetIsReg && "Invalid access!");
337 return Mem.Offset.RegNum;
338 }
339 const MCExpr *getMemOffset() const {
340 assert(!Mem.OffsetIsReg && "Invalid access!");
341 return Mem.Offset.Value;
342 }
343 unsigned getMemOffsetRegShifted() const {
344 assert(Mem.OffsetIsReg && "Invalid access!");
345 return Mem.OffsetRegShifted;
346 }
347 const MCExpr *getMemShiftAmount() const {
348 assert(Mem.OffsetIsReg && Mem.OffsetRegShifted && "Invalid access!");
349 return Mem.ShiftAmount;
350 }
Owen Anderson00828302011-03-18 22:50:18 +0000351 enum ARM_AM::ShiftOpc getMemShiftType() const {
Daniel Dunbar6ec56202011-01-18 05:55:21 +0000352 assert(Mem.OffsetIsReg && Mem.OffsetRegShifted && "Invalid access!");
353 return Mem.ShiftType;
354 }
355 bool getMemPreindexed() const { return Mem.Preindexed; }
356 bool getMemPostindexed() const { return Mem.Postindexed; }
357 bool getMemOffsetIsReg() const { return Mem.OffsetIsReg; }
358 bool getMemNegative() const { return Mem.Negative; }
359 bool getMemWriteback() const { return Mem.Writeback; }
360
361 /// @}
362
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000363 bool isCoprocNum() const { return Kind == CoprocNum; }
364 bool isCoprocReg() const { return Kind == CoprocReg; }
Daniel Dunbar8462b302010-08-11 06:36:53 +0000365 bool isCondCode() const { return Kind == CondCode; }
Jim Grosbachd67641b2010-12-06 18:21:12 +0000366 bool isCCOut() const { return Kind == CCOut; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000367 bool isImm() const { return Kind == Immediate; }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000368 bool isImm0_255() const {
369 if (Kind != Immediate)
370 return false;
371 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
372 if (!CE) return false;
373 int64_t Value = CE->getValue();
374 return Value >= 0 && Value < 256;
375 }
376 bool isT2SOImm() const {
377 if (Kind != Immediate)
378 return false;
379 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
380 if (!CE) return false;
381 int64_t Value = CE->getValue();
382 return ARM_AM::getT2SOImmVal(Value) != -1;
383 }
Bill Wendlingb32e7842010-11-08 00:32:40 +0000384 bool isReg() const { return Kind == Register; }
Bill Wendling8d5acb72010-11-06 19:56:04 +0000385 bool isRegList() const { return Kind == RegisterList; }
Bill Wendling0f630752010-11-17 04:32:08 +0000386 bool isDPRRegList() const { return Kind == DPRRegisterList; }
387 bool isSPRRegList() const { return Kind == SPRRegisterList; }
Chris Lattner14b93852010-10-29 00:27:31 +0000388 bool isToken() const { return Kind == Token; }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000389 bool isMemBarrierOpt() const { return Kind == MemBarrierOpt; }
Chris Lattner14b93852010-10-29 00:27:31 +0000390 bool isMemory() const { return Kind == Memory; }
Owen Anderson00828302011-03-18 22:50:18 +0000391 bool isShifter() const { return Kind == Shifter; }
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000392 bool isMemMode2() const {
393 if (getMemAddrMode() != ARMII::AddrMode2)
394 return false;
395
396 if (getMemOffsetIsReg())
397 return true;
398
399 if (getMemNegative() &&
400 !(getMemPostindexed() || getMemPreindexed()))
401 return false;
402
403 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
404 if (!CE) return false;
405 int64_t Value = CE->getValue();
406
407 // The offset must be in the range 0-4095 (imm12).
408 if (Value > 4095 || Value < -4095)
409 return false;
410
411 return true;
412 }
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000413 bool isMemMode3() const {
414 if (getMemAddrMode() != ARMII::AddrMode3)
415 return false;
416
417 if (getMemOffsetIsReg()) {
418 if (getMemOffsetRegShifted())
419 return false; // No shift with offset reg allowed
420 return true;
421 }
422
423 if (getMemNegative() &&
424 !(getMemPostindexed() || getMemPreindexed()))
425 return false;
426
427 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
428 if (!CE) return false;
429 int64_t Value = CE->getValue();
430
431 // The offset must be in the range 0-255 (imm8).
432 if (Value > 255 || Value < -255)
433 return false;
434
435 return true;
436 }
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000437 bool isMemMode5() const {
Daniel Dunbar4b462672011-01-18 05:55:27 +0000438 if (!isMemory() || getMemOffsetIsReg() || getMemWriteback() ||
439 getMemNegative())
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000440 return false;
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000441
Daniel Dunbar4b462672011-01-18 05:55:27 +0000442 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000443 if (!CE) return false;
444
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000445 // The offset must be a multiple of 4 in the range 0-1020.
446 int64_t Value = CE->getValue();
447 return ((Value & 0x3) == 0 && Value <= 1020 && Value >= -1020);
448 }
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000449 bool isMemMode7() const {
450 if (!isMemory() ||
451 getMemPreindexed() ||
452 getMemPostindexed() ||
453 getMemOffsetIsReg() ||
454 getMemNegative() ||
455 getMemWriteback())
456 return false;
457
458 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
459 if (!CE) return false;
460
461 if (CE->getValue())
462 return false;
463
464 return true;
465 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000466 bool isMemModeRegThumb() const {
Daniel Dunbar4b462672011-01-18 05:55:27 +0000467 if (!isMemory() || !getMemOffsetIsReg() || getMemWriteback())
Bill Wendlingf4caf692010-12-14 03:36:38 +0000468 return false;
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000469 return true;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000470 }
471 bool isMemModeImmThumb() const {
Daniel Dunbar4b462672011-01-18 05:55:27 +0000472 if (!isMemory() || getMemOffsetIsReg() || getMemWriteback())
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000473 return false;
474
Daniel Dunbar4b462672011-01-18 05:55:27 +0000475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000476 if (!CE) return false;
477
478 // The offset must be a multiple of 4 in the range 0-124.
479 uint64_t Value = CE->getValue();
480 return ((Value & 0x3) == 0 && Value <= 124);
481 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000482 bool isMSRMask() const { return Kind == MSRMask; }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000483 bool isProcIFlags() const { return Kind == ProcIFlags; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000484
485 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +0000486 // Add as immediates when possible. Null MCExpr = 0.
487 if (Expr == 0)
488 Inst.addOperand(MCOperand::CreateImm(0));
489 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000490 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
491 else
492 Inst.addOperand(MCOperand::CreateExpr(Expr));
493 }
494
Daniel Dunbar8462b302010-08-11 06:36:53 +0000495 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000496 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000497 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +0000498 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
499 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +0000500 }
501
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000502 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
503 assert(N == 1 && "Invalid number of operands!");
504 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
505 }
506
507 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
508 assert(N == 1 && "Invalid number of operands!");
509 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
510 }
511
Jim Grosbachd67641b2010-12-06 18:21:12 +0000512 void addCCOutOperands(MCInst &Inst, unsigned N) const {
513 assert(N == 1 && "Invalid number of operands!");
514 Inst.addOperand(MCOperand::CreateReg(getReg()));
515 }
516
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000517 void addRegOperands(MCInst &Inst, unsigned N) const {
518 assert(N == 1 && "Invalid number of operands!");
519 Inst.addOperand(MCOperand::CreateReg(getReg()));
520 }
521
Owen Anderson00828302011-03-18 22:50:18 +0000522 void addShifterOperands(MCInst &Inst, unsigned N) const {
523 assert(N == 1 && "Invalid number of operands!");
524 Inst.addOperand(MCOperand::CreateImm(
525 ARM_AM::getSORegOpc(Shift.ShiftTy, 0)));
526 }
527
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000528 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +0000529 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +0000530 const SmallVectorImpl<unsigned> &RegList = getRegList();
531 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000532 I = RegList.begin(), E = RegList.end(); I != E; ++I)
533 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000534 }
535
Bill Wendling0f630752010-11-17 04:32:08 +0000536 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
537 addRegListOperands(Inst, N);
538 }
539
540 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
541 addRegListOperands(Inst, N);
542 }
543
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000544 void addImmOperands(MCInst &Inst, unsigned N) const {
545 assert(N == 1 && "Invalid number of operands!");
546 addExpr(Inst, getImm());
547 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000548
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000549 void addImm0_255Operands(MCInst &Inst, unsigned N) const {
550 assert(N == 1 && "Invalid number of operands!");
551 addExpr(Inst, getImm());
552 }
553
554 void addT2SOImmOperands(MCInst &Inst, unsigned N) const {
555 assert(N == 1 && "Invalid number of operands!");
556 addExpr(Inst, getImm());
557 }
558
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000559 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
560 assert(N == 1 && "Invalid number of operands!");
561 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
562 }
563
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000564 void addMemMode7Operands(MCInst &Inst, unsigned N) const {
565 assert(N == 1 && isMemMode7() && "Invalid number of operands!");
566 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
567
568 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
Matt Beaumont-Gay1866af42011-03-24 22:05:48 +0000569 (void)CE;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000570 assert((CE || CE->getValue() == 0) &&
571 "No offset operand support in mode 7");
572 }
573
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000574 void addMemMode2Operands(MCInst &Inst, unsigned N) const {
575 assert(isMemMode2() && "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 ARM_AM::ShiftOpc ShOpc = ARM_AM::no_shift;
584 int64_t ShiftAmount = 0;
585
586 if (getMemOffsetRegShifted()) {
587 ShOpc = getMemShiftType();
588 const MCConstantExpr *CE =
589 dyn_cast<MCConstantExpr>(getMemShiftAmount());
590 ShiftAmount = CE->getValue();
591 }
592
593 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM2Opc(AMOpc, ShiftAmount,
594 ShOpc, IdxMode)));
595 return;
596 }
597
598 // Create a operand placeholder to always yield the same number of operands.
599 Inst.addOperand(MCOperand::CreateReg(0));
600
601 // FIXME: #-0 is encoded differently than #0. Does the parser preserve
602 // the difference?
603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
604 assert(CE && "Non-constant mode 2 offset operand!");
605 int64_t Offset = CE->getValue();
606
607 if (Offset >= 0)
608 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM2Opc(ARM_AM::add,
609 Offset, ARM_AM::no_shift, IdxMode)));
610 else
611 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM2Opc(ARM_AM::sub,
612 -Offset, ARM_AM::no_shift, IdxMode)));
613 }
614
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000615 void addMemMode3Operands(MCInst &Inst, unsigned N) const {
616 assert(isMemMode3() && "Invalid mode or number of operands!");
617 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
618 unsigned IdxMode = (getMemPreindexed() | getMemPostindexed() << 1);
619
620 if (getMemOffsetIsReg()) {
621 Inst.addOperand(MCOperand::CreateReg(getMemOffsetRegNum()));
622
623 ARM_AM::AddrOpc AMOpc = getMemNegative() ? ARM_AM::sub : ARM_AM::add;
624 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM3Opc(AMOpc, 0,
625 IdxMode)));
626 return;
627 }
628
629 // Create a operand placeholder to always yield the same number of operands.
630 Inst.addOperand(MCOperand::CreateReg(0));
631
632 // FIXME: #-0 is encoded differently than #0. Does the parser preserve
633 // the difference?
634 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
635 assert(CE && "Non-constant mode 3 offset operand!");
636 int64_t Offset = CE->getValue();
637
638 if (Offset >= 0)
639 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM3Opc(ARM_AM::add,
640 Offset, IdxMode)));
641 else
642 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM3Opc(ARM_AM::sub,
643 -Offset, IdxMode)));
644 }
645
Chris Lattner14b93852010-10-29 00:27:31 +0000646 void addMemMode5Operands(MCInst &Inst, unsigned N) const {
647 assert(N == 2 && isMemMode5() && "Invalid number of operands!");
Jim Grosbach16c74252010-10-29 14:46:02 +0000648
Daniel Dunbar4b462672011-01-18 05:55:27 +0000649 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
650 assert(!getMemOffsetIsReg() && "Invalid mode 5 operand");
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000651
Jim Grosbach80eb2332010-10-29 17:41:25 +0000652 // FIXME: #-0 is encoded differently than #0. Does the parser preserve
653 // the difference?
Daniel Dunbar4b462672011-01-18 05:55:27 +0000654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000655 assert(CE && "Non-constant mode 5 offset operand!");
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000656
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000657 // The MCInst offset operand doesn't include the low two bits (like
658 // the instruction encoding).
659 int64_t Offset = CE->getValue() / 4;
660 if (Offset >= 0)
661 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add,
662 Offset)));
663 else
664 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub,
665 -Offset)));
Chris Lattner14b93852010-10-29 00:27:31 +0000666 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000667
Bill Wendlingf4caf692010-12-14 03:36:38 +0000668 void addMemModeRegThumbOperands(MCInst &Inst, unsigned N) const {
669 assert(N == 2 && isMemModeRegThumb() && "Invalid number of operands!");
Daniel Dunbar4b462672011-01-18 05:55:27 +0000670 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
671 Inst.addOperand(MCOperand::CreateReg(getMemOffsetRegNum()));
Bill Wendlingf4caf692010-12-14 03:36:38 +0000672 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000673
Bill Wendlingf4caf692010-12-14 03:36:38 +0000674 void addMemModeImmThumbOperands(MCInst &Inst, unsigned N) const {
675 assert(N == 2 && isMemModeImmThumb() && "Invalid number of operands!");
Daniel Dunbar4b462672011-01-18 05:55:27 +0000676 Inst.addOperand(MCOperand::CreateReg(getMemBaseRegNum()));
677 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemOffset());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000678 assert(CE && "Non-constant mode offset operand!");
679 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000680 }
681
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000682 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
683 assert(N == 1 && "Invalid number of operands!");
684 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
685 }
686
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000687 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
688 assert(N == 1 && "Invalid number of operands!");
689 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
690 }
691
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000692 virtual void dump(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +0000693
Chris Lattner3a697562010-10-28 17:20:03 +0000694 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
695 ARMOperand *Op = new ARMOperand(CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000696 Op->CC.Val = CC;
697 Op->StartLoc = S;
698 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000699 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000700 }
701
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000702 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
703 ARMOperand *Op = new ARMOperand(CoprocNum);
704 Op->Cop.Val = CopVal;
705 Op->StartLoc = S;
706 Op->EndLoc = S;
707 return Op;
708 }
709
710 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
711 ARMOperand *Op = new ARMOperand(CoprocReg);
712 Op->Cop.Val = CopVal;
713 Op->StartLoc = S;
714 Op->EndLoc = S;
715 return Op;
716 }
717
Jim Grosbachd67641b2010-12-06 18:21:12 +0000718 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
719 ARMOperand *Op = new ARMOperand(CCOut);
720 Op->Reg.RegNum = RegNum;
721 Op->StartLoc = S;
722 Op->EndLoc = S;
723 return Op;
724 }
725
Chris Lattner3a697562010-10-28 17:20:03 +0000726 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
727 ARMOperand *Op = new ARMOperand(Token);
Sean Callanan76264762010-04-02 22:27:05 +0000728 Op->Tok.Data = Str.data();
729 Op->Tok.Length = Str.size();
730 Op->StartLoc = S;
731 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000732 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000733 }
734
Bill Wendling50d0f582010-11-18 23:43:05 +0000735 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Chris Lattner3a697562010-10-28 17:20:03 +0000736 ARMOperand *Op = new ARMOperand(Register);
Sean Callanan76264762010-04-02 22:27:05 +0000737 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +0000738 Op->StartLoc = S;
739 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000740 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000741 }
742
Owen Anderson00828302011-03-18 22:50:18 +0000743 static ARMOperand *CreateShifter(ARM_AM::ShiftOpc ShTy,
744 SMLoc S, SMLoc E) {
745 ARMOperand *Op = new ARMOperand(Shifter);
746 Op->Shift.ShiftTy = ShTy;
747 Op->StartLoc = S;
748 Op->EndLoc = E;
749 return Op;
750 }
751
Bill Wendling7729e062010-11-09 22:44:22 +0000752 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +0000753 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000754 SMLoc StartLoc, SMLoc EndLoc) {
Bill Wendling0f630752010-11-17 04:32:08 +0000755 KindTy Kind = RegisterList;
756
757 if (ARM::DPRRegClass.contains(Regs.front().first))
758 Kind = DPRRegisterList;
759 else if (ARM::SPRRegClass.contains(Regs.front().first))
760 Kind = SPRRegisterList;
761
762 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +0000763 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000764 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +0000765 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +0000766 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000767 Op->StartLoc = StartLoc;
768 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000769 return Op;
770 }
771
Chris Lattner3a697562010-10-28 17:20:03 +0000772 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
773 ARMOperand *Op = new ARMOperand(Immediate);
Sean Callanan76264762010-04-02 22:27:05 +0000774 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +0000775 Op->StartLoc = S;
776 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000777 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +0000778 }
779
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000780 static ARMOperand *CreateMem(ARMII::AddrMode AddrMode, unsigned BaseRegNum,
781 bool OffsetIsReg, const MCExpr *Offset,
782 int OffsetRegNum, bool OffsetRegShifted,
Owen Anderson00828302011-03-18 22:50:18 +0000783 enum ARM_AM::ShiftOpc ShiftType,
Chris Lattner3a697562010-10-28 17:20:03 +0000784 const MCExpr *ShiftAmount, bool Preindexed,
785 bool Postindexed, bool Negative, bool Writeback,
786 SMLoc S, SMLoc E) {
Daniel Dunbar023835d2011-01-18 05:34:05 +0000787 assert((OffsetRegNum == -1 || OffsetIsReg) &&
788 "OffsetRegNum must imply OffsetIsReg!");
789 assert((!OffsetRegShifted || OffsetIsReg) &&
790 "OffsetRegShifted must imply OffsetIsReg!");
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000791 assert((Offset || OffsetIsReg) &&
792 "Offset must exists unless register offset is used!");
Daniel Dunbar023835d2011-01-18 05:34:05 +0000793 assert((!ShiftAmount || (OffsetIsReg && OffsetRegShifted)) &&
794 "Cannot have shift amount without shifted register offset!");
795 assert((!Offset || !OffsetIsReg) &&
796 "Cannot have expression offset and register offset!");
797
Chris Lattner3a697562010-10-28 17:20:03 +0000798 ARMOperand *Op = new ARMOperand(Memory);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000799 Op->Mem.AddrMode = AddrMode;
Sean Callanan76264762010-04-02 22:27:05 +0000800 Op->Mem.BaseRegNum = BaseRegNum;
801 Op->Mem.OffsetIsReg = OffsetIsReg;
Daniel Dunbar2637dc92011-01-18 05:55:15 +0000802 if (OffsetIsReg)
803 Op->Mem.Offset.RegNum = OffsetRegNum;
804 else
805 Op->Mem.Offset.Value = Offset;
Sean Callanan76264762010-04-02 22:27:05 +0000806 Op->Mem.OffsetRegShifted = OffsetRegShifted;
807 Op->Mem.ShiftType = ShiftType;
808 Op->Mem.ShiftAmount = ShiftAmount;
809 Op->Mem.Preindexed = Preindexed;
810 Op->Mem.Postindexed = Postindexed;
811 Op->Mem.Negative = Negative;
812 Op->Mem.Writeback = Writeback;
Jim Grosbach16c74252010-10-29 14:46:02 +0000813
Sean Callanan76264762010-04-02 22:27:05 +0000814 Op->StartLoc = S;
815 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000816 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000817 }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000818
819 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
820 ARMOperand *Op = new ARMOperand(MemBarrierOpt);
821 Op->MBOpt.Val = Opt;
822 Op->StartLoc = S;
823 Op->EndLoc = S;
824 return Op;
825 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000826
827 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
828 ARMOperand *Op = new ARMOperand(ProcIFlags);
829 Op->IFlags.Val = IFlags;
830 Op->StartLoc = S;
831 Op->EndLoc = S;
832 return Op;
833 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000834
835 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
836 ARMOperand *Op = new ARMOperand(MSRMask);
837 Op->MMask.Val = MMask;
838 Op->StartLoc = S;
839 Op->EndLoc = S;
840 return Op;
841 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000842};
843
844} // end anonymous namespace.
845
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000846void ARMOperand::dump(raw_ostream &OS) const {
847 switch (Kind) {
848 case CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000849 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000850 break;
Jim Grosbachd67641b2010-12-06 18:21:12 +0000851 case CCOut:
852 OS << "<ccout " << getReg() << ">";
853 break;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000854 case CoprocNum:
855 OS << "<coprocessor number: " << getCoproc() << ">";
856 break;
857 case CoprocReg:
858 OS << "<coprocessor register: " << getCoproc() << ">";
859 break;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000860 case MSRMask:
861 OS << "<mask: " << getMSRMask() << ">";
862 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000863 case Immediate:
864 getImm()->print(OS);
865 break;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000866 case MemBarrierOpt:
867 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
868 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000869 case Memory:
Daniel Dunbar6ec56202011-01-18 05:55:21 +0000870 OS << "<memory "
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000871 << "am:" << ARMII::AddrModeToString(getMemAddrMode())
872 << " base:" << getMemBaseRegNum();
Daniel Dunbar6ec56202011-01-18 05:55:21 +0000873 if (getMemOffsetIsReg()) {
874 OS << " offset:<register " << getMemOffsetRegNum();
875 if (getMemOffsetRegShifted()) {
876 OS << " offset-shift-type:" << getMemShiftType();
877 OS << " offset-shift-amount:" << *getMemShiftAmount();
878 }
879 } else {
880 OS << " offset:" << *getMemOffset();
881 }
882 if (getMemOffsetIsReg())
883 OS << " (offset-is-reg)";
884 if (getMemPreindexed())
885 OS << " (pre-indexed)";
886 if (getMemPostindexed())
887 OS << " (post-indexed)";
888 if (getMemNegative())
889 OS << " (negative)";
890 if (getMemWriteback())
891 OS << " (writeback)";
892 OS << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000893 break;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000894 case ProcIFlags: {
895 OS << "<ARM_PROC::";
896 unsigned IFlags = getProcIFlags();
897 for (int i=2; i >= 0; --i)
898 if (IFlags & (1 << i))
899 OS << ARM_PROC::IFlagsToString(1 << i);
900 OS << ">";
901 break;
902 }
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000903 case Register:
Bill Wendling50d0f582010-11-18 23:43:05 +0000904 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000905 break;
Owen Anderson00828302011-03-18 22:50:18 +0000906 case Shifter:
907 OS << "<shifter " << getShiftOpcStr(Shift.ShiftTy) << ">";
908 break;
Bill Wendling0f630752010-11-17 04:32:08 +0000909 case RegisterList:
910 case DPRRegisterList:
911 case SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +0000912 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000913
Bill Wendling5fa22a12010-11-09 23:28:44 +0000914 const SmallVectorImpl<unsigned> &RegList = getRegList();
915 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000916 I = RegList.begin(), E = RegList.end(); I != E; ) {
917 OS << *I;
918 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000919 }
920
921 OS << ">";
922 break;
923 }
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000924 case Token:
925 OS << "'" << getToken() << "'";
926 break;
927 }
928}
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000929
930/// @name Auto-generated Match Functions
931/// {
932
933static unsigned MatchRegisterName(StringRef Name);
934
935/// }
936
Bob Wilson69df7232011-02-03 21:46:10 +0000937bool ARMAsmParser::ParseRegister(unsigned &RegNo,
938 SMLoc &StartLoc, SMLoc &EndLoc) {
Roman Divackybf755322011-01-27 17:14:22 +0000939 RegNo = TryParseRegister();
940
941 return (RegNo == (unsigned)-1);
942}
943
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000944/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +0000945/// and if it is a register name the token is eaten and the register number is
946/// returned. Otherwise return -1.
947///
948int ARMAsmParser::TryParseRegister() {
949 const AsmToken &Tok = Parser.getTok();
950 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
Jim Grosbachd4462a52010-11-01 16:44:21 +0000951
Chris Lattnere5658fa2010-10-30 04:09:10 +0000952 // FIXME: Validate register for the current architecture; we have to do
953 // validation later, so maybe there is no need for this here.
Owen Anderson0c9f2502011-01-13 22:50:36 +0000954 std::string upperCase = Tok.getString().str();
955 std::string lowerCase = LowercaseString(upperCase);
956 unsigned RegNum = MatchRegisterName(lowerCase);
957 if (!RegNum) {
958 RegNum = StringSwitch<unsigned>(lowerCase)
959 .Case("r13", ARM::SP)
960 .Case("r14", ARM::LR)
961 .Case("r15", ARM::PC)
962 .Case("ip", ARM::R12)
963 .Default(0);
964 }
965 if (!RegNum) return -1;
Bob Wilson69df7232011-02-03 21:46:10 +0000966
Chris Lattnere5658fa2010-10-30 04:09:10 +0000967 Parser.Lex(); // Eat identifier token.
968 return RegNum;
969}
Jim Grosbachd4462a52010-11-01 16:44:21 +0000970
Owen Anderson00828302011-03-18 22:50:18 +0000971/// Try to parse a register name. The token must be an Identifier when called,
972/// and if it is a register name the token is eaten and the register number is
973/// returned. Otherwise return -1.
974///
975bool ARMAsmParser::TryParseShiftRegister(
976 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
977 SMLoc S = Parser.getTok().getLoc();
978 const AsmToken &Tok = Parser.getTok();
979 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
980
981 std::string upperCase = Tok.getString().str();
982 std::string lowerCase = LowercaseString(upperCase);
983 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
984 .Case("lsl", ARM_AM::lsl)
985 .Case("lsr", ARM_AM::lsr)
986 .Case("asr", ARM_AM::asr)
987 .Case("ror", ARM_AM::ror)
988 .Case("rrx", ARM_AM::rrx)
989 .Default(ARM_AM::no_shift);
990
991 if (ShiftTy == ARM_AM::no_shift)
992 return true;
993
994 Parser.Lex(); // Eat shift-type operand;
995 int RegNum = TryParseRegister();
996 if (RegNum == -1)
997 return Error(Parser.getTok().getLoc(), "register expected");
998
999 Operands.push_back(ARMOperand::CreateReg(RegNum,S, Parser.getTok().getLoc()));
1000 Operands.push_back(ARMOperand::CreateShifter(ShiftTy,
1001 S, Parser.getTok().getLoc()));
1002
1003 return false;
1004}
1005
1006
Bill Wendling50d0f582010-11-18 23:43:05 +00001007/// Try to parse a register name. The token must be an Identifier when called.
1008/// If it's a register, an AsmOperand is created. Another AsmOperand is created
1009/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +00001010///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001011/// TODO this is likely to change to allow different register types and or to
1012/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +00001013bool ARMAsmParser::
1014TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00001015 SMLoc S = Parser.getTok().getLoc();
1016 int RegNo = TryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +00001017 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +00001018 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +00001019
Bill Wendling50d0f582010-11-18 23:43:05 +00001020 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001021
Chris Lattnere5658fa2010-10-30 04:09:10 +00001022 const AsmToken &ExclaimTok = Parser.getTok();
1023 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +00001024 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
1025 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +00001026 Parser.Lex(); // Eat exclaim token
Kevin Enderby99e6d4e2009-10-07 18:01:35 +00001027 }
1028
Bill Wendling50d0f582010-11-18 23:43:05 +00001029 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001030}
1031
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001032/// MatchCoprocessorOperandName - Try to parse an coprocessor related
1033/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
1034/// "c5", ...
1035static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001036 // Use the same layout as the tablegen'erated register name matcher. Ugly,
1037 // but efficient.
1038 switch (Name.size()) {
1039 default: break;
1040 case 2:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001041 if (Name[0] != CoprocOp)
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001042 return -1;
1043 switch (Name[1]) {
1044 default: return -1;
1045 case '0': return 0;
1046 case '1': return 1;
1047 case '2': return 2;
1048 case '3': return 3;
1049 case '4': return 4;
1050 case '5': return 5;
1051 case '6': return 6;
1052 case '7': return 7;
1053 case '8': return 8;
1054 case '9': return 9;
1055 }
1056 break;
1057 case 3:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001058 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001059 return -1;
1060 switch (Name[2]) {
1061 default: return -1;
1062 case '0': return 10;
1063 case '1': return 11;
1064 case '2': return 12;
1065 case '3': return 13;
1066 case '4': return 14;
1067 case '5': return 15;
1068 }
1069 break;
1070 }
1071
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001072 return -1;
1073}
1074
Jim Grosbachf922c472011-02-12 01:34:40 +00001075/// tryParseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001076/// token must be an Identifier when called, and if it is a coprocessor
1077/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00001078ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1079tryParseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001080 SMLoc S = Parser.getTok().getLoc();
1081 const AsmToken &Tok = Parser.getTok();
1082 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1083
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001084 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001085 if (Num == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00001086 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001087
1088 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001089 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00001090 return MatchOperand_Success;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001091}
1092
Jim Grosbachf922c472011-02-12 01:34:40 +00001093/// tryParseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001094/// token must be an Identifier when called, and if it is a coprocessor
1095/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00001096ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1097tryParseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001098 SMLoc S = Parser.getTok().getLoc();
1099 const AsmToken &Tok = Parser.getTok();
1100 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1101
1102 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
1103 if (Reg == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00001104 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001105
1106 Parser.Lex(); // Eat identifier token.
1107 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00001108 return MatchOperand_Success;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001109}
1110
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001111/// Parse a register list, return it if successful else return null. The first
1112/// token must be a '{' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00001113bool ARMAsmParser::
1114ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +00001115 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00001116 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +00001117 SMLoc S = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001118
Bill Wendling7729e062010-11-09 22:44:22 +00001119 // Read the rest of the registers in the list.
1120 unsigned PrevRegNum = 0;
Bill Wendling5fa22a12010-11-09 23:28:44 +00001121 SmallVector<std::pair<unsigned, SMLoc>, 32> Registers;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001122
Bill Wendling7729e062010-11-09 22:44:22 +00001123 do {
Bill Wendlinge7176102010-11-06 22:36:58 +00001124 bool IsRange = Parser.getTok().is(AsmToken::Minus);
Bill Wendling7729e062010-11-09 22:44:22 +00001125 Parser.Lex(); // Eat non-identifier token.
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001126
Sean Callanan18b83232010-01-19 21:44:56 +00001127 const AsmToken &RegTok = Parser.getTok();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001128 SMLoc RegLoc = RegTok.getLoc();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001129 if (RegTok.isNot(AsmToken::Identifier)) {
1130 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001131 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001132 }
Bill Wendlinge7176102010-11-06 22:36:58 +00001133
Bill Wendling1d6a2652010-11-06 10:40:24 +00001134 int RegNum = TryParseRegister();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001135 if (RegNum == -1) {
1136 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001137 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001138 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001139
Bill Wendlinge7176102010-11-06 22:36:58 +00001140 if (IsRange) {
1141 int Reg = PrevRegNum;
1142 do {
1143 ++Reg;
1144 Registers.push_back(std::make_pair(Reg, RegLoc));
1145 } while (Reg != RegNum);
1146 } else {
1147 Registers.push_back(std::make_pair(RegNum, RegLoc));
1148 }
1149
1150 PrevRegNum = RegNum;
Bill Wendling7729e062010-11-09 22:44:22 +00001151 } while (Parser.getTok().is(AsmToken::Comma) ||
1152 Parser.getTok().is(AsmToken::Minus));
Bill Wendlinge7176102010-11-06 22:36:58 +00001153
1154 // Process the right curly brace of the list.
Sean Callanan18b83232010-01-19 21:44:56 +00001155 const AsmToken &RCurlyTok = Parser.getTok();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001156 if (RCurlyTok.isNot(AsmToken::RCurly)) {
1157 Error(RCurlyTok.getLoc(), "'}' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001158 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +00001159 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001160
Bill Wendlinge7176102010-11-06 22:36:58 +00001161 SMLoc E = RCurlyTok.getLoc();
1162 Parser.Lex(); // Eat right curly brace token.
Jim Grosbach03f44a02010-11-29 23:18:01 +00001163
Bill Wendlinge7176102010-11-06 22:36:58 +00001164 // Verify the register list.
Bill Wendling5fa22a12010-11-09 23:28:44 +00001165 SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendlinge7176102010-11-06 22:36:58 +00001166 RI = Registers.begin(), RE = Registers.end();
1167
Bill Wendling7caebff2011-01-12 21:20:59 +00001168 unsigned HighRegNum = getARMRegisterNumbering(RI->first);
Bill Wendling8e8b18b2010-11-09 23:45:59 +00001169 bool EmittedWarning = false;
1170
Bill Wendling7caebff2011-01-12 21:20:59 +00001171 DenseMap<unsigned, bool> RegMap;
1172 RegMap[HighRegNum] = true;
1173
Bill Wendlinge7176102010-11-06 22:36:58 +00001174 for (++RI; RI != RE; ++RI) {
Bill Wendling7729e062010-11-09 22:44:22 +00001175 const std::pair<unsigned, SMLoc> &RegInfo = *RI;
Bill Wendling7caebff2011-01-12 21:20:59 +00001176 unsigned Reg = getARMRegisterNumbering(RegInfo.first);
Bill Wendlinge7176102010-11-06 22:36:58 +00001177
Bill Wendling8e8b18b2010-11-09 23:45:59 +00001178 if (RegMap[Reg]) {
Bill Wendlinge7176102010-11-06 22:36:58 +00001179 Error(RegInfo.second, "register duplicated in register list");
Bill Wendling50d0f582010-11-18 23:43:05 +00001180 return true;
Bill Wendlinge7176102010-11-06 22:36:58 +00001181 }
1182
Bill Wendling8e8b18b2010-11-09 23:45:59 +00001183 if (!EmittedWarning && Reg < HighRegNum)
Bill Wendlinge7176102010-11-06 22:36:58 +00001184 Warning(RegInfo.second,
1185 "register not in ascending order in register list");
1186
Bill Wendling8e8b18b2010-11-09 23:45:59 +00001187 RegMap[Reg] = true;
1188 HighRegNum = std::max(Reg, HighRegNum);
Bill Wendlinge7176102010-11-06 22:36:58 +00001189 }
1190
Bill Wendling50d0f582010-11-18 23:43:05 +00001191 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
1192 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001193}
1194
Jim Grosbachf922c472011-02-12 01:34:40 +00001195/// tryParseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
1196ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1197tryParseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001198 SMLoc S = Parser.getTok().getLoc();
1199 const AsmToken &Tok = Parser.getTok();
1200 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1201 StringRef OptStr = Tok.getString();
1202
1203 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()))
1204 .Case("sy", ARM_MB::SY)
1205 .Case("st", ARM_MB::ST)
1206 .Case("ish", ARM_MB::ISH)
1207 .Case("ishst", ARM_MB::ISHST)
1208 .Case("nsh", ARM_MB::NSH)
1209 .Case("nshst", ARM_MB::NSHST)
1210 .Case("osh", ARM_MB::OSH)
1211 .Case("oshst", ARM_MB::OSHST)
1212 .Default(~0U);
1213
1214 if (Opt == ~0U)
Jim Grosbachf922c472011-02-12 01:34:40 +00001215 return MatchOperand_NoMatch;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001216
1217 Parser.Lex(); // Eat identifier token.
1218 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00001219 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001220}
1221
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +00001222/// tryParseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001223ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1224tryParseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1225 SMLoc S = Parser.getTok().getLoc();
1226 const AsmToken &Tok = Parser.getTok();
1227 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1228 StringRef IFlagsStr = Tok.getString();
1229
1230 unsigned IFlags = 0;
1231 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
1232 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
1233 .Case("a", ARM_PROC::A)
1234 .Case("i", ARM_PROC::I)
1235 .Case("f", ARM_PROC::F)
1236 .Default(~0U);
1237
1238 // If some specific iflag is already set, it means that some letter is
1239 // present more than once, this is not acceptable.
1240 if (Flag == ~0U || (IFlags & Flag))
1241 return MatchOperand_NoMatch;
1242
1243 IFlags |= Flag;
1244 }
1245
1246 Parser.Lex(); // Eat identifier token.
1247 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
1248 return MatchOperand_Success;
1249}
1250
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001251/// tryParseMSRMaskOperand - Try to parse mask flags from MSR instruction.
1252ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1253tryParseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1254 SMLoc S = Parser.getTok().getLoc();
1255 const AsmToken &Tok = Parser.getTok();
1256 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1257 StringRef Mask = Tok.getString();
1258
1259 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
1260 size_t Start = 0, Next = Mask.find('_');
1261 StringRef Flags = "";
1262 StringRef SpecReg = Mask.slice(Start, Next);
1263 if (Next != StringRef::npos)
1264 Flags = Mask.slice(Next+1, Mask.size());
1265
1266 // FlagsVal contains the complete mask:
1267 // 3-0: Mask
1268 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
1269 unsigned FlagsVal = 0;
1270
1271 if (SpecReg == "apsr") {
1272 FlagsVal = StringSwitch<unsigned>(Flags)
1273 .Case("nzcvq", 0x8) // same as CPSR_c
1274 .Case("g", 0x4) // same as CPSR_s
1275 .Case("nzcvqg", 0xc) // same as CPSR_fs
1276 .Default(~0U);
1277
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00001278 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001279 if (!Flags.empty())
1280 return MatchOperand_NoMatch;
1281 else
1282 FlagsVal = 0; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00001283 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001284 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00001285 if (Flags == "all") // cpsr_all is an alias for cpsr_fc
1286 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001287 for (int i = 0, e = Flags.size(); i != e; ++i) {
1288 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
1289 .Case("c", 1)
1290 .Case("x", 2)
1291 .Case("s", 4)
1292 .Case("f", 8)
1293 .Default(~0U);
1294
1295 // If some specific flag is already set, it means that some letter is
1296 // present more than once, this is not acceptable.
1297 if (FlagsVal == ~0U || (FlagsVal & Flag))
1298 return MatchOperand_NoMatch;
1299 FlagsVal |= Flag;
1300 }
1301 } else // No match for special register.
1302 return MatchOperand_NoMatch;
1303
1304 // Special register without flags are equivalent to "fc" flags.
1305 if (!FlagsVal)
1306 FlagsVal = 0x9;
1307
1308 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
1309 if (SpecReg == "spsr")
1310 FlagsVal |= 16;
1311
1312 Parser.Lex(); // Eat identifier token.
1313 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
1314 return MatchOperand_Success;
1315}
1316
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001317/// tryParseMemMode2Operand - Try to parse memory addressing mode 2 operand.
1318ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1319tryParseMemMode2Operand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Matt Beaumont-Gaye3662cc2011-04-01 00:06:01 +00001320 assert(Parser.getTok().is(AsmToken::LBrac) && "Token is not a \"[\"");
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001321
1322 if (ParseMemory(Operands, ARMII::AddrMode2))
1323 return MatchOperand_NoMatch;
1324
1325 return MatchOperand_Success;
1326}
1327
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001328/// tryParseMemMode3Operand - Try to parse memory addressing mode 3 operand.
1329ARMAsmParser::OperandMatchResultTy ARMAsmParser::
1330tryParseMemMode3Operand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1331 assert(Parser.getTok().is(AsmToken::LBrac) && "Token is not a \"[\"");
1332
1333 if (ParseMemory(Operands, ARMII::AddrMode3))
1334 return MatchOperand_NoMatch;
1335
1336 return MatchOperand_Success;
1337}
1338
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001339/// CvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
1340/// Needed here because the Asm Gen Matcher can't handle properly tied operands
1341/// when they refer multiple MIOperands inside a single one.
1342bool ARMAsmParser::
1343CvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
1344 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1345 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
1346
1347 // Create a writeback register dummy placeholder.
1348 Inst.addOperand(MCOperand::CreateImm(0));
1349
1350 ((ARMOperand*)Operands[3])->addMemMode2Operands(Inst, 3);
1351 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
1352 return true;
1353}
1354
1355/// CvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
1356/// Needed here because the Asm Gen Matcher can't handle properly tied operands
1357/// when they refer multiple MIOperands inside a single one.
1358bool ARMAsmParser::
1359CvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
1360 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1361 // Create a writeback register dummy placeholder.
1362 Inst.addOperand(MCOperand::CreateImm(0));
1363 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
1364 ((ARMOperand*)Operands[3])->addMemMode2Operands(Inst, 3);
1365 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
1366 return true;
1367}
1368
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001369/// CvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
1370/// Needed here because the Asm Gen Matcher can't handle properly tied operands
1371/// when they refer multiple MIOperands inside a single one.
1372bool ARMAsmParser::
1373CvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
1374 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1375 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
1376
1377 // Create a writeback register dummy placeholder.
1378 Inst.addOperand(MCOperand::CreateImm(0));
1379
1380 ((ARMOperand*)Operands[3])->addMemMode3Operands(Inst, 3);
1381 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
1382 return true;
1383}
1384
1385/// CvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
1386/// Needed here because the Asm Gen Matcher can't handle properly tied operands
1387/// when they refer multiple MIOperands inside a single one.
1388bool ARMAsmParser::
1389CvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
1390 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1391 // Create a writeback register dummy placeholder.
1392 Inst.addOperand(MCOperand::CreateImm(0));
1393 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
1394 ((ARMOperand*)Operands[3])->addMemMode3Operands(Inst, 3);
1395 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
1396 return true;
1397}
1398
Bill Wendlinge7176102010-11-06 22:36:58 +00001399/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001400/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00001401///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001402/// TODO Only preindexing and postindexing addressing are started, unindexed
1403/// with option, etc are still to do.
Bill Wendling50d0f582010-11-18 23:43:05 +00001404bool ARMAsmParser::
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001405ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
1406 ARMII::AddrMode AddrMode = ARMII::AddrModeNone) {
Sean Callanan76264762010-04-02 22:27:05 +00001407 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00001408 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00001409 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00001410 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00001411 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001412
Sean Callanan18b83232010-01-19 21:44:56 +00001413 const AsmToken &BaseRegTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +00001414 if (BaseRegTok.isNot(AsmToken::Identifier)) {
1415 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001416 return true;
Chris Lattner550276e2010-10-28 20:52:15 +00001417 }
Chris Lattnere5658fa2010-10-30 04:09:10 +00001418 int BaseRegNum = TryParseRegister();
1419 if (BaseRegNum == -1) {
Chris Lattner550276e2010-10-28 20:52:15 +00001420 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001421 return true;
Chris Lattner550276e2010-10-28 20:52:15 +00001422 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001423
Daniel Dunbar05710932011-01-18 05:34:17 +00001424 // The next token must either be a comma or a closing bracket.
1425 const AsmToken &Tok = Parser.getTok();
1426 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
1427 return true;
1428
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001429 bool Preindexed = false;
1430 bool Postindexed = false;
1431 bool OffsetIsReg = false;
1432 bool Negative = false;
1433 bool Writeback = false;
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001434 ARMOperand *WBOp = 0;
1435 int OffsetRegNum = -1;
1436 bool OffsetRegShifted = false;
Owen Anderson00828302011-03-18 22:50:18 +00001437 enum ARM_AM::ShiftOpc ShiftType = ARM_AM::lsl;
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001438 const MCExpr *ShiftAmount = 0;
1439 const MCExpr *Offset = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001440
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001441 // First look for preindexed address forms, that is after the "[Rn" we now
1442 // have to see if the next token is a comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001443 if (Tok.is(AsmToken::Comma)) {
1444 Preindexed = true;
Sean Callananb9a25b72010-01-19 20:27:46 +00001445 Parser.Lex(); // Eat comma token.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001446
Chris Lattner550276e2010-10-28 20:52:15 +00001447 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType, ShiftAmount,
1448 Offset, OffsetIsReg, OffsetRegNum, E))
Bill Wendling50d0f582010-11-18 23:43:05 +00001449 return true;
Sean Callanan18b83232010-01-19 21:44:56 +00001450 const AsmToken &RBracTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +00001451 if (RBracTok.isNot(AsmToken::RBrac)) {
1452 Error(RBracTok.getLoc(), "']' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001453 return true;
Chris Lattner550276e2010-10-28 20:52:15 +00001454 }
Sean Callanan76264762010-04-02 22:27:05 +00001455 E = RBracTok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00001456 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001457
Sean Callanan18b83232010-01-19 21:44:56 +00001458 const AsmToken &ExclaimTok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001459 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001460 // None of addrmode3 instruction uses "!"
1461 if (AddrMode == ARMII::AddrMode3)
1462 return true;
1463
Bill Wendling50d0f582010-11-18 23:43:05 +00001464 WBOp = ARMOperand::CreateToken(ExclaimTok.getString(),
1465 ExclaimTok.getLoc());
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001466 Writeback = true;
Sean Callananb9a25b72010-01-19 20:27:46 +00001467 Parser.Lex(); // Eat exclaim token
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001468 } else { // In addressing mode 2, pre-indexed mode always end with "!"
1469 if (AddrMode == ARMII::AddrMode2)
1470 Preindexed = false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001471 }
Daniel Dunbar05710932011-01-18 05:34:17 +00001472 } else {
1473 // The "[Rn" we have so far was not followed by a comma.
1474
Jim Grosbach80eb2332010-10-29 17:41:25 +00001475 // If there's anything other than the right brace, this is a post indexing
1476 // addressing form.
Sean Callanan76264762010-04-02 22:27:05 +00001477 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00001478 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001479
Sean Callanan18b83232010-01-19 21:44:56 +00001480 const AsmToken &NextTok = Parser.getTok();
Jim Grosbach03f44a02010-11-29 23:18:01 +00001481
Kevin Enderbye2a98dd2009-10-15 21:42:45 +00001482 if (NextTok.isNot(AsmToken::EndOfStatement)) {
Jim Grosbach80eb2332010-10-29 17:41:25 +00001483 Postindexed = true;
1484 Writeback = true;
Bill Wendling50d0f582010-11-18 23:43:05 +00001485
Chris Lattner550276e2010-10-28 20:52:15 +00001486 if (NextTok.isNot(AsmToken::Comma)) {
1487 Error(NextTok.getLoc(), "',' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +00001488 return true;
Chris Lattner550276e2010-10-28 20:52:15 +00001489 }
Bill Wendling50d0f582010-11-18 23:43:05 +00001490
Sean Callananb9a25b72010-01-19 20:27:46 +00001491 Parser.Lex(); // Eat comma token.
Bill Wendling50d0f582010-11-18 23:43:05 +00001492
Chris Lattner550276e2010-10-28 20:52:15 +00001493 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType,
Jim Grosbach16c74252010-10-29 14:46:02 +00001494 ShiftAmount, Offset, OffsetIsReg, OffsetRegNum,
Chris Lattner550276e2010-10-28 20:52:15 +00001495 E))
Bill Wendling50d0f582010-11-18 23:43:05 +00001496 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001497 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001498 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001499
1500 // Force Offset to exist if used.
1501 if (!OffsetIsReg) {
1502 if (!Offset)
1503 Offset = MCConstantExpr::Create(0, getContext());
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001504 } else {
1505 if (AddrMode == ARMII::AddrMode3 && OffsetRegShifted) {
1506 Error(E, "shift amount not supported");
1507 return true;
1508 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001509 }
1510
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001511 Operands.push_back(ARMOperand::CreateMem(AddrMode, BaseRegNum, OffsetIsReg,
1512 Offset, OffsetRegNum, OffsetRegShifted,
1513 ShiftType, ShiftAmount, Preindexed,
1514 Postindexed, Negative, Writeback, S, E));
Daniel Dunbar05d8b712011-01-18 05:34:24 +00001515 if (WBOp)
1516 Operands.push_back(WBOp);
1517
1518 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001519}
1520
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001521/// Parse the offset of a memory operand after we have seen "[Rn," or "[Rn],"
1522/// we will parse the following (were +/- means that a plus or minus is
1523/// optional):
1524/// +/-Rm
1525/// +/-Rm, shift
1526/// #offset
1527/// we return false on success or an error otherwise.
1528bool ARMAsmParser::ParseMemoryOffsetReg(bool &Negative,
Sean Callanan76264762010-04-02 22:27:05 +00001529 bool &OffsetRegShifted,
Owen Anderson00828302011-03-18 22:50:18 +00001530 enum ARM_AM::ShiftOpc &ShiftType,
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001531 const MCExpr *&ShiftAmount,
1532 const MCExpr *&Offset,
1533 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +00001534 int &OffsetRegNum,
1535 SMLoc &E) {
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001536 Negative = false;
1537 OffsetRegShifted = false;
1538 OffsetIsReg = false;
1539 OffsetRegNum = -1;
Sean Callanan18b83232010-01-19 21:44:56 +00001540 const AsmToken &NextTok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +00001541 E = NextTok.getLoc();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001542 if (NextTok.is(AsmToken::Plus))
Sean Callananb9a25b72010-01-19 20:27:46 +00001543 Parser.Lex(); // Eat plus token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001544 else if (NextTok.is(AsmToken::Minus)) {
1545 Negative = true;
Sean Callananb9a25b72010-01-19 20:27:46 +00001546 Parser.Lex(); // Eat minus token
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001547 }
1548 // See if there is a register following the "[Rn," or "[Rn]," we have so far.
Sean Callanan18b83232010-01-19 21:44:56 +00001549 const AsmToken &OffsetRegTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001550 if (OffsetRegTok.is(AsmToken::Identifier)) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00001551 SMLoc CurLoc = OffsetRegTok.getLoc();
1552 OffsetRegNum = TryParseRegister();
1553 if (OffsetRegNum != -1) {
Chris Lattner550276e2010-10-28 20:52:15 +00001554 OffsetIsReg = true;
Chris Lattnere5658fa2010-10-30 04:09:10 +00001555 E = CurLoc;
Sean Callanan76264762010-04-02 22:27:05 +00001556 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001557 }
Jim Grosbachd4462a52010-11-01 16:44:21 +00001558
Bill Wendling12f40e92010-11-06 10:51:53 +00001559 // If we parsed a register as the offset then there can be a shift after that.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001560 if (OffsetRegNum != -1) {
1561 // Look for a comma then a shift
Sean Callanan18b83232010-01-19 21:44:56 +00001562 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001563 if (Tok.is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00001564 Parser.Lex(); // Eat comma token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001565
Sean Callanan18b83232010-01-19 21:44:56 +00001566 const AsmToken &Tok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +00001567 if (ParseShift(ShiftType, ShiftAmount, E))
Duncan Sands34727662010-07-12 08:16:59 +00001568 return Error(Tok.getLoc(), "shift expected");
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001569 OffsetRegShifted = true;
1570 }
1571 }
1572 else { // the "[Rn," or "[Rn,]" we have so far was not followed by "Rm"
1573 // Look for #offset following the "[Rn," or "[Rn],"
Sean Callanan18b83232010-01-19 21:44:56 +00001574 const AsmToken &HashTok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001575 if (HashTok.isNot(AsmToken::Hash))
1576 return Error(HashTok.getLoc(), "'#' expected");
Jim Grosbach16c74252010-10-29 14:46:02 +00001577
Sean Callananb9a25b72010-01-19 20:27:46 +00001578 Parser.Lex(); // Eat hash token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001579
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001580 if (getParser().ParseExpression(Offset))
1581 return true;
Sean Callanan76264762010-04-02 22:27:05 +00001582 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001583 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001584 return false;
1585}
1586
1587/// ParseShift as one of these two:
1588/// ( lsl | lsr | asr | ror ) , # shift_amount
1589/// rrx
1590/// and returns true if it parses a shift otherwise it returns false.
Owen Anderson00828302011-03-18 22:50:18 +00001591bool ARMAsmParser::ParseShift(ARM_AM::ShiftOpc &St,
1592 const MCExpr *&ShiftAmount, SMLoc &E) {
Sean Callanan18b83232010-01-19 21:44:56 +00001593 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001594 if (Tok.isNot(AsmToken::Identifier))
1595 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00001596 StringRef ShiftName = Tok.getString();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001597 if (ShiftName == "lsl" || ShiftName == "LSL")
Owen Anderson00828302011-03-18 22:50:18 +00001598 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001599 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00001600 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001601 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00001602 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001603 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00001604 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001605 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00001606 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001607 else
1608 return true;
Sean Callananb9a25b72010-01-19 20:27:46 +00001609 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001610
1611 // Rrx stands alone.
Owen Anderson00828302011-03-18 22:50:18 +00001612 if (St == ARM_AM::rrx)
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001613 return false;
1614
1615 // Otherwise, there must be a '#' and a shift amount.
Sean Callanan18b83232010-01-19 21:44:56 +00001616 const AsmToken &HashTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001617 if (HashTok.isNot(AsmToken::Hash))
1618 return Error(HashTok.getLoc(), "'#' expected");
Sean Callananb9a25b72010-01-19 20:27:46 +00001619 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001620
1621 if (getParser().ParseExpression(ShiftAmount))
1622 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001623
1624 return false;
1625}
1626
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001627/// Parse a arm instruction operand. For now this parses the operand regardless
1628/// of the mnemonic.
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001629bool ARMAsmParser::ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001630 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00001631 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001632
1633 // Check if the current operand has a custom associated parser, if so, try to
1634 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00001635 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
1636 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001637 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00001638 // If there wasn't a custom match, try the generic matcher below. Otherwise,
1639 // there was a match, but an error occurred, in which case, just return that
1640 // the operand parsing failed.
1641 if (ResTy == MatchOperand_ParseFail)
1642 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001643
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001644 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00001645 default:
1646 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00001647 return true;
Kevin Enderby67b212e2011-01-13 20:32:36 +00001648 case AsmToken::Identifier:
Bill Wendling50d0f582010-11-18 23:43:05 +00001649 if (!TryParseRegisterWithWriteBack(Operands))
1650 return false;
Owen Anderson00828302011-03-18 22:50:18 +00001651 if (!TryParseShiftRegister(Operands))
1652 return false;
1653
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001654
1655 // Fall though for the Identifier case that is not a register or a
1656 // special name.
Kevin Enderby67b212e2011-01-13 20:32:36 +00001657 case AsmToken::Integer: // things like 1f and 2b as a branch targets
1658 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00001659 // This was not a register so parse other operands that start with an
1660 // identifier (like labels) as expressions and create them as immediates.
1661 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00001662 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00001663 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00001664 return true;
Sean Callanan76264762010-04-02 22:27:05 +00001665 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00001666 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
1667 return false;
1668 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001669 case AsmToken::LBrac:
Bill Wendling50d0f582010-11-18 23:43:05 +00001670 return ParseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001671 case AsmToken::LCurly:
Bill Wendling50d0f582010-11-18 23:43:05 +00001672 return ParseRegisterList(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00001673 case AsmToken::Hash:
Kevin Enderby079469f2009-10-13 23:33:38 +00001674 // #42 -> immediate.
1675 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
Sean Callanan76264762010-04-02 22:27:05 +00001676 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00001677 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001678 const MCExpr *ImmVal;
1679 if (getParser().ParseExpression(ImmVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00001680 return true;
Sean Callanan76264762010-04-02 22:27:05 +00001681 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00001682 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
1683 return false;
Jason W Kim9081b4b2011-01-11 23:53:41 +00001684 case AsmToken::Colon: {
1685 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00001686 // FIXME: Check it's an expression prefix,
1687 // e.g. (FOO - :lower16:BAR) isn't legal.
1688 ARMMCExpr::VariantKind RefKind;
Jason W Kim9081b4b2011-01-11 23:53:41 +00001689 if (ParsePrefix(RefKind))
1690 return true;
1691
Evan Cheng75972122011-01-13 07:58:56 +00001692 const MCExpr *SubExprVal;
1693 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00001694 return true;
1695
Evan Cheng75972122011-01-13 07:58:56 +00001696 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
1697 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00001698 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00001699 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00001700 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001701 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00001702 }
1703}
1704
Evan Cheng75972122011-01-13 07:58:56 +00001705// ParsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
1706// :lower16: and :upper16:.
1707bool ARMAsmParser::ParsePrefix(ARMMCExpr::VariantKind &RefKind) {
1708 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00001709
1710 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00001711 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00001712 Parser.Lex(); // Eat ':'
1713
1714 if (getLexer().isNot(AsmToken::Identifier)) {
1715 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
1716 return true;
1717 }
1718
1719 StringRef IDVal = Parser.getTok().getIdentifier();
1720 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00001721 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00001722 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00001723 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00001724 } else {
1725 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
1726 return true;
1727 }
1728 Parser.Lex();
1729
1730 if (getLexer().isNot(AsmToken::Colon)) {
1731 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
1732 return true;
1733 }
1734 Parser.Lex(); // Eat the last ':'
1735 return false;
1736}
1737
1738const MCExpr *
1739ARMAsmParser::ApplyPrefixToExpr(const MCExpr *E,
1740 MCSymbolRefExpr::VariantKind Variant) {
1741 // Recurse over the given expression, rebuilding it to apply the given variant
1742 // to the leftmost symbol.
1743 if (Variant == MCSymbolRefExpr::VK_None)
1744 return E;
1745
1746 switch (E->getKind()) {
1747 case MCExpr::Target:
1748 llvm_unreachable("Can't handle target expr yet");
1749 case MCExpr::Constant:
1750 llvm_unreachable("Can't handle lower16/upper16 of constant yet");
1751
1752 case MCExpr::SymbolRef: {
1753 const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E);
1754
1755 if (SRE->getKind() != MCSymbolRefExpr::VK_None)
1756 return 0;
1757
1758 return MCSymbolRefExpr::Create(&SRE->getSymbol(), Variant, getContext());
1759 }
1760
1761 case MCExpr::Unary:
1762 llvm_unreachable("Can't handle unary expressions yet");
1763
1764 case MCExpr::Binary: {
1765 const MCBinaryExpr *BE = cast<MCBinaryExpr>(E);
1766 const MCExpr *LHS = ApplyPrefixToExpr(BE->getLHS(), Variant);
1767 const MCExpr *RHS = BE->getRHS();
1768 if (!LHS)
1769 return 0;
1770
1771 return MCBinaryExpr::Create(BE->getOpcode(), LHS, RHS, getContext());
1772 }
1773 }
1774
1775 assert(0 && "Invalid expression kind!");
1776 return 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001777}
1778
Daniel Dunbar352e1482011-01-11 15:59:50 +00001779/// \brief Given a mnemonic, split out possible predication code and carry
1780/// setting letters to form a canonical mnemonic and flags.
1781//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001782// FIXME: Would be nice to autogen this.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001783static StringRef SplitMnemonic(StringRef Mnemonic,
1784 unsigned &PredicationCode,
1785 bool &CarrySetting,
1786 unsigned &ProcessorIMod) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00001787 PredicationCode = ARMCC::AL;
1788 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001789 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00001790
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001791 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00001792 //
1793 // FIXME: Would be nice to autogen this.
Daniel Dunbar8ab11122011-01-10 21:01:03 +00001794 if (Mnemonic == "teq" || Mnemonic == "vceq" ||
1795 Mnemonic == "movs" ||
1796 Mnemonic == "svc" ||
1797 (Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
1798 Mnemonic == "vmls" || Mnemonic == "vnmls") ||
1799 Mnemonic == "vacge" || Mnemonic == "vcge" ||
1800 Mnemonic == "vclt" ||
1801 Mnemonic == "vacgt" || Mnemonic == "vcgt" ||
1802 Mnemonic == "vcle" ||
1803 (Mnemonic == "smlal" || Mnemonic == "umaal" || Mnemonic == "umlal" ||
1804 Mnemonic == "vabal" || Mnemonic == "vmlal" || Mnemonic == "vpadal" ||
Jim Grosbachd1f0bbe2011-06-27 20:59:10 +00001805 Mnemonic == "vqdmlal" || Mnemonic == "bics"))
Daniel Dunbar352e1482011-01-11 15:59:50 +00001806 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00001807
Daniel Dunbar352e1482011-01-11 15:59:50 +00001808 // First, split out any predication code.
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001809 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001810 .Case("eq", ARMCC::EQ)
1811 .Case("ne", ARMCC::NE)
1812 .Case("hs", ARMCC::HS)
Jim Grosbach660a9ec2011-06-27 20:40:29 +00001813 .Case("cs", ARMCC::HS)
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001814 .Case("lo", ARMCC::LO)
Jim Grosbach660a9ec2011-06-27 20:40:29 +00001815 .Case("cc", ARMCC::LO)
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001816 .Case("mi", ARMCC::MI)
1817 .Case("pl", ARMCC::PL)
1818 .Case("vs", ARMCC::VS)
1819 .Case("vc", ARMCC::VC)
1820 .Case("hi", ARMCC::HI)
1821 .Case("ls", ARMCC::LS)
1822 .Case("ge", ARMCC::GE)
1823 .Case("lt", ARMCC::LT)
1824 .Case("gt", ARMCC::GT)
1825 .Case("le", ARMCC::LE)
1826 .Case("al", ARMCC::AL)
1827 .Default(~0U);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001828 if (CC != ~0U) {
1829 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
Daniel Dunbar352e1482011-01-11 15:59:50 +00001830 PredicationCode = CC;
Bill Wendling52925b62010-10-29 23:50:21 +00001831 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001832
Daniel Dunbar352e1482011-01-11 15:59:50 +00001833 // Next, determine if we have a carry setting bit. We explicitly ignore all
1834 // the instructions we know end in 's'.
1835 if (Mnemonic.endswith("s") &&
1836 !(Mnemonic == "asrs" || Mnemonic == "cps" || Mnemonic == "mls" ||
1837 Mnemonic == "movs" || Mnemonic == "mrs" || Mnemonic == "smmls" ||
1838 Mnemonic == "vabs" || Mnemonic == "vcls" || Mnemonic == "vmls" ||
1839 Mnemonic == "vmrs" || Mnemonic == "vnmls" || Mnemonic == "vqabs" ||
1840 Mnemonic == "vrecps" || Mnemonic == "vrsqrts")) {
1841 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
1842 CarrySetting = true;
1843 }
1844
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001845 // The "cps" instruction can have a interrupt mode operand which is glued into
1846 // the mnemonic. Check if this is the case, split it and parse the imod op
1847 if (Mnemonic.startswith("cps")) {
1848 // Split out any imod code.
1849 unsigned IMod =
1850 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
1851 .Case("ie", ARM_PROC::IE)
1852 .Case("id", ARM_PROC::ID)
1853 .Default(~0U);
1854 if (IMod != ~0U) {
1855 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
1856 ProcessorIMod = IMod;
1857 }
1858 }
1859
Daniel Dunbar352e1482011-01-11 15:59:50 +00001860 return Mnemonic;
1861}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001862
1863/// \brief Given a canonical mnemonic, determine if the instruction ever allows
1864/// inclusion of carry set or predication code operands.
1865//
1866// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00001867void ARMAsmParser::
1868GetMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
1869 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001870 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
1871 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
1872 Mnemonic == "smull" || Mnemonic == "add" || Mnemonic == "adc" ||
1873 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Bruno Cardoso Lopesbe64b392011-05-27 23:46:09 +00001874 Mnemonic == "umlal" || Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001875 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
1876 Mnemonic == "sbc" || Mnemonic == "mla" || Mnemonic == "umull" ||
Bruno Cardoso Lopesbe64b392011-05-27 23:46:09 +00001877 Mnemonic == "eor" || Mnemonic == "smlal" ||
Evan Chengebdeeab2011-07-08 01:53:10 +00001878 (Mnemonic == "mov" && !isThumbOne())) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001879 CanAcceptCarrySet = true;
1880 } else {
1881 CanAcceptCarrySet = false;
1882 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001883
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001884 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
1885 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
1886 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
1887 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Bruno Cardoso Lopese47f3752011-01-20 19:18:32 +00001888 Mnemonic == "dsb" || Mnemonic == "movs" || Mnemonic == "isb" ||
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001889 Mnemonic == "clrex" || Mnemonic.startswith("cps")) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001890 CanAcceptPredicationCode = false;
1891 } else {
1892 CanAcceptPredicationCode = true;
1893 }
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001894
Evan Chengebdeeab2011-07-08 01:53:10 +00001895 if (isThumb())
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001896 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00001897 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001898 CanAcceptPredicationCode = false;
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001899}
1900
1901/// Parse an arm instruction mnemonic followed by its operands.
1902bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
1903 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1904 // Create the leading tokens for the mnemonic, split by '.' characters.
1905 size_t Start = 0, Next = Name.find('.');
1906 StringRef Head = Name.slice(Start, Next);
1907
Daniel Dunbar352e1482011-01-11 15:59:50 +00001908 // Split out the predication code and carry setting flag from the mnemonic.
1909 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001910 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00001911 bool CarrySetting;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001912 Head = SplitMnemonic(Head, PredicationCode, CarrySetting,
1913 ProcessorIMod);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001914
Chris Lattner3a697562010-10-28 17:20:03 +00001915 Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
Bill Wendling9717fa92010-11-21 10:56:05 +00001916
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001917 // Next, add the CCOut and ConditionCode operands, if needed.
1918 //
1919 // For mnemonics which can ever incorporate a carry setting bit or predication
1920 // code, our matching model involves us always generating CCOut and
1921 // ConditionCode operands to match the mnemonic "as written" and then we let
1922 // the matcher deal with finding the right instruction or generating an
1923 // appropriate error.
1924 bool CanAcceptCarrySet, CanAcceptPredicationCode;
1925 GetMnemonicAcceptInfo(Head, CanAcceptCarrySet, CanAcceptPredicationCode);
1926
1927 // Add the carry setting operand, if necessary.
1928 //
1929 // FIXME: It would be awesome if we could somehow invent a location such that
1930 // match errors on this operand would print a nice diagnostic about how the
1931 // 's' character in the mnemonic resulted in a CCOut operand.
1932 if (CanAcceptCarrySet) {
1933 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
1934 NameLoc));
1935 } else {
1936 // This mnemonic can't ever accept a carry set, but the user wrote one (or
1937 // misspelled another mnemonic).
1938
1939 // FIXME: Issue a nice error.
1940 }
1941
1942 // Add the predication code operand, if necessary.
1943 if (CanAcceptPredicationCode) {
1944 Operands.push_back(ARMOperand::CreateCondCode(
1945 ARMCC::CondCodes(PredicationCode), NameLoc));
1946 } else {
1947 // This mnemonic can't ever accept a predication code, but the user wrote
1948 // one (or misspelled another mnemonic).
1949
1950 // FIXME: Issue a nice error.
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001951 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001952
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001953 // Add the processor imod operand, if necessary.
1954 if (ProcessorIMod) {
1955 Operands.push_back(ARMOperand::CreateImm(
1956 MCConstantExpr::Create(ProcessorIMod, getContext()),
1957 NameLoc, NameLoc));
1958 } else {
1959 // This mnemonic can't ever accept a imod, but the user wrote
1960 // one (or misspelled another mnemonic).
1961
1962 // FIXME: Issue a nice error.
1963 }
1964
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001965 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00001966 while (Next != StringRef::npos) {
1967 Start = Next;
1968 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001969 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001970
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001971 Operands.push_back(ARMOperand::CreateToken(ExtraToken, NameLoc));
Daniel Dunbar5747b132010-08-11 06:37:16 +00001972 }
1973
1974 // Read the remaining operands.
1975 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001976 // Read the first operand.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001977 if (ParseOperand(Operands, Head)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00001978 Parser.EatToEndOfStatement();
1979 return true;
1980 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001981
1982 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00001983 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001984
1985 // Parse and remember the operand.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001986 if (ParseOperand(Operands, Head)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00001987 Parser.EatToEndOfStatement();
1988 return true;
1989 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001990 }
1991 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001992
Chris Lattnercbf8a982010-09-11 16:18:25 +00001993 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1994 Parser.EatToEndOfStatement();
Chris Lattner34e53142010-09-08 05:10:46 +00001995 return TokError("unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00001996 }
Bill Wendling146018f2010-11-06 21:42:12 +00001997
Chris Lattner34e53142010-09-08 05:10:46 +00001998 Parser.Lex(); // Consume the EndOfStatement
Chris Lattner98986712010-01-14 22:21:20 +00001999 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002000}
2001
Chris Lattnerfa42fad2010-10-28 21:28:01 +00002002bool ARMAsmParser::
2003MatchAndEmitInstruction(SMLoc IDLoc,
2004 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
2005 MCStreamer &Out) {
2006 MCInst Inst;
2007 unsigned ErrorInfo;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00002008 MatchResultTy MatchResult, MatchResult2;
2009 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
2010 if (MatchResult != Match_Success) {
2011 // If we get a Match_InvalidOperand it might be some arithmetic instruction
2012 // that does not update the condition codes. So try adding a CCOut operand
2013 // with a value of reg0.
2014 if (MatchResult == Match_InvalidOperand) {
2015 Operands.insert(Operands.begin() + 1,
2016 ARMOperand::CreateCCOut(0,
2017 ((ARMOperand*)Operands[0])->getStartLoc()));
2018 MatchResult2 = MatchInstructionImpl(Operands, Inst, ErrorInfo);
2019 if (MatchResult2 == Match_Success)
2020 MatchResult = Match_Success;
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00002021 else {
2022 ARMOperand *CCOut = ((ARMOperand*)Operands[1]);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00002023 Operands.erase(Operands.begin() + 1);
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00002024 delete CCOut;
2025 }
Kevin Enderby193c3ac2010-12-09 19:19:43 +00002026 }
2027 // If we get a Match_MnemonicFail it might be some arithmetic instruction
2028 // that updates the condition codes if it ends in 's'. So see if the
2029 // mnemonic ends in 's' and if so try removing the 's' and adding a CCOut
2030 // operand with a value of CPSR.
2031 else if(MatchResult == Match_MnemonicFail) {
2032 // Get the instruction mnemonic, which is the first token.
2033 StringRef Mnemonic = ((ARMOperand*)Operands[0])->getToken();
2034 if (Mnemonic.substr(Mnemonic.size()-1) == "s") {
2035 // removed the 's' from the mnemonic for matching.
2036 StringRef MnemonicNoS = Mnemonic.slice(0, Mnemonic.size() - 1);
2037 SMLoc NameLoc = ((ARMOperand*)Operands[0])->getStartLoc();
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00002038 ARMOperand *OldMnemonic = ((ARMOperand*)Operands[0]);
2039 Operands.erase(Operands.begin());
2040 delete OldMnemonic;
2041 Operands.insert(Operands.begin(),
Kevin Enderby193c3ac2010-12-09 19:19:43 +00002042 ARMOperand::CreateToken(MnemonicNoS, NameLoc));
2043 Operands.insert(Operands.begin() + 1,
2044 ARMOperand::CreateCCOut(ARM::CPSR, NameLoc));
2045 MatchResult2 = MatchInstructionImpl(Operands, Inst, ErrorInfo);
2046 if (MatchResult2 == Match_Success)
2047 MatchResult = Match_Success;
2048 else {
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00002049 ARMOperand *OldMnemonic = ((ARMOperand*)Operands[0]);
2050 Operands.erase(Operands.begin());
2051 delete OldMnemonic;
2052 Operands.insert(Operands.begin(),
Kevin Enderby193c3ac2010-12-09 19:19:43 +00002053 ARMOperand::CreateToken(Mnemonic, NameLoc));
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00002054 ARMOperand *CCOut = ((ARMOperand*)Operands[1]);
2055 Operands.erase(Operands.begin() + 1);
2056 delete CCOut;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00002057 }
2058 }
2059 }
2060 }
2061 switch (MatchResult) {
Chris Lattnere73d4f82010-10-28 21:41:58 +00002062 case Match_Success:
Chris Lattnerfa42fad2010-10-28 21:28:01 +00002063 Out.EmitInstruction(Inst);
2064 return false;
Chris Lattnere73d4f82010-10-28 21:41:58 +00002065 case Match_MissingFeature:
2066 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
2067 return true;
2068 case Match_InvalidOperand: {
2069 SMLoc ErrorLoc = IDLoc;
2070 if (ErrorInfo != ~0U) {
2071 if (ErrorInfo >= Operands.size())
2072 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00002073
Chris Lattnere73d4f82010-10-28 21:41:58 +00002074 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
2075 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
2076 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002077
Chris Lattnere73d4f82010-10-28 21:41:58 +00002078 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00002079 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00002080 case Match_MnemonicFail:
2081 return Error(IDLoc, "unrecognized instruction mnemonic");
Daniel Dunbarb4129152011-02-04 17:12:23 +00002082 case Match_ConversionFail:
2083 return Error(IDLoc, "unable to convert operands to instruction");
Chris Lattnere73d4f82010-10-28 21:41:58 +00002084 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002085
Eric Christopherc223e2b2010-10-29 09:26:59 +00002086 llvm_unreachable("Implement any new match types added!");
Bill Wendling146018f2010-11-06 21:42:12 +00002087 return true;
Chris Lattnerfa42fad2010-10-28 21:28:01 +00002088}
2089
Kevin Enderby515d5092009-10-15 20:48:48 +00002090/// ParseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002091bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
2092 StringRef IDVal = DirectiveID.getIdentifier();
2093 if (IDVal == ".word")
2094 return ParseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00002095 else if (IDVal == ".thumb")
2096 return ParseDirectiveThumb(DirectiveID.getLoc());
2097 else if (IDVal == ".thumb_func")
2098 return ParseDirectiveThumbFunc(DirectiveID.getLoc());
2099 else if (IDVal == ".code")
2100 return ParseDirectiveCode(DirectiveID.getLoc());
2101 else if (IDVal == ".syntax")
2102 return ParseDirectiveSyntax(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002103 return true;
2104}
2105
2106/// ParseDirectiveWord
2107/// ::= .word [ expression (, expression)* ]
2108bool ARMAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
2109 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2110 for (;;) {
2111 const MCExpr *Value;
2112 if (getParser().ParseExpression(Value))
2113 return true;
2114
Chris Lattneraaec2052010-01-19 19:46:13 +00002115 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002116
2117 if (getLexer().is(AsmToken::EndOfStatement))
2118 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00002119
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002120 // FIXME: Improve diagnostic.
2121 if (getLexer().isNot(AsmToken::Comma))
2122 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00002123 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002124 }
2125 }
2126
Sean Callananb9a25b72010-01-19 20:27:46 +00002127 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002128 return false;
2129}
2130
Kevin Enderby515d5092009-10-15 20:48:48 +00002131/// ParseDirectiveThumb
2132/// ::= .thumb
2133bool ARMAsmParser::ParseDirectiveThumb(SMLoc L) {
2134 if (getLexer().isNot(AsmToken::EndOfStatement))
2135 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00002136 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00002137
2138 // TODO: set thumb mode
2139 // TODO: tell the MC streamer the mode
2140 // getParser().getStreamer().Emit???();
2141 return false;
2142}
2143
2144/// ParseDirectiveThumbFunc
2145/// ::= .thumbfunc symbol_name
2146bool ARMAsmParser::ParseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00002147 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
2148 bool isMachO = MAI.hasSubsectionsViaSymbols();
2149 StringRef Name;
2150
2151 // Darwin asm has function name after .thumb_func direction
2152 // ELF doesn't
2153 if (isMachO) {
2154 const AsmToken &Tok = Parser.getTok();
2155 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
2156 return Error(L, "unexpected token in .thumb_func directive");
2157 Name = Tok.getString();
2158 Parser.Lex(); // Consume the identifier token.
2159 }
2160
Kevin Enderby515d5092009-10-15 20:48:48 +00002161 if (getLexer().isNot(AsmToken::EndOfStatement))
2162 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00002163 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00002164
Rafael Espindola64695402011-05-16 16:17:21 +00002165 // FIXME: assuming function name will be the line following .thumb_func
2166 if (!isMachO) {
2167 Name = Parser.getTok().getString();
2168 }
2169
Jim Grosbach642fc9c2010-11-05 22:33:53 +00002170 // Mark symbol as a thumb symbol.
2171 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
2172 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00002173 return false;
2174}
2175
2176/// ParseDirectiveSyntax
2177/// ::= .syntax unified | divided
2178bool ARMAsmParser::ParseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00002179 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00002180 if (Tok.isNot(AsmToken::Identifier))
2181 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00002182 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00002183 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00002184 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00002185 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00002186 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00002187 else
2188 return Error(L, "unrecognized syntax mode in .syntax directive");
2189
2190 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00002191 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00002192 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00002193
2194 // TODO tell the MC streamer the mode
2195 // getParser().getStreamer().Emit???();
2196 return false;
2197}
2198
2199/// ParseDirectiveCode
2200/// ::= .code 16 | 32
2201bool ARMAsmParser::ParseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00002202 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00002203 if (Tok.isNot(AsmToken::Integer))
2204 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00002205 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00002206 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00002207 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00002208 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00002209 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00002210 else
2211 return Error(L, "invalid operand to .code directive");
2212
2213 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00002214 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00002215 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00002216
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00002217 // FIXME: We need to be able switch subtargets at this point so that
2218 // MatchInstructionImpl() will work when it gets the AvailableFeatures which
2219 // includes Feature_IsThumb or not to match the right instructions. This is
2220 // blocked on the FIXME in llvm-mc.cpp when creating the TargetMachine.
2221 if (Val == 16){
Evan Chengebdeeab2011-07-08 01:53:10 +00002222 assert(isThumb() &&
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00002223 "switching between arm/thumb not yet suppported via .code 16)");
Jim Grosbach2a301702010-11-05 22:40:53 +00002224 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00002225 }
2226 else{
Evan Chengebdeeab2011-07-08 01:53:10 +00002227 assert(!isThumb() &&
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00002228 "switching between thumb/arm not yet suppported via .code 32)");
Jim Grosbach2a301702010-11-05 22:40:53 +00002229 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00002230 }
Jim Grosbach2a301702010-11-05 22:40:53 +00002231
Kevin Enderby515d5092009-10-15 20:48:48 +00002232 return false;
2233}
2234
Sean Callanan90b70972010-04-07 20:29:34 +00002235extern "C" void LLVMInitializeARMAsmLexer();
2236
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002237/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002238extern "C" void LLVMInitializeARMAsmParser() {
2239 RegisterAsmParser<ARMAsmParser> X(TheARMTarget);
2240 RegisterAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00002241 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00002242}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002243
Chris Lattner0692ee62010-09-06 19:11:01 +00002244#define GET_REGISTER_MATCHER
2245#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002246#include "ARMGenAsmMatcher.inc"