blob: d849fa59961a72bf94d40e3c26794b62516663a7 [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"
Jim Grosbach642fc9c2010-11-05 22:33:53 +000018#include "llvm/MC/MCContext.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000019#include "llvm/MC/MCStreamer.h"
20#include "llvm/MC/MCExpr.h"
21#include "llvm/MC/MCInst.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000022#include "llvm/Target/TargetRegistry.h"
23#include "llvm/Target/TargetAsmParser.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000024#include "llvm/Support/SourceMgr.h"
Daniel Dunbarfa315de2010-08-11 06:37:12 +000025#include "llvm/Support/raw_ostream.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000026#include "llvm/ADT/SmallVector.h"
Daniel Dunbar345a9a62010-08-11 06:37:20 +000027#include "llvm/ADT/StringSwitch.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000028#include "llvm/ADT/Twine.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000029using namespace llvm;
30
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +000031/// Shift types used for register controlled shifts in ARM memory addressing.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000032enum ShiftType {
33 Lsl,
34 Lsr,
35 Asr,
36 Ror,
37 Rrx
38};
39
Chris Lattner3a697562010-10-28 17:20:03 +000040namespace {
Bill Wendling146018f2010-11-06 21:42:12 +000041
42class ARMOperand;
Jim Grosbach16c74252010-10-29 14:46:02 +000043
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000044class ARMAsmParser : public TargetAsmParser {
45 MCAsmParser &Parser;
Daniel Dunbard73ada72010-07-19 00:33:49 +000046 TargetMachine &TM;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000047
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000048 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000049 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
50
51 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000052 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
53
Chris Lattnere5658fa2010-10-30 04:09:10 +000054 int TryParseRegister();
Owen Andersone4e5e2a2011-01-13 21:46:02 +000055 bool TryParseMCRName(SmallVectorImpl<MCParsedAsmOperand*>&);
Bill Wendling50d0f582010-11-18 23:43:05 +000056 bool TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
57 bool ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
58 bool ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Owen Andersone4e5e2a2011-01-13 21:46:02 +000059 bool ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, bool isMCR);
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,
67 enum ShiftType &ShiftType,
68 const MCExpr *&ShiftAmount,
69 const MCExpr *&Offset,
70 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +000071 int &OffsetRegNum,
72 SMLoc &E);
Sean Callanan76264762010-04-02 22:27:05 +000073 bool ParseShift(enum ShiftType &St, const MCExpr *&ShiftAmount, SMLoc &E);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000074 bool ParseDirectiveWord(unsigned Size, SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000075 bool ParseDirectiveThumb(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000076 bool ParseDirectiveThumbFunc(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000077 bool ParseDirectiveCode(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000078 bool ParseDirectiveSyntax(SMLoc L);
79
Chris Lattner7036f8b2010-09-29 01:42:58 +000080 bool MatchAndEmitInstruction(SMLoc IDLoc,
Chris Lattner7c51a312010-09-29 01:50:45 +000081 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chris Lattnerfa42fad2010-10-28 21:28:01 +000082 MCStreamer &Out);
Jim Grosbach16c74252010-10-29 14:46:02 +000083
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000084 /// @name Auto-generated Match Functions
85 /// {
Daniel Dunbar3483aca2010-08-11 05:24:50 +000086
Chris Lattner0692ee62010-09-06 19:11:01 +000087#define GET_ASSEMBLER_HEADER
88#include "ARMGenAsmMatcher.inc"
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000089
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000090 /// }
91
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000092public:
Daniel Dunbard73ada72010-07-19 00:33:49 +000093 ARMAsmParser(const Target &T, MCAsmParser &_Parser, TargetMachine &_TM)
Jim Grosbach833c93c2010-11-01 16:59:54 +000094 : TargetAsmParser(T), Parser(_Parser), TM(_TM) {
95 // Initialize the set of available features.
96 setAvailableFeatures(ComputeAvailableFeatures(
97 &TM.getSubtarget<ARMSubtarget>()));
98 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000099
Benjamin Kramer38e59892010-07-14 22:38:02 +0000100 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Chris Lattner98986712010-01-14 22:21:20 +0000101 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000102 virtual bool ParseDirective(AsmToken DirectiveID);
103};
Jim Grosbach16c74252010-10-29 14:46:02 +0000104} // end anonymous namespace
105
Chris Lattner3a697562010-10-28 17:20:03 +0000106namespace {
107
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000108/// ARMOperand - Instances of this class represent a parsed ARM machine
109/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000110class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000111 enum KindTy {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000112 CondCode,
Jim Grosbachd67641b2010-12-06 18:21:12 +0000113 CCOut,
Kevin Enderbycfe07242009-10-13 22:19:02 +0000114 Immediate,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000115 Memory,
116 Register,
Bill Wendling8d5acb72010-11-06 19:56:04 +0000117 RegisterList,
Bill Wendling0f630752010-11-17 04:32:08 +0000118 DPRRegisterList,
119 SPRRegisterList,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000120 Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000121 } Kind;
122
Sean Callanan76264762010-04-02 22:27:05 +0000123 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000124 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000125
126 union {
127 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000128 ARMCC::CondCodes Val;
129 } CC;
130
131 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000132 const char *Data;
133 unsigned Length;
134 } Tok;
135
136 struct {
137 unsigned RegNum;
138 } Reg;
139
Bill Wendling8155e5b2010-11-06 22:19:43 +0000140 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000141 const MCExpr *Val;
142 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000143
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000144 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000145 struct {
146 unsigned BaseRegNum;
Bill Wendling146018f2010-11-06 21:42:12 +0000147 unsigned OffsetRegNum; // used when OffsetIsReg is true
148 const MCExpr *Offset; // used when OffsetIsReg is false
149 const MCExpr *ShiftAmount; // used when OffsetRegShifted is true
150 enum ShiftType ShiftType; // used when OffsetRegShifted is true
151 unsigned OffsetRegShifted : 1; // only used when OffsetIsReg is true
Bill Wendling50d0f582010-11-18 23:43:05 +0000152 unsigned Preindexed : 1;
153 unsigned Postindexed : 1;
154 unsigned OffsetIsReg : 1;
155 unsigned Negative : 1; // only used when OffsetIsReg is true
156 unsigned Writeback : 1;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000157 } Mem;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000158 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000159
Bill Wendling146018f2010-11-06 21:42:12 +0000160 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
161public:
Sean Callanan76264762010-04-02 22:27:05 +0000162 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
163 Kind = o.Kind;
164 StartLoc = o.StartLoc;
165 EndLoc = o.EndLoc;
166 switch (Kind) {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000167 case CondCode:
168 CC = o.CC;
169 break;
Sean Callanan76264762010-04-02 22:27:05 +0000170 case Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000171 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000172 break;
Jim Grosbachd67641b2010-12-06 18:21:12 +0000173 case CCOut:
Sean Callanan76264762010-04-02 22:27:05 +0000174 case Register:
175 Reg = o.Reg;
176 break;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000177 case RegisterList:
Bill Wendling0f630752010-11-17 04:32:08 +0000178 case DPRRegisterList:
179 case SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000180 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000181 break;
Sean Callanan76264762010-04-02 22:27:05 +0000182 case Immediate:
183 Imm = o.Imm;
184 break;
185 case Memory:
186 Mem = o.Mem;
187 break;
188 }
189 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000190
Sean Callanan76264762010-04-02 22:27:05 +0000191 /// getStartLoc - Get the location of the first token of this operand.
192 SMLoc getStartLoc() const { return StartLoc; }
193 /// getEndLoc - Get the location of the last token of this operand.
194 SMLoc getEndLoc() const { return EndLoc; }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000195
Daniel Dunbar8462b302010-08-11 06:36:53 +0000196 ARMCC::CondCodes getCondCode() const {
197 assert(Kind == CondCode && "Invalid access!");
198 return CC.Val;
199 }
200
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000201 StringRef getToken() const {
202 assert(Kind == Token && "Invalid access!");
203 return StringRef(Tok.Data, Tok.Length);
204 }
205
206 unsigned getReg() const {
Benjamin Kramer6aa49432010-12-07 15:50:35 +0000207 assert((Kind == Register || Kind == CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000208 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000209 }
210
Bill Wendling5fa22a12010-11-09 23:28:44 +0000211 const SmallVectorImpl<unsigned> &getRegList() const {
Bill Wendling0f630752010-11-17 04:32:08 +0000212 assert((Kind == RegisterList || Kind == DPRRegisterList ||
213 Kind == SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000214 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000215 }
216
Kevin Enderbycfe07242009-10-13 22:19:02 +0000217 const MCExpr *getImm() const {
218 assert(Kind == Immediate && "Invalid access!");
219 return Imm.Val;
220 }
221
Daniel Dunbar8462b302010-08-11 06:36:53 +0000222 bool isCondCode() const { return Kind == CondCode; }
Jim Grosbachd67641b2010-12-06 18:21:12 +0000223 bool isCCOut() const { return Kind == CCOut; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000224 bool isImm() const { return Kind == Immediate; }
Bill Wendlingb32e7842010-11-08 00:32:40 +0000225 bool isReg() const { return Kind == Register; }
Bill Wendling8d5acb72010-11-06 19:56:04 +0000226 bool isRegList() const { return Kind == RegisterList; }
Bill Wendling0f630752010-11-17 04:32:08 +0000227 bool isDPRRegList() const { return Kind == DPRRegisterList; }
228 bool isSPRRegList() const { return Kind == SPRRegisterList; }
Chris Lattner14b93852010-10-29 00:27:31 +0000229 bool isToken() const { return Kind == Token; }
230 bool isMemory() const { return Kind == Memory; }
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000231 bool isMemMode5() const {
232 if (!isMemory() || Mem.OffsetIsReg || Mem.OffsetRegShifted ||
233 Mem.Writeback || Mem.Negative)
234 return false;
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000235
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000236 // If there is an offset expression, make sure it's valid.
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000237 if (!Mem.Offset) return true;
238
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000239 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000240 if (!CE) return false;
241
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000242 // The offset must be a multiple of 4 in the range 0-1020.
243 int64_t Value = CE->getValue();
244 return ((Value & 0x3) == 0 && Value <= 1020 && Value >= -1020);
245 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000246 bool isMemModeRegThumb() const {
247 if (!isMemory() || (!Mem.OffsetIsReg && !Mem.Offset) || Mem.Writeback)
248 return false;
249 return !Mem.Offset || !isa<MCConstantExpr>(Mem.Offset);
250 }
251 bool isMemModeImmThumb() const {
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000252 if (!isMemory() || (!Mem.OffsetIsReg && !Mem.Offset) || Mem.Writeback)
253 return false;
254
Bill Wendlingf4caf692010-12-14 03:36:38 +0000255 if (!Mem.Offset) return false;
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000256
257 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
258 if (!CE) return false;
259
260 // The offset must be a multiple of 4 in the range 0-124.
261 uint64_t Value = CE->getValue();
262 return ((Value & 0x3) == 0 && Value <= 124);
263 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000264
265 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +0000266 // Add as immediates when possible. Null MCExpr = 0.
267 if (Expr == 0)
268 Inst.addOperand(MCOperand::CreateImm(0));
269 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000270 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
271 else
272 Inst.addOperand(MCOperand::CreateExpr(Expr));
273 }
274
Daniel Dunbar8462b302010-08-11 06:36:53 +0000275 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000276 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000277 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +0000278 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
279 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +0000280 }
281
Jim Grosbachd67641b2010-12-06 18:21:12 +0000282 void addCCOutOperands(MCInst &Inst, unsigned N) const {
283 assert(N == 1 && "Invalid number of operands!");
284 Inst.addOperand(MCOperand::CreateReg(getReg()));
285 }
286
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000287 void addRegOperands(MCInst &Inst, unsigned N) const {
288 assert(N == 1 && "Invalid number of operands!");
289 Inst.addOperand(MCOperand::CreateReg(getReg()));
290 }
291
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000292 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +0000293 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +0000294 const SmallVectorImpl<unsigned> &RegList = getRegList();
295 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000296 I = RegList.begin(), E = RegList.end(); I != E; ++I)
297 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000298 }
299
Bill Wendling0f630752010-11-17 04:32:08 +0000300 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
301 addRegListOperands(Inst, N);
302 }
303
304 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
305 addRegListOperands(Inst, N);
306 }
307
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000308 void addImmOperands(MCInst &Inst, unsigned N) const {
309 assert(N == 1 && "Invalid number of operands!");
310 addExpr(Inst, getImm());
311 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000312
Chris Lattner14b93852010-10-29 00:27:31 +0000313 void addMemMode5Operands(MCInst &Inst, unsigned N) const {
314 assert(N == 2 && isMemMode5() && "Invalid number of operands!");
Jim Grosbach16c74252010-10-29 14:46:02 +0000315
Chris Lattner14b93852010-10-29 00:27:31 +0000316 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
Bill Wendlinga60f1572010-11-06 10:48:18 +0000317 assert(!Mem.OffsetIsReg && "Invalid mode 5 operand");
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000318
Jim Grosbach80eb2332010-10-29 17:41:25 +0000319 // FIXME: #-0 is encoded differently than #0. Does the parser preserve
320 // the difference?
321 if (Mem.Offset) {
322 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000323 assert(CE && "Non-constant mode 5 offset operand!");
324
Jim Grosbach80eb2332010-10-29 17:41:25 +0000325 // The MCInst offset operand doesn't include the low two bits (like
326 // the instruction encoding).
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000327 int64_t Offset = CE->getValue() / 4;
328 if (Offset >= 0)
329 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add,
330 Offset)));
331 else
332 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub,
333 -Offset)));
334 } else {
Jim Grosbach80eb2332010-10-29 17:41:25 +0000335 Inst.addOperand(MCOperand::CreateImm(0));
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000336 }
Chris Lattner14b93852010-10-29 00:27:31 +0000337 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000338
Bill Wendlingf4caf692010-12-14 03:36:38 +0000339 void addMemModeRegThumbOperands(MCInst &Inst, unsigned N) const {
340 assert(N == 2 && isMemModeRegThumb() && "Invalid number of operands!");
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000341 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
Bill Wendlingf4caf692010-12-14 03:36:38 +0000342 Inst.addOperand(MCOperand::CreateReg(Mem.OffsetRegNum));
343 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000344
Bill Wendlingf4caf692010-12-14 03:36:38 +0000345 void addMemModeImmThumbOperands(MCInst &Inst, unsigned N) const {
346 assert(N == 2 && isMemModeImmThumb() && "Invalid number of operands!");
347 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
348 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
349 assert(CE && "Non-constant mode offset operand!");
350 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000351 }
352
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000353 virtual void dump(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +0000354
Chris Lattner3a697562010-10-28 17:20:03 +0000355 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
356 ARMOperand *Op = new ARMOperand(CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000357 Op->CC.Val = CC;
358 Op->StartLoc = S;
359 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000360 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000361 }
362
Jim Grosbachd67641b2010-12-06 18:21:12 +0000363 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
364 ARMOperand *Op = new ARMOperand(CCOut);
365 Op->Reg.RegNum = RegNum;
366 Op->StartLoc = S;
367 Op->EndLoc = S;
368 return Op;
369 }
370
Chris Lattner3a697562010-10-28 17:20:03 +0000371 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
372 ARMOperand *Op = new ARMOperand(Token);
Sean Callanan76264762010-04-02 22:27:05 +0000373 Op->Tok.Data = Str.data();
374 Op->Tok.Length = Str.size();
375 Op->StartLoc = S;
376 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000377 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000378 }
379
Bill Wendling50d0f582010-11-18 23:43:05 +0000380 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Chris Lattner3a697562010-10-28 17:20:03 +0000381 ARMOperand *Op = new ARMOperand(Register);
Sean Callanan76264762010-04-02 22:27:05 +0000382 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +0000383 Op->StartLoc = S;
384 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000385 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000386 }
387
Bill Wendling7729e062010-11-09 22:44:22 +0000388 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +0000389 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000390 SMLoc StartLoc, SMLoc EndLoc) {
Bill Wendling0f630752010-11-17 04:32:08 +0000391 KindTy Kind = RegisterList;
392
393 if (ARM::DPRRegClass.contains(Regs.front().first))
394 Kind = DPRRegisterList;
395 else if (ARM::SPRRegClass.contains(Regs.front().first))
396 Kind = SPRRegisterList;
397
398 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +0000399 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000400 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +0000401 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +0000402 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000403 Op->StartLoc = StartLoc;
404 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000405 return Op;
406 }
407
Chris Lattner3a697562010-10-28 17:20:03 +0000408 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
409 ARMOperand *Op = new ARMOperand(Immediate);
Sean Callanan76264762010-04-02 22:27:05 +0000410 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +0000411 Op->StartLoc = S;
412 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000413 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +0000414 }
415
Chris Lattner3a697562010-10-28 17:20:03 +0000416 static ARMOperand *CreateMem(unsigned BaseRegNum, bool OffsetIsReg,
417 const MCExpr *Offset, unsigned OffsetRegNum,
418 bool OffsetRegShifted, enum ShiftType ShiftType,
419 const MCExpr *ShiftAmount, bool Preindexed,
420 bool Postindexed, bool Negative, bool Writeback,
421 SMLoc S, SMLoc E) {
422 ARMOperand *Op = new ARMOperand(Memory);
Sean Callanan76264762010-04-02 22:27:05 +0000423 Op->Mem.BaseRegNum = BaseRegNum;
424 Op->Mem.OffsetIsReg = OffsetIsReg;
425 Op->Mem.Offset = Offset;
426 Op->Mem.OffsetRegNum = OffsetRegNum;
427 Op->Mem.OffsetRegShifted = OffsetRegShifted;
428 Op->Mem.ShiftType = ShiftType;
429 Op->Mem.ShiftAmount = ShiftAmount;
430 Op->Mem.Preindexed = Preindexed;
431 Op->Mem.Postindexed = Postindexed;
432 Op->Mem.Negative = Negative;
433 Op->Mem.Writeback = Writeback;
Jim Grosbach16c74252010-10-29 14:46:02 +0000434
Sean Callanan76264762010-04-02 22:27:05 +0000435 Op->StartLoc = S;
436 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000437 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000438 }
439};
440
441} // end anonymous namespace.
442
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000443void ARMOperand::dump(raw_ostream &OS) const {
444 switch (Kind) {
445 case CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000446 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000447 break;
Jim Grosbachd67641b2010-12-06 18:21:12 +0000448 case CCOut:
449 OS << "<ccout " << getReg() << ">";
450 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000451 case Immediate:
452 getImm()->print(OS);
453 break;
454 case Memory:
Bill Wendling50d0f582010-11-18 23:43:05 +0000455 OS << "<memory>";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000456 break;
457 case Register:
Bill Wendling50d0f582010-11-18 23:43:05 +0000458 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000459 break;
Bill Wendling0f630752010-11-17 04:32:08 +0000460 case RegisterList:
461 case DPRRegisterList:
462 case SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +0000463 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000464
Bill Wendling5fa22a12010-11-09 23:28:44 +0000465 const SmallVectorImpl<unsigned> &RegList = getRegList();
466 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000467 I = RegList.begin(), E = RegList.end(); I != E; ) {
468 OS << *I;
469 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000470 }
471
472 OS << ">";
473 break;
474 }
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000475 case Token:
476 OS << "'" << getToken() << "'";
477 break;
478 }
479}
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000480
481/// @name Auto-generated Match Functions
482/// {
483
484static unsigned MatchRegisterName(StringRef Name);
485
486/// }
487
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000488/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +0000489/// and if it is a register name the token is eaten and the register number is
490/// returned. Otherwise return -1.
491///
492int ARMAsmParser::TryParseRegister() {
493 const AsmToken &Tok = Parser.getTok();
494 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
Jim Grosbachd4462a52010-11-01 16:44:21 +0000495
Chris Lattnere5658fa2010-10-30 04:09:10 +0000496 // FIXME: Validate register for the current architecture; we have to do
497 // validation later, so maybe there is no need for this here.
Bill Wendlingd68fd9c2010-11-06 10:45:34 +0000498 unsigned RegNum = MatchRegisterName(Tok.getString());
499 if (RegNum == 0)
Chris Lattnere5658fa2010-10-30 04:09:10 +0000500 return -1;
501 Parser.Lex(); // Eat identifier token.
502 return RegNum;
503}
Jim Grosbachd4462a52010-11-01 16:44:21 +0000504
505
Bill Wendling50d0f582010-11-18 23:43:05 +0000506/// Try to parse a register name. The token must be an Identifier when called.
507/// If it's a register, an AsmOperand is created. Another AsmOperand is created
508/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +0000509///
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000510/// TODO this is likely to change to allow different register types and or to
511/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +0000512bool ARMAsmParser::
513TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +0000514 SMLoc S = Parser.getTok().getLoc();
515 int RegNo = TryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +0000516 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +0000517 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +0000518
Bill Wendling50d0f582010-11-18 23:43:05 +0000519 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000520
Chris Lattnere5658fa2010-10-30 04:09:10 +0000521 const AsmToken &ExclaimTok = Parser.getTok();
522 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +0000523 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
524 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +0000525 Parser.Lex(); // Eat exclaim token
Kevin Enderby99e6d4e2009-10-07 18:01:35 +0000526 }
527
Bill Wendling50d0f582010-11-18 23:43:05 +0000528 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000529}
530
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000531static int MatchMCRName(StringRef Name) {
532 // Use the same layout as the tablegen'erated register name matcher. Ugly,
533 // but efficient.
534 switch (Name.size()) {
535 default: break;
536 case 2:
537 if (Name[0] != 'p' && Name[0] != 'c')
538 return -1;
539 switch (Name[1]) {
540 default: return -1;
541 case '0': return 0;
542 case '1': return 1;
543 case '2': return 2;
544 case '3': return 3;
545 case '4': return 4;
546 case '5': return 5;
547 case '6': return 6;
548 case '7': return 7;
549 case '8': return 8;
550 case '9': return 9;
551 }
552 break;
553 case 3:
554 if ((Name[0] != 'p' && Name[0] != 'c') || Name[1] != '1')
555 return -1;
556 switch (Name[2]) {
557 default: return -1;
558 case '0': return 10;
559 case '1': return 11;
560 case '2': return 12;
561 case '3': return 13;
562 case '4': return 14;
563 case '5': return 15;
564 }
565 break;
566 }
567
568 llvm_unreachable("Unhandled coprocessor operand string!");
569 return -1;
570}
571
572/// TryParseMCRName - Try to parse an MCR/MRC symbolic operand
573/// name. The token must be an Identifier when called, and if it is a MCR
574/// operand name, the token is eaten and the operand is added to the
575/// operand list.
576bool ARMAsmParser::
577TryParseMCRName(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
578 SMLoc S = Parser.getTok().getLoc();
579 const AsmToken &Tok = Parser.getTok();
580 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
581
582 int Num = MatchMCRName(Tok.getString());
583 if (Num == -1)
584 return true;
585
586 Parser.Lex(); // Eat identifier token.
587 Operands.push_back(ARMOperand::CreateImm(
588 MCConstantExpr::Create(Num, getContext()), S, Parser.getTok().getLoc()));
589 return false;
590}
591
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000592/// Parse a register list, return it if successful else return null. The first
593/// token must be a '{' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +0000594bool ARMAsmParser::
595ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +0000596 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +0000597 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +0000598 SMLoc S = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000599
Bill Wendling7729e062010-11-09 22:44:22 +0000600 // Read the rest of the registers in the list.
601 unsigned PrevRegNum = 0;
Bill Wendling5fa22a12010-11-09 23:28:44 +0000602 SmallVector<std::pair<unsigned, SMLoc>, 32> Registers;
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000603
Bill Wendling7729e062010-11-09 22:44:22 +0000604 do {
Bill Wendlinge7176102010-11-06 22:36:58 +0000605 bool IsRange = Parser.getTok().is(AsmToken::Minus);
Bill Wendling7729e062010-11-09 22:44:22 +0000606 Parser.Lex(); // Eat non-identifier token.
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000607
Sean Callanan18b83232010-01-19 21:44:56 +0000608 const AsmToken &RegTok = Parser.getTok();
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000609 SMLoc RegLoc = RegTok.getLoc();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000610 if (RegTok.isNot(AsmToken::Identifier)) {
611 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000612 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000613 }
Bill Wendlinge7176102010-11-06 22:36:58 +0000614
Bill Wendling1d6a2652010-11-06 10:40:24 +0000615 int RegNum = TryParseRegister();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000616 if (RegNum == -1) {
617 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000618 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000619 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000620
Bill Wendlinge7176102010-11-06 22:36:58 +0000621 if (IsRange) {
622 int Reg = PrevRegNum;
623 do {
624 ++Reg;
625 Registers.push_back(std::make_pair(Reg, RegLoc));
626 } while (Reg != RegNum);
627 } else {
628 Registers.push_back(std::make_pair(RegNum, RegLoc));
629 }
630
631 PrevRegNum = RegNum;
Bill Wendling7729e062010-11-09 22:44:22 +0000632 } while (Parser.getTok().is(AsmToken::Comma) ||
633 Parser.getTok().is(AsmToken::Minus));
Bill Wendlinge7176102010-11-06 22:36:58 +0000634
635 // Process the right curly brace of the list.
Sean Callanan18b83232010-01-19 21:44:56 +0000636 const AsmToken &RCurlyTok = Parser.getTok();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000637 if (RCurlyTok.isNot(AsmToken::RCurly)) {
638 Error(RCurlyTok.getLoc(), "'}' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000639 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000640 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000641
Bill Wendlinge7176102010-11-06 22:36:58 +0000642 SMLoc E = RCurlyTok.getLoc();
643 Parser.Lex(); // Eat right curly brace token.
Jim Grosbach03f44a02010-11-29 23:18:01 +0000644
Bill Wendlinge7176102010-11-06 22:36:58 +0000645 // Verify the register list.
Bill Wendling5fa22a12010-11-09 23:28:44 +0000646 SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendlinge7176102010-11-06 22:36:58 +0000647 RI = Registers.begin(), RE = Registers.end();
648
Bill Wendling7caebff2011-01-12 21:20:59 +0000649 unsigned HighRegNum = getARMRegisterNumbering(RI->first);
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000650 bool EmittedWarning = false;
651
Bill Wendling7caebff2011-01-12 21:20:59 +0000652 DenseMap<unsigned, bool> RegMap;
653 RegMap[HighRegNum] = true;
654
Bill Wendlinge7176102010-11-06 22:36:58 +0000655 for (++RI; RI != RE; ++RI) {
Bill Wendling7729e062010-11-09 22:44:22 +0000656 const std::pair<unsigned, SMLoc> &RegInfo = *RI;
Bill Wendling7caebff2011-01-12 21:20:59 +0000657 unsigned Reg = getARMRegisterNumbering(RegInfo.first);
Bill Wendlinge7176102010-11-06 22:36:58 +0000658
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000659 if (RegMap[Reg]) {
Bill Wendlinge7176102010-11-06 22:36:58 +0000660 Error(RegInfo.second, "register duplicated in register list");
Bill Wendling50d0f582010-11-18 23:43:05 +0000661 return true;
Bill Wendlinge7176102010-11-06 22:36:58 +0000662 }
663
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000664 if (!EmittedWarning && Reg < HighRegNum)
Bill Wendlinge7176102010-11-06 22:36:58 +0000665 Warning(RegInfo.second,
666 "register not in ascending order in register list");
667
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000668 RegMap[Reg] = true;
669 HighRegNum = std::max(Reg, HighRegNum);
Bill Wendlinge7176102010-11-06 22:36:58 +0000670 }
671
Bill Wendling50d0f582010-11-18 23:43:05 +0000672 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
673 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000674}
675
Bill Wendlinge7176102010-11-06 22:36:58 +0000676/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000677/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +0000678///
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000679/// TODO Only preindexing and postindexing addressing are started, unindexed
680/// with option, etc are still to do.
Bill Wendling50d0f582010-11-18 23:43:05 +0000681bool ARMAsmParser::
682ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +0000683 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +0000684 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +0000685 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +0000686 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000687 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000688
Sean Callanan18b83232010-01-19 21:44:56 +0000689 const AsmToken &BaseRegTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +0000690 if (BaseRegTok.isNot(AsmToken::Identifier)) {
691 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000692 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000693 }
Chris Lattnere5658fa2010-10-30 04:09:10 +0000694 int BaseRegNum = TryParseRegister();
695 if (BaseRegNum == -1) {
Chris Lattner550276e2010-10-28 20:52:15 +0000696 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000697 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000698 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000699
700 bool Preindexed = false;
701 bool Postindexed = false;
702 bool OffsetIsReg = false;
703 bool Negative = false;
704 bool Writeback = false;
705
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000706 // First look for preindexed address forms, that is after the "[Rn" we now
707 // have to see if the next token is a comma.
Sean Callanan18b83232010-01-19 21:44:56 +0000708 const AsmToken &Tok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000709 if (Tok.is(AsmToken::Comma)) {
710 Preindexed = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000711 Parser.Lex(); // Eat comma token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000712 int OffsetRegNum;
713 bool OffsetRegShifted;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000714 enum ShiftType ShiftType;
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000715 const MCExpr *ShiftAmount = 0;
716 const MCExpr *Offset = 0;
Chris Lattner550276e2010-10-28 20:52:15 +0000717 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType, ShiftAmount,
718 Offset, OffsetIsReg, OffsetRegNum, E))
Bill Wendling50d0f582010-11-18 23:43:05 +0000719 return true;
Sean Callanan18b83232010-01-19 21:44:56 +0000720 const AsmToken &RBracTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +0000721 if (RBracTok.isNot(AsmToken::RBrac)) {
722 Error(RBracTok.getLoc(), "']' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000723 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000724 }
Sean Callanan76264762010-04-02 22:27:05 +0000725 E = RBracTok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000726 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000727
Jim Grosbach03f44a02010-11-29 23:18:01 +0000728
Sean Callanan18b83232010-01-19 21:44:56 +0000729 const AsmToken &ExclaimTok = Parser.getTok();
Bill Wendling50d0f582010-11-18 23:43:05 +0000730 ARMOperand *WBOp = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000731 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +0000732 WBOp = ARMOperand::CreateToken(ExclaimTok.getString(),
733 ExclaimTok.getLoc());
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000734 Writeback = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000735 Parser.Lex(); // Eat exclaim token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000736 }
Bill Wendling50d0f582010-11-18 23:43:05 +0000737
738 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, OffsetIsReg, Offset,
739 OffsetRegNum, OffsetRegShifted,
740 ShiftType, ShiftAmount, Preindexed,
741 Postindexed, Negative, Writeback,
742 S, E));
743 if (WBOp)
744 Operands.push_back(WBOp);
745
746 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000747 }
748 // The "[Rn" we have so far was not followed by a comma.
749 else if (Tok.is(AsmToken::RBrac)) {
Jim Grosbach80eb2332010-10-29 17:41:25 +0000750 // If there's anything other than the right brace, this is a post indexing
751 // addressing form.
Sean Callanan76264762010-04-02 22:27:05 +0000752 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000753 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000754
Kevin Enderbye2a98dd2009-10-15 21:42:45 +0000755 int OffsetRegNum = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000756 bool OffsetRegShifted = false;
Jim Grosbach00a257a2010-11-29 23:41:10 +0000757 enum ShiftType ShiftType = Lsl;
758 const MCExpr *ShiftAmount = 0;
Chris Lattner14b93852010-10-29 00:27:31 +0000759 const MCExpr *Offset = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000760
Sean Callanan18b83232010-01-19 21:44:56 +0000761 const AsmToken &NextTok = Parser.getTok();
Jim Grosbach03f44a02010-11-29 23:18:01 +0000762
Kevin Enderbye2a98dd2009-10-15 21:42:45 +0000763 if (NextTok.isNot(AsmToken::EndOfStatement)) {
Jim Grosbach80eb2332010-10-29 17:41:25 +0000764 Postindexed = true;
765 Writeback = true;
Bill Wendling50d0f582010-11-18 23:43:05 +0000766
Chris Lattner550276e2010-10-28 20:52:15 +0000767 if (NextTok.isNot(AsmToken::Comma)) {
768 Error(NextTok.getLoc(), "',' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000769 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000770 }
Bill Wendling50d0f582010-11-18 23:43:05 +0000771
Sean Callananb9a25b72010-01-19 20:27:46 +0000772 Parser.Lex(); // Eat comma token.
Bill Wendling50d0f582010-11-18 23:43:05 +0000773
Chris Lattner550276e2010-10-28 20:52:15 +0000774 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType,
Jim Grosbach16c74252010-10-29 14:46:02 +0000775 ShiftAmount, Offset, OffsetIsReg, OffsetRegNum,
Chris Lattner550276e2010-10-28 20:52:15 +0000776 E))
Bill Wendling50d0f582010-11-18 23:43:05 +0000777 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000778 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000779
Bill Wendling50d0f582010-11-18 23:43:05 +0000780 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, OffsetIsReg, Offset,
781 OffsetRegNum, OffsetRegShifted,
782 ShiftType, ShiftAmount, Preindexed,
783 Postindexed, Negative, Writeback,
784 S, E));
785 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000786 }
787
Bill Wendling50d0f582010-11-18 23:43:05 +0000788 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000789}
790
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000791/// Parse the offset of a memory operand after we have seen "[Rn," or "[Rn],"
792/// we will parse the following (were +/- means that a plus or minus is
793/// optional):
794/// +/-Rm
795/// +/-Rm, shift
796/// #offset
797/// we return false on success or an error otherwise.
798bool ARMAsmParser::ParseMemoryOffsetReg(bool &Negative,
Sean Callanan76264762010-04-02 22:27:05 +0000799 bool &OffsetRegShifted,
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000800 enum ShiftType &ShiftType,
801 const MCExpr *&ShiftAmount,
802 const MCExpr *&Offset,
803 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +0000804 int &OffsetRegNum,
805 SMLoc &E) {
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000806 Negative = false;
807 OffsetRegShifted = false;
808 OffsetIsReg = false;
809 OffsetRegNum = -1;
Sean Callanan18b83232010-01-19 21:44:56 +0000810 const AsmToken &NextTok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +0000811 E = NextTok.getLoc();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000812 if (NextTok.is(AsmToken::Plus))
Sean Callananb9a25b72010-01-19 20:27:46 +0000813 Parser.Lex(); // Eat plus token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000814 else if (NextTok.is(AsmToken::Minus)) {
815 Negative = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000816 Parser.Lex(); // Eat minus token
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000817 }
818 // See if there is a register following the "[Rn," or "[Rn]," we have so far.
Sean Callanan18b83232010-01-19 21:44:56 +0000819 const AsmToken &OffsetRegTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000820 if (OffsetRegTok.is(AsmToken::Identifier)) {
Chris Lattnere5658fa2010-10-30 04:09:10 +0000821 SMLoc CurLoc = OffsetRegTok.getLoc();
822 OffsetRegNum = TryParseRegister();
823 if (OffsetRegNum != -1) {
Chris Lattner550276e2010-10-28 20:52:15 +0000824 OffsetIsReg = true;
Chris Lattnere5658fa2010-10-30 04:09:10 +0000825 E = CurLoc;
Sean Callanan76264762010-04-02 22:27:05 +0000826 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000827 }
Jim Grosbachd4462a52010-11-01 16:44:21 +0000828
Bill Wendling12f40e92010-11-06 10:51:53 +0000829 // If we parsed a register as the offset then there can be a shift after that.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000830 if (OffsetRegNum != -1) {
831 // Look for a comma then a shift
Sean Callanan18b83232010-01-19 21:44:56 +0000832 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000833 if (Tok.is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +0000834 Parser.Lex(); // Eat comma token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000835
Sean Callanan18b83232010-01-19 21:44:56 +0000836 const AsmToken &Tok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +0000837 if (ParseShift(ShiftType, ShiftAmount, E))
Duncan Sands34727662010-07-12 08:16:59 +0000838 return Error(Tok.getLoc(), "shift expected");
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000839 OffsetRegShifted = true;
840 }
841 }
842 else { // the "[Rn," or "[Rn,]" we have so far was not followed by "Rm"
843 // Look for #offset following the "[Rn," or "[Rn],"
Sean Callanan18b83232010-01-19 21:44:56 +0000844 const AsmToken &HashTok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000845 if (HashTok.isNot(AsmToken::Hash))
846 return Error(HashTok.getLoc(), "'#' expected");
Jim Grosbach16c74252010-10-29 14:46:02 +0000847
Sean Callananb9a25b72010-01-19 20:27:46 +0000848 Parser.Lex(); // Eat hash token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000849
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000850 if (getParser().ParseExpression(Offset))
851 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000852 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000853 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000854 return false;
855}
856
857/// ParseShift as one of these two:
858/// ( lsl | lsr | asr | ror ) , # shift_amount
859/// rrx
860/// and returns true if it parses a shift otherwise it returns false.
Jim Grosbach16c74252010-10-29 14:46:02 +0000861bool ARMAsmParser::ParseShift(ShiftType &St, const MCExpr *&ShiftAmount,
Sean Callanan76264762010-04-02 22:27:05 +0000862 SMLoc &E) {
Sean Callanan18b83232010-01-19 21:44:56 +0000863 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000864 if (Tok.isNot(AsmToken::Identifier))
865 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +0000866 StringRef ShiftName = Tok.getString();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000867 if (ShiftName == "lsl" || ShiftName == "LSL")
868 St = Lsl;
869 else if (ShiftName == "lsr" || ShiftName == "LSR")
870 St = Lsr;
871 else if (ShiftName == "asr" || ShiftName == "ASR")
872 St = Asr;
873 else if (ShiftName == "ror" || ShiftName == "ROR")
874 St = Ror;
875 else if (ShiftName == "rrx" || ShiftName == "RRX")
876 St = Rrx;
877 else
878 return true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000879 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000880
881 // Rrx stands alone.
882 if (St == Rrx)
883 return false;
884
885 // Otherwise, there must be a '#' and a shift amount.
Sean Callanan18b83232010-01-19 21:44:56 +0000886 const AsmToken &HashTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000887 if (HashTok.isNot(AsmToken::Hash))
888 return Error(HashTok.getLoc(), "'#' expected");
Sean Callananb9a25b72010-01-19 20:27:46 +0000889 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000890
891 if (getParser().ParseExpression(ShiftAmount))
892 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000893
894 return false;
895}
896
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000897/// Parse a arm instruction operand. For now this parses the operand regardless
898/// of the mnemonic.
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000899bool ARMAsmParser::ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
900 bool isMCR){
Sean Callanan76264762010-04-02 22:27:05 +0000901 SMLoc S, E;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000902 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +0000903 default:
904 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +0000905 return true;
Kevin Enderby67b212e2011-01-13 20:32:36 +0000906 case AsmToken::Identifier:
Bill Wendling50d0f582010-11-18 23:43:05 +0000907 if (!TryParseRegisterWithWriteBack(Operands))
908 return false;
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000909 if (isMCR && !TryParseMCRName(Operands))
910 return false;
911
912 // Fall though for the Identifier case that is not a register or a
913 // special name.
Kevin Enderby67b212e2011-01-13 20:32:36 +0000914 case AsmToken::Integer: // things like 1f and 2b as a branch targets
915 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +0000916 // This was not a register so parse other operands that start with an
917 // identifier (like labels) as expressions and create them as immediates.
918 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +0000919 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +0000920 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +0000921 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000922 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +0000923 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
924 return false;
925 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000926 case AsmToken::LBrac:
Bill Wendling50d0f582010-11-18 23:43:05 +0000927 return ParseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000928 case AsmToken::LCurly:
Bill Wendling50d0f582010-11-18 23:43:05 +0000929 return ParseRegisterList(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000930 case AsmToken::Hash:
Kevin Enderby079469f2009-10-13 23:33:38 +0000931 // #42 -> immediate.
932 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
Sean Callanan76264762010-04-02 22:27:05 +0000933 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000934 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +0000935 const MCExpr *ImmVal;
936 if (getParser().ParseExpression(ImmVal))
Bill Wendling50d0f582010-11-18 23:43:05 +0000937 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000938 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +0000939 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
940 return false;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000941 case AsmToken::Colon: {
942 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +0000943 // FIXME: Check it's an expression prefix,
944 // e.g. (FOO - :lower16:BAR) isn't legal.
945 ARMMCExpr::VariantKind RefKind;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000946 if (ParsePrefix(RefKind))
947 return true;
948
Evan Cheng75972122011-01-13 07:58:56 +0000949 const MCExpr *SubExprVal;
950 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +0000951 return true;
952
Evan Cheng75972122011-01-13 07:58:56 +0000953 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
954 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +0000955 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +0000956 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +0000957 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000958 }
Jason W Kim9081b4b2011-01-11 23:53:41 +0000959 }
960}
961
Evan Cheng75972122011-01-13 07:58:56 +0000962// ParsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
963// :lower16: and :upper16:.
964bool ARMAsmParser::ParsePrefix(ARMMCExpr::VariantKind &RefKind) {
965 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000966
967 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +0000968 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +0000969 Parser.Lex(); // Eat ':'
970
971 if (getLexer().isNot(AsmToken::Identifier)) {
972 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
973 return true;
974 }
975
976 StringRef IDVal = Parser.getTok().getIdentifier();
977 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +0000978 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000979 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +0000980 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000981 } else {
982 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
983 return true;
984 }
985 Parser.Lex();
986
987 if (getLexer().isNot(AsmToken::Colon)) {
988 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
989 return true;
990 }
991 Parser.Lex(); // Eat the last ':'
992 return false;
993}
994
995const MCExpr *
996ARMAsmParser::ApplyPrefixToExpr(const MCExpr *E,
997 MCSymbolRefExpr::VariantKind Variant) {
998 // Recurse over the given expression, rebuilding it to apply the given variant
999 // to the leftmost symbol.
1000 if (Variant == MCSymbolRefExpr::VK_None)
1001 return E;
1002
1003 switch (E->getKind()) {
1004 case MCExpr::Target:
1005 llvm_unreachable("Can't handle target expr yet");
1006 case MCExpr::Constant:
1007 llvm_unreachable("Can't handle lower16/upper16 of constant yet");
1008
1009 case MCExpr::SymbolRef: {
1010 const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E);
1011
1012 if (SRE->getKind() != MCSymbolRefExpr::VK_None)
1013 return 0;
1014
1015 return MCSymbolRefExpr::Create(&SRE->getSymbol(), Variant, getContext());
1016 }
1017
1018 case MCExpr::Unary:
1019 llvm_unreachable("Can't handle unary expressions yet");
1020
1021 case MCExpr::Binary: {
1022 const MCBinaryExpr *BE = cast<MCBinaryExpr>(E);
1023 const MCExpr *LHS = ApplyPrefixToExpr(BE->getLHS(), Variant);
1024 const MCExpr *RHS = BE->getRHS();
1025 if (!LHS)
1026 return 0;
1027
1028 return MCBinaryExpr::Create(BE->getOpcode(), LHS, RHS, getContext());
1029 }
1030 }
1031
1032 assert(0 && "Invalid expression kind!");
1033 return 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001034}
1035
Daniel Dunbar352e1482011-01-11 15:59:50 +00001036/// \brief Given a mnemonic, split out possible predication code and carry
1037/// setting letters to form a canonical mnemonic and flags.
1038//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001039// FIXME: Would be nice to autogen this.
Daniel Dunbar352e1482011-01-11 15:59:50 +00001040static StringRef SplitMnemonicAndCC(StringRef Mnemonic,
1041 unsigned &PredicationCode,
1042 bool &CarrySetting) {
1043 PredicationCode = ARMCC::AL;
1044 CarrySetting = false;
1045
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001046 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00001047 //
1048 // FIXME: Would be nice to autogen this.
Daniel Dunbar8ab11122011-01-10 21:01:03 +00001049 if (Mnemonic == "teq" || Mnemonic == "vceq" ||
1050 Mnemonic == "movs" ||
1051 Mnemonic == "svc" ||
1052 (Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
1053 Mnemonic == "vmls" || Mnemonic == "vnmls") ||
1054 Mnemonic == "vacge" || Mnemonic == "vcge" ||
1055 Mnemonic == "vclt" ||
1056 Mnemonic == "vacgt" || Mnemonic == "vcgt" ||
1057 Mnemonic == "vcle" ||
1058 (Mnemonic == "smlal" || Mnemonic == "umaal" || Mnemonic == "umlal" ||
1059 Mnemonic == "vabal" || Mnemonic == "vmlal" || Mnemonic == "vpadal" ||
1060 Mnemonic == "vqdmlal"))
Daniel Dunbar352e1482011-01-11 15:59:50 +00001061 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00001062
Daniel Dunbar352e1482011-01-11 15:59:50 +00001063 // First, split out any predication code.
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001064 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001065 .Case("eq", ARMCC::EQ)
1066 .Case("ne", ARMCC::NE)
1067 .Case("hs", ARMCC::HS)
1068 .Case("lo", ARMCC::LO)
1069 .Case("mi", ARMCC::MI)
1070 .Case("pl", ARMCC::PL)
1071 .Case("vs", ARMCC::VS)
1072 .Case("vc", ARMCC::VC)
1073 .Case("hi", ARMCC::HI)
1074 .Case("ls", ARMCC::LS)
1075 .Case("ge", ARMCC::GE)
1076 .Case("lt", ARMCC::LT)
1077 .Case("gt", ARMCC::GT)
1078 .Case("le", ARMCC::LE)
1079 .Case("al", ARMCC::AL)
1080 .Default(~0U);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001081 if (CC != ~0U) {
1082 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
Daniel Dunbar352e1482011-01-11 15:59:50 +00001083 PredicationCode = CC;
Bill Wendling52925b62010-10-29 23:50:21 +00001084 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001085
Daniel Dunbar352e1482011-01-11 15:59:50 +00001086 // Next, determine if we have a carry setting bit. We explicitly ignore all
1087 // the instructions we know end in 's'.
1088 if (Mnemonic.endswith("s") &&
1089 !(Mnemonic == "asrs" || Mnemonic == "cps" || Mnemonic == "mls" ||
1090 Mnemonic == "movs" || Mnemonic == "mrs" || Mnemonic == "smmls" ||
1091 Mnemonic == "vabs" || Mnemonic == "vcls" || Mnemonic == "vmls" ||
1092 Mnemonic == "vmrs" || Mnemonic == "vnmls" || Mnemonic == "vqabs" ||
1093 Mnemonic == "vrecps" || Mnemonic == "vrsqrts")) {
1094 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
1095 CarrySetting = true;
1096 }
1097
1098 return Mnemonic;
1099}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001100
1101/// \brief Given a canonical mnemonic, determine if the instruction ever allows
1102/// inclusion of carry set or predication code operands.
1103//
1104// FIXME: It would be nice to autogen this.
1105static void GetMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
1106 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001107 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
1108 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
1109 Mnemonic == "smull" || Mnemonic == "add" || Mnemonic == "adc" ||
1110 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
1111 Mnemonic == "umlal" || Mnemonic == "orr" || Mnemonic == "mov" ||
1112 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
1113 Mnemonic == "sbc" || Mnemonic == "mla" || Mnemonic == "umull" ||
1114 Mnemonic == "eor" || Mnemonic == "smlal" || Mnemonic == "mvn") {
1115 CanAcceptCarrySet = true;
1116 } else {
1117 CanAcceptCarrySet = false;
1118 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001119
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001120 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
1121 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
1122 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
1123 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
1124 Mnemonic == "dsb" || Mnemonic == "movs") {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001125 CanAcceptPredicationCode = false;
1126 } else {
1127 CanAcceptPredicationCode = true;
1128 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001129}
1130
1131/// Parse an arm instruction mnemonic followed by its operands.
1132bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
1133 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1134 // Create the leading tokens for the mnemonic, split by '.' characters.
1135 size_t Start = 0, Next = Name.find('.');
1136 StringRef Head = Name.slice(Start, Next);
1137
Daniel Dunbar352e1482011-01-11 15:59:50 +00001138 // Split out the predication code and carry setting flag from the mnemonic.
1139 unsigned PredicationCode;
1140 bool CarrySetting;
1141 Head = SplitMnemonicAndCC(Head, PredicationCode, CarrySetting);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001142
Chris Lattner3a697562010-10-28 17:20:03 +00001143 Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
Bill Wendling9717fa92010-11-21 10:56:05 +00001144
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001145 // Next, add the CCOut and ConditionCode operands, if needed.
1146 //
1147 // For mnemonics which can ever incorporate a carry setting bit or predication
1148 // code, our matching model involves us always generating CCOut and
1149 // ConditionCode operands to match the mnemonic "as written" and then we let
1150 // the matcher deal with finding the right instruction or generating an
1151 // appropriate error.
1152 bool CanAcceptCarrySet, CanAcceptPredicationCode;
1153 GetMnemonicAcceptInfo(Head, CanAcceptCarrySet, CanAcceptPredicationCode);
1154
1155 // Add the carry setting operand, if necessary.
1156 //
1157 // FIXME: It would be awesome if we could somehow invent a location such that
1158 // match errors on this operand would print a nice diagnostic about how the
1159 // 's' character in the mnemonic resulted in a CCOut operand.
1160 if (CanAcceptCarrySet) {
1161 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
1162 NameLoc));
1163 } else {
1164 // This mnemonic can't ever accept a carry set, but the user wrote one (or
1165 // misspelled another mnemonic).
1166
1167 // FIXME: Issue a nice error.
1168 }
1169
1170 // Add the predication code operand, if necessary.
1171 if (CanAcceptPredicationCode) {
1172 Operands.push_back(ARMOperand::CreateCondCode(
1173 ARMCC::CondCodes(PredicationCode), NameLoc));
1174 } else {
1175 // This mnemonic can't ever accept a predication code, but the user wrote
1176 // one (or misspelled another mnemonic).
1177
1178 // FIXME: Issue a nice error.
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001179 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001180
1181 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00001182 while (Next != StringRef::npos) {
1183 Start = Next;
1184 Next = Name.find('.', Start + 1);
1185 Head = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001186
Chris Lattner3a697562010-10-28 17:20:03 +00001187 Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
Daniel Dunbar5747b132010-08-11 06:37:16 +00001188 }
1189
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001190 bool isMCR = (Head == "mcr" || Head == "mcr2" ||
1191 Head == "mcrr" || Head == "mcrr2" ||
1192 Head == "mrc" || Head == "mrc2" ||
1193 Head == "mrrc" || Head == "mrrc2");
1194
Daniel Dunbar5747b132010-08-11 06:37:16 +00001195 // Read the remaining operands.
1196 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001197 // Read the first operand.
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001198 if (ParseOperand(Operands, isMCR)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00001199 Parser.EatToEndOfStatement();
1200 return true;
1201 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001202
1203 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00001204 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001205
1206 // Parse and remember the operand.
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001207 if (ParseOperand(Operands, isMCR)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00001208 Parser.EatToEndOfStatement();
1209 return true;
1210 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001211 }
1212 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001213
Chris Lattnercbf8a982010-09-11 16:18:25 +00001214 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1215 Parser.EatToEndOfStatement();
Chris Lattner34e53142010-09-08 05:10:46 +00001216 return TokError("unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00001217 }
Bill Wendling146018f2010-11-06 21:42:12 +00001218
Chris Lattner34e53142010-09-08 05:10:46 +00001219 Parser.Lex(); // Consume the EndOfStatement
Chris Lattner98986712010-01-14 22:21:20 +00001220 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001221}
1222
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001223bool ARMAsmParser::
1224MatchAndEmitInstruction(SMLoc IDLoc,
1225 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
1226 MCStreamer &Out) {
1227 MCInst Inst;
1228 unsigned ErrorInfo;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001229 MatchResultTy MatchResult, MatchResult2;
1230 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1231 if (MatchResult != Match_Success) {
1232 // If we get a Match_InvalidOperand it might be some arithmetic instruction
1233 // that does not update the condition codes. So try adding a CCOut operand
1234 // with a value of reg0.
1235 if (MatchResult == Match_InvalidOperand) {
1236 Operands.insert(Operands.begin() + 1,
1237 ARMOperand::CreateCCOut(0,
1238 ((ARMOperand*)Operands[0])->getStartLoc()));
1239 MatchResult2 = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1240 if (MatchResult2 == Match_Success)
1241 MatchResult = Match_Success;
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001242 else {
1243 ARMOperand *CCOut = ((ARMOperand*)Operands[1]);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001244 Operands.erase(Operands.begin() + 1);
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001245 delete CCOut;
1246 }
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001247 }
1248 // If we get a Match_MnemonicFail it might be some arithmetic instruction
1249 // that updates the condition codes if it ends in 's'. So see if the
1250 // mnemonic ends in 's' and if so try removing the 's' and adding a CCOut
1251 // operand with a value of CPSR.
1252 else if(MatchResult == Match_MnemonicFail) {
1253 // Get the instruction mnemonic, which is the first token.
1254 StringRef Mnemonic = ((ARMOperand*)Operands[0])->getToken();
1255 if (Mnemonic.substr(Mnemonic.size()-1) == "s") {
1256 // removed the 's' from the mnemonic for matching.
1257 StringRef MnemonicNoS = Mnemonic.slice(0, Mnemonic.size() - 1);
1258 SMLoc NameLoc = ((ARMOperand*)Operands[0])->getStartLoc();
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001259 ARMOperand *OldMnemonic = ((ARMOperand*)Operands[0]);
1260 Operands.erase(Operands.begin());
1261 delete OldMnemonic;
1262 Operands.insert(Operands.begin(),
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001263 ARMOperand::CreateToken(MnemonicNoS, NameLoc));
1264 Operands.insert(Operands.begin() + 1,
1265 ARMOperand::CreateCCOut(ARM::CPSR, NameLoc));
1266 MatchResult2 = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1267 if (MatchResult2 == Match_Success)
1268 MatchResult = Match_Success;
1269 else {
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001270 ARMOperand *OldMnemonic = ((ARMOperand*)Operands[0]);
1271 Operands.erase(Operands.begin());
1272 delete OldMnemonic;
1273 Operands.insert(Operands.begin(),
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001274 ARMOperand::CreateToken(Mnemonic, NameLoc));
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001275 ARMOperand *CCOut = ((ARMOperand*)Operands[1]);
1276 Operands.erase(Operands.begin() + 1);
1277 delete CCOut;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001278 }
1279 }
1280 }
1281 }
1282 switch (MatchResult) {
Chris Lattnere73d4f82010-10-28 21:41:58 +00001283 case Match_Success:
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001284 Out.EmitInstruction(Inst);
1285 return false;
Chris Lattnere73d4f82010-10-28 21:41:58 +00001286 case Match_MissingFeature:
1287 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
1288 return true;
1289 case Match_InvalidOperand: {
1290 SMLoc ErrorLoc = IDLoc;
1291 if (ErrorInfo != ~0U) {
1292 if (ErrorInfo >= Operands.size())
1293 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00001294
Chris Lattnere73d4f82010-10-28 21:41:58 +00001295 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
1296 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
1297 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001298
Chris Lattnere73d4f82010-10-28 21:41:58 +00001299 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001300 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00001301 case Match_MnemonicFail:
1302 return Error(IDLoc, "unrecognized instruction mnemonic");
1303 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001304
Eric Christopherc223e2b2010-10-29 09:26:59 +00001305 llvm_unreachable("Implement any new match types added!");
Bill Wendling146018f2010-11-06 21:42:12 +00001306 return true;
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001307}
1308
Kevin Enderby515d5092009-10-15 20:48:48 +00001309/// ParseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001310bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
1311 StringRef IDVal = DirectiveID.getIdentifier();
1312 if (IDVal == ".word")
1313 return ParseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00001314 else if (IDVal == ".thumb")
1315 return ParseDirectiveThumb(DirectiveID.getLoc());
1316 else if (IDVal == ".thumb_func")
1317 return ParseDirectiveThumbFunc(DirectiveID.getLoc());
1318 else if (IDVal == ".code")
1319 return ParseDirectiveCode(DirectiveID.getLoc());
1320 else if (IDVal == ".syntax")
1321 return ParseDirectiveSyntax(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001322 return true;
1323}
1324
1325/// ParseDirectiveWord
1326/// ::= .word [ expression (, expression)* ]
1327bool ARMAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
1328 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1329 for (;;) {
1330 const MCExpr *Value;
1331 if (getParser().ParseExpression(Value))
1332 return true;
1333
Chris Lattneraaec2052010-01-19 19:46:13 +00001334 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001335
1336 if (getLexer().is(AsmToken::EndOfStatement))
1337 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00001338
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001339 // FIXME: Improve diagnostic.
1340 if (getLexer().isNot(AsmToken::Comma))
1341 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001342 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001343 }
1344 }
1345
Sean Callananb9a25b72010-01-19 20:27:46 +00001346 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001347 return false;
1348}
1349
Kevin Enderby515d5092009-10-15 20:48:48 +00001350/// ParseDirectiveThumb
1351/// ::= .thumb
1352bool ARMAsmParser::ParseDirectiveThumb(SMLoc L) {
1353 if (getLexer().isNot(AsmToken::EndOfStatement))
1354 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001355 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001356
1357 // TODO: set thumb mode
1358 // TODO: tell the MC streamer the mode
1359 // getParser().getStreamer().Emit???();
1360 return false;
1361}
1362
1363/// ParseDirectiveThumbFunc
1364/// ::= .thumbfunc symbol_name
1365bool ARMAsmParser::ParseDirectiveThumbFunc(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001366 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001367 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
Jim Grosbach83c40182010-11-05 22:11:33 +00001368 return Error(L, "unexpected token in .thumb_func directive");
Jim Grosbach642fc9c2010-11-05 22:33:53 +00001369 StringRef Name = Tok.getString();
Sean Callananb9a25b72010-01-19 20:27:46 +00001370 Parser.Lex(); // Consume the identifier token.
Kevin Enderby515d5092009-10-15 20:48:48 +00001371 if (getLexer().isNot(AsmToken::EndOfStatement))
1372 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001373 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001374
Jim Grosbach642fc9c2010-11-05 22:33:53 +00001375 // Mark symbol as a thumb symbol.
1376 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
1377 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00001378 return false;
1379}
1380
1381/// ParseDirectiveSyntax
1382/// ::= .syntax unified | divided
1383bool ARMAsmParser::ParseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001384 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001385 if (Tok.isNot(AsmToken::Identifier))
1386 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00001387 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00001388 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00001389 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00001390 else if (Mode == "divided" || Mode == "DIVIDED")
Sean Callananb9a25b72010-01-19 20:27:46 +00001391 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001392 else
1393 return Error(L, "unrecognized syntax mode in .syntax directive");
1394
1395 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00001396 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001397 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001398
1399 // TODO tell the MC streamer the mode
1400 // getParser().getStreamer().Emit???();
1401 return false;
1402}
1403
1404/// ParseDirectiveCode
1405/// ::= .code 16 | 32
1406bool ARMAsmParser::ParseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001407 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001408 if (Tok.isNot(AsmToken::Integer))
1409 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00001410 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00001411 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00001412 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00001413 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00001414 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001415 else
1416 return Error(L, "invalid operand to .code directive");
1417
1418 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00001419 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001420 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001421
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00001422 // FIXME: We need to be able switch subtargets at this point so that
1423 // MatchInstructionImpl() will work when it gets the AvailableFeatures which
1424 // includes Feature_IsThumb or not to match the right instructions. This is
1425 // blocked on the FIXME in llvm-mc.cpp when creating the TargetMachine.
1426 if (Val == 16){
1427 assert(TM.getSubtarget<ARMSubtarget>().isThumb() &&
1428 "switching between arm/thumb not yet suppported via .code 16)");
Jim Grosbach2a301702010-11-05 22:40:53 +00001429 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00001430 }
1431 else{
1432 assert(!TM.getSubtarget<ARMSubtarget>().isThumb() &&
1433 "switching between thumb/arm not yet suppported via .code 32)");
Jim Grosbach2a301702010-11-05 22:40:53 +00001434 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00001435 }
Jim Grosbach2a301702010-11-05 22:40:53 +00001436
Kevin Enderby515d5092009-10-15 20:48:48 +00001437 return false;
1438}
1439
Sean Callanan90b70972010-04-07 20:29:34 +00001440extern "C" void LLVMInitializeARMAsmLexer();
1441
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001442/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001443extern "C" void LLVMInitializeARMAsmParser() {
1444 RegisterAsmParser<ARMAsmParser> X(TheARMTarget);
1445 RegisterAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00001446 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001447}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001448
Chris Lattner0692ee62010-09-06 19:11:01 +00001449#define GET_REGISTER_MATCHER
1450#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001451#include "ARMGenAsmMatcher.inc"