blob: a34fdb66cf256a5fd6b6e269a474476c7199f031 [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"
Owen Anderson0c9f2502011-01-13 22:50:36 +000027#include "llvm/ADT/StringExtras.h"
Daniel Dunbar345a9a62010-08-11 06:37:20 +000028#include "llvm/ADT/StringSwitch.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000029#include "llvm/ADT/Twine.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000030using namespace llvm;
31
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +000032/// Shift types used for register controlled shifts in ARM memory addressing.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000033enum ShiftType {
34 Lsl,
35 Lsr,
36 Asr,
37 Ror,
38 Rrx
39};
40
Chris Lattner3a697562010-10-28 17:20:03 +000041namespace {
Bill Wendling146018f2010-11-06 21:42:12 +000042
43class ARMOperand;
Jim Grosbach16c74252010-10-29 14:46:02 +000044
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000045class ARMAsmParser : public TargetAsmParser {
46 MCAsmParser &Parser;
Daniel Dunbard73ada72010-07-19 00:33:49 +000047 TargetMachine &TM;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000048
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000049 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000050 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
51
52 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000053 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
54
Chris Lattnere5658fa2010-10-30 04:09:10 +000055 int TryParseRegister();
Owen Andersone4e5e2a2011-01-13 21:46:02 +000056 bool TryParseMCRName(SmallVectorImpl<MCParsedAsmOperand*>&);
Bill Wendling50d0f582010-11-18 23:43:05 +000057 bool TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
58 bool ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
59 bool ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Owen Andersone4e5e2a2011-01-13 21:46:02 +000060 bool ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, bool isMCR);
Evan Cheng75972122011-01-13 07:58:56 +000061 bool ParsePrefix(ARMMCExpr::VariantKind &RefKind);
Jason W Kim9081b4b2011-01-11 23:53:41 +000062 const MCExpr *ApplyPrefixToExpr(const MCExpr *E,
63 MCSymbolRefExpr::VariantKind Variant);
64
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000065
Kevin Enderby9c41fa82009-10-30 22:55:57 +000066 bool ParseMemoryOffsetReg(bool &Negative,
67 bool &OffsetRegShifted,
68 enum ShiftType &ShiftType,
69 const MCExpr *&ShiftAmount,
70 const MCExpr *&Offset,
71 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +000072 int &OffsetRegNum,
73 SMLoc &E);
Sean Callanan76264762010-04-02 22:27:05 +000074 bool ParseShift(enum ShiftType &St, 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);
Jim Grosbach16c74252010-10-29 14:46:02 +000084
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000085 /// @name Auto-generated Match Functions
86 /// {
Daniel Dunbar3483aca2010-08-11 05:24:50 +000087
Chris Lattner0692ee62010-09-06 19:11:01 +000088#define GET_ASSEMBLER_HEADER
89#include "ARMGenAsmMatcher.inc"
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000090
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000091 /// }
92
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000093public:
Daniel Dunbard73ada72010-07-19 00:33:49 +000094 ARMAsmParser(const Target &T, MCAsmParser &_Parser, TargetMachine &_TM)
Jim Grosbach833c93c2010-11-01 16:59:54 +000095 : TargetAsmParser(T), Parser(_Parser), TM(_TM) {
96 // Initialize the set of available features.
97 setAvailableFeatures(ComputeAvailableFeatures(
98 &TM.getSubtarget<ARMSubtarget>()));
99 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000100
Benjamin Kramer38e59892010-07-14 22:38:02 +0000101 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Chris Lattner98986712010-01-14 22:21:20 +0000102 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000103 virtual bool ParseDirective(AsmToken DirectiveID);
104};
Jim Grosbach16c74252010-10-29 14:46:02 +0000105} // end anonymous namespace
106
Chris Lattner3a697562010-10-28 17:20:03 +0000107namespace {
108
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000109/// ARMOperand - Instances of this class represent a parsed ARM machine
110/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000111class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000112 enum KindTy {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000113 CondCode,
Jim Grosbachd67641b2010-12-06 18:21:12 +0000114 CCOut,
Kevin Enderbycfe07242009-10-13 22:19:02 +0000115 Immediate,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000116 Memory,
117 Register,
Bill Wendling8d5acb72010-11-06 19:56:04 +0000118 RegisterList,
Bill Wendling0f630752010-11-17 04:32:08 +0000119 DPRRegisterList,
120 SPRRegisterList,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000121 Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000122 } Kind;
123
Sean Callanan76264762010-04-02 22:27:05 +0000124 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000125 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000126
127 union {
128 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000129 ARMCC::CondCodes Val;
130 } CC;
131
132 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000133 const char *Data;
134 unsigned Length;
135 } Tok;
136
137 struct {
138 unsigned RegNum;
139 } Reg;
140
Bill Wendling8155e5b2010-11-06 22:19:43 +0000141 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000142 const MCExpr *Val;
143 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000144
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000145 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000146 struct {
147 unsigned BaseRegNum;
Bill Wendling146018f2010-11-06 21:42:12 +0000148 unsigned OffsetRegNum; // used when OffsetIsReg is true
149 const MCExpr *Offset; // used when OffsetIsReg is false
150 const MCExpr *ShiftAmount; // used when OffsetRegShifted is true
151 enum ShiftType ShiftType; // used when OffsetRegShifted is true
152 unsigned OffsetRegShifted : 1; // only used when OffsetIsReg is true
Bill Wendling50d0f582010-11-18 23:43:05 +0000153 unsigned Preindexed : 1;
154 unsigned Postindexed : 1;
155 unsigned OffsetIsReg : 1;
156 unsigned Negative : 1; // only used when OffsetIsReg is true
157 unsigned Writeback : 1;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000158 } Mem;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000159 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000160
Bill Wendling146018f2010-11-06 21:42:12 +0000161 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
162public:
Sean Callanan76264762010-04-02 22:27:05 +0000163 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
164 Kind = o.Kind;
165 StartLoc = o.StartLoc;
166 EndLoc = o.EndLoc;
167 switch (Kind) {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000168 case CondCode:
169 CC = o.CC;
170 break;
Sean Callanan76264762010-04-02 22:27:05 +0000171 case Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000172 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000173 break;
Jim Grosbachd67641b2010-12-06 18:21:12 +0000174 case CCOut:
Sean Callanan76264762010-04-02 22:27:05 +0000175 case Register:
176 Reg = o.Reg;
177 break;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000178 case RegisterList:
Bill Wendling0f630752010-11-17 04:32:08 +0000179 case DPRRegisterList:
180 case SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000181 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000182 break;
Sean Callanan76264762010-04-02 22:27:05 +0000183 case Immediate:
184 Imm = o.Imm;
185 break;
186 case Memory:
187 Mem = o.Mem;
188 break;
189 }
190 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000191
Sean Callanan76264762010-04-02 22:27:05 +0000192 /// getStartLoc - Get the location of the first token of this operand.
193 SMLoc getStartLoc() const { return StartLoc; }
194 /// getEndLoc - Get the location of the last token of this operand.
195 SMLoc getEndLoc() const { return EndLoc; }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000196
Daniel Dunbar8462b302010-08-11 06:36:53 +0000197 ARMCC::CondCodes getCondCode() const {
198 assert(Kind == CondCode && "Invalid access!");
199 return CC.Val;
200 }
201
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000202 StringRef getToken() const {
203 assert(Kind == Token && "Invalid access!");
204 return StringRef(Tok.Data, Tok.Length);
205 }
206
207 unsigned getReg() const {
Benjamin Kramer6aa49432010-12-07 15:50:35 +0000208 assert((Kind == Register || Kind == CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000209 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000210 }
211
Bill Wendling5fa22a12010-11-09 23:28:44 +0000212 const SmallVectorImpl<unsigned> &getRegList() const {
Bill Wendling0f630752010-11-17 04:32:08 +0000213 assert((Kind == RegisterList || Kind == DPRRegisterList ||
214 Kind == SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000215 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000216 }
217
Kevin Enderbycfe07242009-10-13 22:19:02 +0000218 const MCExpr *getImm() const {
219 assert(Kind == Immediate && "Invalid access!");
220 return Imm.Val;
221 }
222
Daniel Dunbar8462b302010-08-11 06:36:53 +0000223 bool isCondCode() const { return Kind == CondCode; }
Jim Grosbachd67641b2010-12-06 18:21:12 +0000224 bool isCCOut() const { return Kind == CCOut; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000225 bool isImm() const { return Kind == Immediate; }
Bill Wendlingb32e7842010-11-08 00:32:40 +0000226 bool isReg() const { return Kind == Register; }
Bill Wendling8d5acb72010-11-06 19:56:04 +0000227 bool isRegList() const { return Kind == RegisterList; }
Bill Wendling0f630752010-11-17 04:32:08 +0000228 bool isDPRRegList() const { return Kind == DPRRegisterList; }
229 bool isSPRRegList() const { return Kind == SPRRegisterList; }
Chris Lattner14b93852010-10-29 00:27:31 +0000230 bool isToken() const { return Kind == Token; }
231 bool isMemory() const { return Kind == Memory; }
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000232 bool isMemMode5() const {
233 if (!isMemory() || Mem.OffsetIsReg || Mem.OffsetRegShifted ||
234 Mem.Writeback || Mem.Negative)
235 return false;
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000236
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000237 // If there is an offset expression, make sure it's valid.
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000238 if (!Mem.Offset) return true;
239
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000240 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000241 if (!CE) return false;
242
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000243 // The offset must be a multiple of 4 in the range 0-1020.
244 int64_t Value = CE->getValue();
245 return ((Value & 0x3) == 0 && Value <= 1020 && Value >= -1020);
246 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000247 bool isMemModeRegThumb() const {
248 if (!isMemory() || (!Mem.OffsetIsReg && !Mem.Offset) || Mem.Writeback)
249 return false;
250 return !Mem.Offset || !isa<MCConstantExpr>(Mem.Offset);
251 }
252 bool isMemModeImmThumb() const {
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000253 if (!isMemory() || (!Mem.OffsetIsReg && !Mem.Offset) || Mem.Writeback)
254 return false;
255
Bill Wendlingf4caf692010-12-14 03:36:38 +0000256 if (!Mem.Offset) return false;
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000257
258 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
259 if (!CE) return false;
260
261 // The offset must be a multiple of 4 in the range 0-124.
262 uint64_t Value = CE->getValue();
263 return ((Value & 0x3) == 0 && Value <= 124);
264 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000265
266 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +0000267 // Add as immediates when possible. Null MCExpr = 0.
268 if (Expr == 0)
269 Inst.addOperand(MCOperand::CreateImm(0));
270 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000271 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
272 else
273 Inst.addOperand(MCOperand::CreateExpr(Expr));
274 }
275
Daniel Dunbar8462b302010-08-11 06:36:53 +0000276 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000277 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000278 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +0000279 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
280 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +0000281 }
282
Jim Grosbachd67641b2010-12-06 18:21:12 +0000283 void addCCOutOperands(MCInst &Inst, unsigned N) const {
284 assert(N == 1 && "Invalid number of operands!");
285 Inst.addOperand(MCOperand::CreateReg(getReg()));
286 }
287
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000288 void addRegOperands(MCInst &Inst, unsigned N) const {
289 assert(N == 1 && "Invalid number of operands!");
290 Inst.addOperand(MCOperand::CreateReg(getReg()));
291 }
292
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000293 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +0000294 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +0000295 const SmallVectorImpl<unsigned> &RegList = getRegList();
296 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000297 I = RegList.begin(), E = RegList.end(); I != E; ++I)
298 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000299 }
300
Bill Wendling0f630752010-11-17 04:32:08 +0000301 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
302 addRegListOperands(Inst, N);
303 }
304
305 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
306 addRegListOperands(Inst, N);
307 }
308
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000309 void addImmOperands(MCInst &Inst, unsigned N) const {
310 assert(N == 1 && "Invalid number of operands!");
311 addExpr(Inst, getImm());
312 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000313
Chris Lattner14b93852010-10-29 00:27:31 +0000314 void addMemMode5Operands(MCInst &Inst, unsigned N) const {
315 assert(N == 2 && isMemMode5() && "Invalid number of operands!");
Jim Grosbach16c74252010-10-29 14:46:02 +0000316
Chris Lattner14b93852010-10-29 00:27:31 +0000317 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
Bill Wendlinga60f1572010-11-06 10:48:18 +0000318 assert(!Mem.OffsetIsReg && "Invalid mode 5 operand");
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000319
Jim Grosbach80eb2332010-10-29 17:41:25 +0000320 // FIXME: #-0 is encoded differently than #0. Does the parser preserve
321 // the difference?
322 if (Mem.Offset) {
323 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000324 assert(CE && "Non-constant mode 5 offset operand!");
325
Jim Grosbach80eb2332010-10-29 17:41:25 +0000326 // The MCInst offset operand doesn't include the low two bits (like
327 // the instruction encoding).
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000328 int64_t Offset = CE->getValue() / 4;
329 if (Offset >= 0)
330 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add,
331 Offset)));
332 else
333 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub,
334 -Offset)));
335 } else {
Jim Grosbach80eb2332010-10-29 17:41:25 +0000336 Inst.addOperand(MCOperand::CreateImm(0));
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000337 }
Chris Lattner14b93852010-10-29 00:27:31 +0000338 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000339
Bill Wendlingf4caf692010-12-14 03:36:38 +0000340 void addMemModeRegThumbOperands(MCInst &Inst, unsigned N) const {
341 assert(N == 2 && isMemModeRegThumb() && "Invalid number of operands!");
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000342 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
Bill Wendlingf4caf692010-12-14 03:36:38 +0000343 Inst.addOperand(MCOperand::CreateReg(Mem.OffsetRegNum));
344 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000345
Bill Wendlingf4caf692010-12-14 03:36:38 +0000346 void addMemModeImmThumbOperands(MCInst &Inst, unsigned N) const {
347 assert(N == 2 && isMemModeImmThumb() && "Invalid number of operands!");
348 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
349 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
350 assert(CE && "Non-constant mode offset operand!");
351 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000352 }
353
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000354 virtual void dump(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +0000355
Chris Lattner3a697562010-10-28 17:20:03 +0000356 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
357 ARMOperand *Op = new ARMOperand(CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000358 Op->CC.Val = CC;
359 Op->StartLoc = S;
360 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000361 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000362 }
363
Jim Grosbachd67641b2010-12-06 18:21:12 +0000364 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
365 ARMOperand *Op = new ARMOperand(CCOut);
366 Op->Reg.RegNum = RegNum;
367 Op->StartLoc = S;
368 Op->EndLoc = S;
369 return Op;
370 }
371
Chris Lattner3a697562010-10-28 17:20:03 +0000372 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
373 ARMOperand *Op = new ARMOperand(Token);
Sean Callanan76264762010-04-02 22:27:05 +0000374 Op->Tok.Data = Str.data();
375 Op->Tok.Length = Str.size();
376 Op->StartLoc = S;
377 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000378 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000379 }
380
Bill Wendling50d0f582010-11-18 23:43:05 +0000381 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Chris Lattner3a697562010-10-28 17:20:03 +0000382 ARMOperand *Op = new ARMOperand(Register);
Sean Callanan76264762010-04-02 22:27:05 +0000383 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +0000384 Op->StartLoc = S;
385 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000386 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000387 }
388
Bill Wendling7729e062010-11-09 22:44:22 +0000389 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +0000390 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000391 SMLoc StartLoc, SMLoc EndLoc) {
Bill Wendling0f630752010-11-17 04:32:08 +0000392 KindTy Kind = RegisterList;
393
394 if (ARM::DPRRegClass.contains(Regs.front().first))
395 Kind = DPRRegisterList;
396 else if (ARM::SPRRegClass.contains(Regs.front().first))
397 Kind = SPRRegisterList;
398
399 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +0000400 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000401 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +0000402 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +0000403 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000404 Op->StartLoc = StartLoc;
405 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000406 return Op;
407 }
408
Chris Lattner3a697562010-10-28 17:20:03 +0000409 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
410 ARMOperand *Op = new ARMOperand(Immediate);
Sean Callanan76264762010-04-02 22:27:05 +0000411 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +0000412 Op->StartLoc = S;
413 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000414 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +0000415 }
416
Chris Lattner3a697562010-10-28 17:20:03 +0000417 static ARMOperand *CreateMem(unsigned BaseRegNum, bool OffsetIsReg,
418 const MCExpr *Offset, unsigned OffsetRegNum,
419 bool OffsetRegShifted, enum ShiftType ShiftType,
420 const MCExpr *ShiftAmount, bool Preindexed,
421 bool Postindexed, bool Negative, bool Writeback,
422 SMLoc S, SMLoc E) {
423 ARMOperand *Op = new ARMOperand(Memory);
Sean Callanan76264762010-04-02 22:27:05 +0000424 Op->Mem.BaseRegNum = BaseRegNum;
425 Op->Mem.OffsetIsReg = OffsetIsReg;
426 Op->Mem.Offset = Offset;
427 Op->Mem.OffsetRegNum = OffsetRegNum;
428 Op->Mem.OffsetRegShifted = OffsetRegShifted;
429 Op->Mem.ShiftType = ShiftType;
430 Op->Mem.ShiftAmount = ShiftAmount;
431 Op->Mem.Preindexed = Preindexed;
432 Op->Mem.Postindexed = Postindexed;
433 Op->Mem.Negative = Negative;
434 Op->Mem.Writeback = Writeback;
Jim Grosbach16c74252010-10-29 14:46:02 +0000435
Sean Callanan76264762010-04-02 22:27:05 +0000436 Op->StartLoc = S;
437 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000438 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000439 }
440};
441
442} // end anonymous namespace.
443
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000444void ARMOperand::dump(raw_ostream &OS) const {
445 switch (Kind) {
446 case CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000447 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000448 break;
Jim Grosbachd67641b2010-12-06 18:21:12 +0000449 case CCOut:
450 OS << "<ccout " << getReg() << ">";
451 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000452 case Immediate:
453 getImm()->print(OS);
454 break;
455 case Memory:
Bill Wendling50d0f582010-11-18 23:43:05 +0000456 OS << "<memory>";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000457 break;
458 case Register:
Bill Wendling50d0f582010-11-18 23:43:05 +0000459 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000460 break;
Bill Wendling0f630752010-11-17 04:32:08 +0000461 case RegisterList:
462 case DPRRegisterList:
463 case SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +0000464 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000465
Bill Wendling5fa22a12010-11-09 23:28:44 +0000466 const SmallVectorImpl<unsigned> &RegList = getRegList();
467 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000468 I = RegList.begin(), E = RegList.end(); I != E; ) {
469 OS << *I;
470 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000471 }
472
473 OS << ">";
474 break;
475 }
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000476 case Token:
477 OS << "'" << getToken() << "'";
478 break;
479 }
480}
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000481
482/// @name Auto-generated Match Functions
483/// {
484
485static unsigned MatchRegisterName(StringRef Name);
486
487/// }
488
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000489/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +0000490/// and if it is a register name the token is eaten and the register number is
491/// returned. Otherwise return -1.
492///
493int ARMAsmParser::TryParseRegister() {
494 const AsmToken &Tok = Parser.getTok();
495 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
Jim Grosbachd4462a52010-11-01 16:44:21 +0000496
Chris Lattnere5658fa2010-10-30 04:09:10 +0000497 // FIXME: Validate register for the current architecture; we have to do
498 // validation later, so maybe there is no need for this here.
Owen Anderson0c9f2502011-01-13 22:50:36 +0000499 std::string upperCase = Tok.getString().str();
500 std::string lowerCase = LowercaseString(upperCase);
501 unsigned RegNum = MatchRegisterName(lowerCase);
502 if (!RegNum) {
503 RegNum = StringSwitch<unsigned>(lowerCase)
504 .Case("r13", ARM::SP)
505 .Case("r14", ARM::LR)
506 .Case("r15", ARM::PC)
507 .Case("ip", ARM::R12)
508 .Default(0);
509 }
510 if (!RegNum) return -1;
511
Chris Lattnere5658fa2010-10-30 04:09:10 +0000512 Parser.Lex(); // Eat identifier token.
513 return RegNum;
514}
Jim Grosbachd4462a52010-11-01 16:44:21 +0000515
516
Bill Wendling50d0f582010-11-18 23:43:05 +0000517/// Try to parse a register name. The token must be an Identifier when called.
518/// If it's a register, an AsmOperand is created. Another AsmOperand is created
519/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +0000520///
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000521/// TODO this is likely to change to allow different register types and or to
522/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +0000523bool ARMAsmParser::
524TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +0000525 SMLoc S = Parser.getTok().getLoc();
526 int RegNo = TryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +0000527 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +0000528 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +0000529
Bill Wendling50d0f582010-11-18 23:43:05 +0000530 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000531
Chris Lattnere5658fa2010-10-30 04:09:10 +0000532 const AsmToken &ExclaimTok = Parser.getTok();
533 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +0000534 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
535 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +0000536 Parser.Lex(); // Eat exclaim token
Kevin Enderby99e6d4e2009-10-07 18:01:35 +0000537 }
538
Bill Wendling50d0f582010-11-18 23:43:05 +0000539 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000540}
541
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000542static int MatchMCRName(StringRef Name) {
543 // Use the same layout as the tablegen'erated register name matcher. Ugly,
544 // but efficient.
545 switch (Name.size()) {
546 default: break;
547 case 2:
548 if (Name[0] != 'p' && Name[0] != 'c')
549 return -1;
550 switch (Name[1]) {
551 default: return -1;
552 case '0': return 0;
553 case '1': return 1;
554 case '2': return 2;
555 case '3': return 3;
556 case '4': return 4;
557 case '5': return 5;
558 case '6': return 6;
559 case '7': return 7;
560 case '8': return 8;
561 case '9': return 9;
562 }
563 break;
564 case 3:
565 if ((Name[0] != 'p' && Name[0] != 'c') || Name[1] != '1')
566 return -1;
567 switch (Name[2]) {
568 default: return -1;
569 case '0': return 10;
570 case '1': return 11;
571 case '2': return 12;
572 case '3': return 13;
573 case '4': return 14;
574 case '5': return 15;
575 }
576 break;
577 }
578
579 llvm_unreachable("Unhandled coprocessor operand string!");
580 return -1;
581}
582
583/// TryParseMCRName - Try to parse an MCR/MRC symbolic operand
584/// name. The token must be an Identifier when called, and if it is a MCR
585/// operand name, the token is eaten and the operand is added to the
586/// operand list.
587bool ARMAsmParser::
588TryParseMCRName(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
589 SMLoc S = Parser.getTok().getLoc();
590 const AsmToken &Tok = Parser.getTok();
591 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
592
593 int Num = MatchMCRName(Tok.getString());
594 if (Num == -1)
595 return true;
596
597 Parser.Lex(); // Eat identifier token.
598 Operands.push_back(ARMOperand::CreateImm(
599 MCConstantExpr::Create(Num, getContext()), S, Parser.getTok().getLoc()));
600 return false;
601}
602
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000603/// Parse a register list, return it if successful else return null. The first
604/// token must be a '{' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +0000605bool ARMAsmParser::
606ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +0000607 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +0000608 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +0000609 SMLoc S = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000610
Bill Wendling7729e062010-11-09 22:44:22 +0000611 // Read the rest of the registers in the list.
612 unsigned PrevRegNum = 0;
Bill Wendling5fa22a12010-11-09 23:28:44 +0000613 SmallVector<std::pair<unsigned, SMLoc>, 32> Registers;
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000614
Bill Wendling7729e062010-11-09 22:44:22 +0000615 do {
Bill Wendlinge7176102010-11-06 22:36:58 +0000616 bool IsRange = Parser.getTok().is(AsmToken::Minus);
Bill Wendling7729e062010-11-09 22:44:22 +0000617 Parser.Lex(); // Eat non-identifier token.
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000618
Sean Callanan18b83232010-01-19 21:44:56 +0000619 const AsmToken &RegTok = Parser.getTok();
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000620 SMLoc RegLoc = RegTok.getLoc();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000621 if (RegTok.isNot(AsmToken::Identifier)) {
622 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000623 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000624 }
Bill Wendlinge7176102010-11-06 22:36:58 +0000625
Bill Wendling1d6a2652010-11-06 10:40:24 +0000626 int RegNum = TryParseRegister();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000627 if (RegNum == -1) {
628 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000629 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000630 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000631
Bill Wendlinge7176102010-11-06 22:36:58 +0000632 if (IsRange) {
633 int Reg = PrevRegNum;
634 do {
635 ++Reg;
636 Registers.push_back(std::make_pair(Reg, RegLoc));
637 } while (Reg != RegNum);
638 } else {
639 Registers.push_back(std::make_pair(RegNum, RegLoc));
640 }
641
642 PrevRegNum = RegNum;
Bill Wendling7729e062010-11-09 22:44:22 +0000643 } while (Parser.getTok().is(AsmToken::Comma) ||
644 Parser.getTok().is(AsmToken::Minus));
Bill Wendlinge7176102010-11-06 22:36:58 +0000645
646 // Process the right curly brace of the list.
Sean Callanan18b83232010-01-19 21:44:56 +0000647 const AsmToken &RCurlyTok = Parser.getTok();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000648 if (RCurlyTok.isNot(AsmToken::RCurly)) {
649 Error(RCurlyTok.getLoc(), "'}' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000650 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000651 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000652
Bill Wendlinge7176102010-11-06 22:36:58 +0000653 SMLoc E = RCurlyTok.getLoc();
654 Parser.Lex(); // Eat right curly brace token.
Jim Grosbach03f44a02010-11-29 23:18:01 +0000655
Bill Wendlinge7176102010-11-06 22:36:58 +0000656 // Verify the register list.
Bill Wendling5fa22a12010-11-09 23:28:44 +0000657 SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendlinge7176102010-11-06 22:36:58 +0000658 RI = Registers.begin(), RE = Registers.end();
659
Bill Wendling7caebff2011-01-12 21:20:59 +0000660 unsigned HighRegNum = getARMRegisterNumbering(RI->first);
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000661 bool EmittedWarning = false;
662
Bill Wendling7caebff2011-01-12 21:20:59 +0000663 DenseMap<unsigned, bool> RegMap;
664 RegMap[HighRegNum] = true;
665
Bill Wendlinge7176102010-11-06 22:36:58 +0000666 for (++RI; RI != RE; ++RI) {
Bill Wendling7729e062010-11-09 22:44:22 +0000667 const std::pair<unsigned, SMLoc> &RegInfo = *RI;
Bill Wendling7caebff2011-01-12 21:20:59 +0000668 unsigned Reg = getARMRegisterNumbering(RegInfo.first);
Bill Wendlinge7176102010-11-06 22:36:58 +0000669
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000670 if (RegMap[Reg]) {
Bill Wendlinge7176102010-11-06 22:36:58 +0000671 Error(RegInfo.second, "register duplicated in register list");
Bill Wendling50d0f582010-11-18 23:43:05 +0000672 return true;
Bill Wendlinge7176102010-11-06 22:36:58 +0000673 }
674
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000675 if (!EmittedWarning && Reg < HighRegNum)
Bill Wendlinge7176102010-11-06 22:36:58 +0000676 Warning(RegInfo.second,
677 "register not in ascending order in register list");
678
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000679 RegMap[Reg] = true;
680 HighRegNum = std::max(Reg, HighRegNum);
Bill Wendlinge7176102010-11-06 22:36:58 +0000681 }
682
Bill Wendling50d0f582010-11-18 23:43:05 +0000683 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
684 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000685}
686
Bill Wendlinge7176102010-11-06 22:36:58 +0000687/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000688/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +0000689///
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000690/// TODO Only preindexing and postindexing addressing are started, unindexed
691/// with option, etc are still to do.
Bill Wendling50d0f582010-11-18 23:43:05 +0000692bool ARMAsmParser::
693ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +0000694 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +0000695 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +0000696 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +0000697 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000698 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000699
Sean Callanan18b83232010-01-19 21:44:56 +0000700 const AsmToken &BaseRegTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +0000701 if (BaseRegTok.isNot(AsmToken::Identifier)) {
702 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000703 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000704 }
Chris Lattnere5658fa2010-10-30 04:09:10 +0000705 int BaseRegNum = TryParseRegister();
706 if (BaseRegNum == -1) {
Chris Lattner550276e2010-10-28 20:52:15 +0000707 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000708 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000709 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000710
711 bool Preindexed = false;
712 bool Postindexed = false;
713 bool OffsetIsReg = false;
714 bool Negative = false;
715 bool Writeback = false;
716
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000717 // First look for preindexed address forms, that is after the "[Rn" we now
718 // have to see if the next token is a comma.
Sean Callanan18b83232010-01-19 21:44:56 +0000719 const AsmToken &Tok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000720 if (Tok.is(AsmToken::Comma)) {
721 Preindexed = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000722 Parser.Lex(); // Eat comma token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000723 int OffsetRegNum;
724 bool OffsetRegShifted;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000725 enum ShiftType ShiftType;
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000726 const MCExpr *ShiftAmount = 0;
727 const MCExpr *Offset = 0;
Chris Lattner550276e2010-10-28 20:52:15 +0000728 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType, ShiftAmount,
729 Offset, OffsetIsReg, OffsetRegNum, E))
Bill Wendling50d0f582010-11-18 23:43:05 +0000730 return true;
Sean Callanan18b83232010-01-19 21:44:56 +0000731 const AsmToken &RBracTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +0000732 if (RBracTok.isNot(AsmToken::RBrac)) {
733 Error(RBracTok.getLoc(), "']' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000734 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000735 }
Sean Callanan76264762010-04-02 22:27:05 +0000736 E = RBracTok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000737 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000738
Jim Grosbach03f44a02010-11-29 23:18:01 +0000739
Sean Callanan18b83232010-01-19 21:44:56 +0000740 const AsmToken &ExclaimTok = Parser.getTok();
Bill Wendling50d0f582010-11-18 23:43:05 +0000741 ARMOperand *WBOp = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000742 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +0000743 WBOp = ARMOperand::CreateToken(ExclaimTok.getString(),
744 ExclaimTok.getLoc());
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000745 Writeback = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000746 Parser.Lex(); // Eat exclaim token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000747 }
Bill Wendling50d0f582010-11-18 23:43:05 +0000748
749 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, OffsetIsReg, Offset,
750 OffsetRegNum, OffsetRegShifted,
751 ShiftType, ShiftAmount, Preindexed,
752 Postindexed, Negative, Writeback,
753 S, E));
754 if (WBOp)
755 Operands.push_back(WBOp);
756
757 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000758 }
759 // The "[Rn" we have so far was not followed by a comma.
760 else if (Tok.is(AsmToken::RBrac)) {
Jim Grosbach80eb2332010-10-29 17:41:25 +0000761 // If there's anything other than the right brace, this is a post indexing
762 // addressing form.
Sean Callanan76264762010-04-02 22:27:05 +0000763 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000764 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000765
Kevin Enderbye2a98dd2009-10-15 21:42:45 +0000766 int OffsetRegNum = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000767 bool OffsetRegShifted = false;
Jim Grosbach00a257a2010-11-29 23:41:10 +0000768 enum ShiftType ShiftType = Lsl;
769 const MCExpr *ShiftAmount = 0;
Chris Lattner14b93852010-10-29 00:27:31 +0000770 const MCExpr *Offset = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000771
Sean Callanan18b83232010-01-19 21:44:56 +0000772 const AsmToken &NextTok = Parser.getTok();
Jim Grosbach03f44a02010-11-29 23:18:01 +0000773
Kevin Enderbye2a98dd2009-10-15 21:42:45 +0000774 if (NextTok.isNot(AsmToken::EndOfStatement)) {
Jim Grosbach80eb2332010-10-29 17:41:25 +0000775 Postindexed = true;
776 Writeback = true;
Bill Wendling50d0f582010-11-18 23:43:05 +0000777
Chris Lattner550276e2010-10-28 20:52:15 +0000778 if (NextTok.isNot(AsmToken::Comma)) {
779 Error(NextTok.getLoc(), "',' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000780 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000781 }
Bill Wendling50d0f582010-11-18 23:43:05 +0000782
Sean Callananb9a25b72010-01-19 20:27:46 +0000783 Parser.Lex(); // Eat comma token.
Bill Wendling50d0f582010-11-18 23:43:05 +0000784
Chris Lattner550276e2010-10-28 20:52:15 +0000785 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType,
Jim Grosbach16c74252010-10-29 14:46:02 +0000786 ShiftAmount, Offset, OffsetIsReg, OffsetRegNum,
Chris Lattner550276e2010-10-28 20:52:15 +0000787 E))
Bill Wendling50d0f582010-11-18 23:43:05 +0000788 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000789 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000790
Bill Wendling50d0f582010-11-18 23:43:05 +0000791 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, OffsetIsReg, Offset,
792 OffsetRegNum, OffsetRegShifted,
793 ShiftType, ShiftAmount, Preindexed,
794 Postindexed, Negative, Writeback,
795 S, E));
796 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000797 }
798
Bill Wendling50d0f582010-11-18 23:43:05 +0000799 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000800}
801
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000802/// Parse the offset of a memory operand after we have seen "[Rn," or "[Rn],"
803/// we will parse the following (were +/- means that a plus or minus is
804/// optional):
805/// +/-Rm
806/// +/-Rm, shift
807/// #offset
808/// we return false on success or an error otherwise.
809bool ARMAsmParser::ParseMemoryOffsetReg(bool &Negative,
Sean Callanan76264762010-04-02 22:27:05 +0000810 bool &OffsetRegShifted,
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000811 enum ShiftType &ShiftType,
812 const MCExpr *&ShiftAmount,
813 const MCExpr *&Offset,
814 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +0000815 int &OffsetRegNum,
816 SMLoc &E) {
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000817 Negative = false;
818 OffsetRegShifted = false;
819 OffsetIsReg = false;
820 OffsetRegNum = -1;
Sean Callanan18b83232010-01-19 21:44:56 +0000821 const AsmToken &NextTok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +0000822 E = NextTok.getLoc();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000823 if (NextTok.is(AsmToken::Plus))
Sean Callananb9a25b72010-01-19 20:27:46 +0000824 Parser.Lex(); // Eat plus token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000825 else if (NextTok.is(AsmToken::Minus)) {
826 Negative = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000827 Parser.Lex(); // Eat minus token
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000828 }
829 // See if there is a register following the "[Rn," or "[Rn]," we have so far.
Sean Callanan18b83232010-01-19 21:44:56 +0000830 const AsmToken &OffsetRegTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000831 if (OffsetRegTok.is(AsmToken::Identifier)) {
Chris Lattnere5658fa2010-10-30 04:09:10 +0000832 SMLoc CurLoc = OffsetRegTok.getLoc();
833 OffsetRegNum = TryParseRegister();
834 if (OffsetRegNum != -1) {
Chris Lattner550276e2010-10-28 20:52:15 +0000835 OffsetIsReg = true;
Chris Lattnere5658fa2010-10-30 04:09:10 +0000836 E = CurLoc;
Sean Callanan76264762010-04-02 22:27:05 +0000837 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000838 }
Jim Grosbachd4462a52010-11-01 16:44:21 +0000839
Bill Wendling12f40e92010-11-06 10:51:53 +0000840 // If we parsed a register as the offset then there can be a shift after that.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000841 if (OffsetRegNum != -1) {
842 // Look for a comma then a shift
Sean Callanan18b83232010-01-19 21:44:56 +0000843 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000844 if (Tok.is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +0000845 Parser.Lex(); // Eat comma token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000846
Sean Callanan18b83232010-01-19 21:44:56 +0000847 const AsmToken &Tok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +0000848 if (ParseShift(ShiftType, ShiftAmount, E))
Duncan Sands34727662010-07-12 08:16:59 +0000849 return Error(Tok.getLoc(), "shift expected");
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000850 OffsetRegShifted = true;
851 }
852 }
853 else { // the "[Rn," or "[Rn,]" we have so far was not followed by "Rm"
854 // Look for #offset following the "[Rn," or "[Rn],"
Sean Callanan18b83232010-01-19 21:44:56 +0000855 const AsmToken &HashTok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000856 if (HashTok.isNot(AsmToken::Hash))
857 return Error(HashTok.getLoc(), "'#' expected");
Jim Grosbach16c74252010-10-29 14:46:02 +0000858
Sean Callananb9a25b72010-01-19 20:27:46 +0000859 Parser.Lex(); // Eat hash token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000860
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000861 if (getParser().ParseExpression(Offset))
862 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000863 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000864 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000865 return false;
866}
867
868/// ParseShift as one of these two:
869/// ( lsl | lsr | asr | ror ) , # shift_amount
870/// rrx
871/// and returns true if it parses a shift otherwise it returns false.
Jim Grosbach16c74252010-10-29 14:46:02 +0000872bool ARMAsmParser::ParseShift(ShiftType &St, const MCExpr *&ShiftAmount,
Sean Callanan76264762010-04-02 22:27:05 +0000873 SMLoc &E) {
Sean Callanan18b83232010-01-19 21:44:56 +0000874 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000875 if (Tok.isNot(AsmToken::Identifier))
876 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +0000877 StringRef ShiftName = Tok.getString();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000878 if (ShiftName == "lsl" || ShiftName == "LSL")
879 St = Lsl;
880 else if (ShiftName == "lsr" || ShiftName == "LSR")
881 St = Lsr;
882 else if (ShiftName == "asr" || ShiftName == "ASR")
883 St = Asr;
884 else if (ShiftName == "ror" || ShiftName == "ROR")
885 St = Ror;
886 else if (ShiftName == "rrx" || ShiftName == "RRX")
887 St = Rrx;
888 else
889 return true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000890 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000891
892 // Rrx stands alone.
893 if (St == Rrx)
894 return false;
895
896 // Otherwise, there must be a '#' and a shift amount.
Sean Callanan18b83232010-01-19 21:44:56 +0000897 const AsmToken &HashTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000898 if (HashTok.isNot(AsmToken::Hash))
899 return Error(HashTok.getLoc(), "'#' expected");
Sean Callananb9a25b72010-01-19 20:27:46 +0000900 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000901
902 if (getParser().ParseExpression(ShiftAmount))
903 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000904
905 return false;
906}
907
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000908/// Parse a arm instruction operand. For now this parses the operand regardless
909/// of the mnemonic.
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000910bool ARMAsmParser::ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
911 bool isMCR){
Sean Callanan76264762010-04-02 22:27:05 +0000912 SMLoc S, E;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000913 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +0000914 default:
915 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +0000916 return true;
Kevin Enderby67b212e2011-01-13 20:32:36 +0000917 case AsmToken::Identifier:
Bill Wendling50d0f582010-11-18 23:43:05 +0000918 if (!TryParseRegisterWithWriteBack(Operands))
919 return false;
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000920 if (isMCR && !TryParseMCRName(Operands))
921 return false;
922
923 // Fall though for the Identifier case that is not a register or a
924 // special name.
Kevin Enderby67b212e2011-01-13 20:32:36 +0000925 case AsmToken::Integer: // things like 1f and 2b as a branch targets
926 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +0000927 // This was not a register so parse other operands that start with an
928 // identifier (like labels) as expressions and create them as immediates.
929 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +0000930 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +0000931 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +0000932 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000933 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +0000934 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
935 return false;
936 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000937 case AsmToken::LBrac:
Bill Wendling50d0f582010-11-18 23:43:05 +0000938 return ParseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000939 case AsmToken::LCurly:
Bill Wendling50d0f582010-11-18 23:43:05 +0000940 return ParseRegisterList(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000941 case AsmToken::Hash:
Kevin Enderby079469f2009-10-13 23:33:38 +0000942 // #42 -> immediate.
943 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
Sean Callanan76264762010-04-02 22:27:05 +0000944 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000945 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +0000946 const MCExpr *ImmVal;
947 if (getParser().ParseExpression(ImmVal))
Bill Wendling50d0f582010-11-18 23:43:05 +0000948 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000949 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +0000950 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
951 return false;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000952 case AsmToken::Colon: {
953 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +0000954 // FIXME: Check it's an expression prefix,
955 // e.g. (FOO - :lower16:BAR) isn't legal.
956 ARMMCExpr::VariantKind RefKind;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000957 if (ParsePrefix(RefKind))
958 return true;
959
Evan Cheng75972122011-01-13 07:58:56 +0000960 const MCExpr *SubExprVal;
961 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +0000962 return true;
963
Evan Cheng75972122011-01-13 07:58:56 +0000964 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
965 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +0000966 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +0000967 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +0000968 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000969 }
Jason W Kim9081b4b2011-01-11 23:53:41 +0000970 }
971}
972
Evan Cheng75972122011-01-13 07:58:56 +0000973// ParsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
974// :lower16: and :upper16:.
975bool ARMAsmParser::ParsePrefix(ARMMCExpr::VariantKind &RefKind) {
976 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000977
978 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +0000979 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +0000980 Parser.Lex(); // Eat ':'
981
982 if (getLexer().isNot(AsmToken::Identifier)) {
983 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
984 return true;
985 }
986
987 StringRef IDVal = Parser.getTok().getIdentifier();
988 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +0000989 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000990 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +0000991 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000992 } else {
993 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
994 return true;
995 }
996 Parser.Lex();
997
998 if (getLexer().isNot(AsmToken::Colon)) {
999 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
1000 return true;
1001 }
1002 Parser.Lex(); // Eat the last ':'
1003 return false;
1004}
1005
1006const MCExpr *
1007ARMAsmParser::ApplyPrefixToExpr(const MCExpr *E,
1008 MCSymbolRefExpr::VariantKind Variant) {
1009 // Recurse over the given expression, rebuilding it to apply the given variant
1010 // to the leftmost symbol.
1011 if (Variant == MCSymbolRefExpr::VK_None)
1012 return E;
1013
1014 switch (E->getKind()) {
1015 case MCExpr::Target:
1016 llvm_unreachable("Can't handle target expr yet");
1017 case MCExpr::Constant:
1018 llvm_unreachable("Can't handle lower16/upper16 of constant yet");
1019
1020 case MCExpr::SymbolRef: {
1021 const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E);
1022
1023 if (SRE->getKind() != MCSymbolRefExpr::VK_None)
1024 return 0;
1025
1026 return MCSymbolRefExpr::Create(&SRE->getSymbol(), Variant, getContext());
1027 }
1028
1029 case MCExpr::Unary:
1030 llvm_unreachable("Can't handle unary expressions yet");
1031
1032 case MCExpr::Binary: {
1033 const MCBinaryExpr *BE = cast<MCBinaryExpr>(E);
1034 const MCExpr *LHS = ApplyPrefixToExpr(BE->getLHS(), Variant);
1035 const MCExpr *RHS = BE->getRHS();
1036 if (!LHS)
1037 return 0;
1038
1039 return MCBinaryExpr::Create(BE->getOpcode(), LHS, RHS, getContext());
1040 }
1041 }
1042
1043 assert(0 && "Invalid expression kind!");
1044 return 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001045}
1046
Daniel Dunbar352e1482011-01-11 15:59:50 +00001047/// \brief Given a mnemonic, split out possible predication code and carry
1048/// setting letters to form a canonical mnemonic and flags.
1049//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001050// FIXME: Would be nice to autogen this.
Daniel Dunbar352e1482011-01-11 15:59:50 +00001051static StringRef SplitMnemonicAndCC(StringRef Mnemonic,
1052 unsigned &PredicationCode,
1053 bool &CarrySetting) {
1054 PredicationCode = ARMCC::AL;
1055 CarrySetting = false;
1056
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001057 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00001058 //
1059 // FIXME: Would be nice to autogen this.
Daniel Dunbar8ab11122011-01-10 21:01:03 +00001060 if (Mnemonic == "teq" || Mnemonic == "vceq" ||
1061 Mnemonic == "movs" ||
1062 Mnemonic == "svc" ||
1063 (Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
1064 Mnemonic == "vmls" || Mnemonic == "vnmls") ||
1065 Mnemonic == "vacge" || Mnemonic == "vcge" ||
1066 Mnemonic == "vclt" ||
1067 Mnemonic == "vacgt" || Mnemonic == "vcgt" ||
1068 Mnemonic == "vcle" ||
1069 (Mnemonic == "smlal" || Mnemonic == "umaal" || Mnemonic == "umlal" ||
1070 Mnemonic == "vabal" || Mnemonic == "vmlal" || Mnemonic == "vpadal" ||
1071 Mnemonic == "vqdmlal"))
Daniel Dunbar352e1482011-01-11 15:59:50 +00001072 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00001073
Daniel Dunbar352e1482011-01-11 15:59:50 +00001074 // First, split out any predication code.
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001075 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001076 .Case("eq", ARMCC::EQ)
1077 .Case("ne", ARMCC::NE)
1078 .Case("hs", ARMCC::HS)
1079 .Case("lo", ARMCC::LO)
1080 .Case("mi", ARMCC::MI)
1081 .Case("pl", ARMCC::PL)
1082 .Case("vs", ARMCC::VS)
1083 .Case("vc", ARMCC::VC)
1084 .Case("hi", ARMCC::HI)
1085 .Case("ls", ARMCC::LS)
1086 .Case("ge", ARMCC::GE)
1087 .Case("lt", ARMCC::LT)
1088 .Case("gt", ARMCC::GT)
1089 .Case("le", ARMCC::LE)
1090 .Case("al", ARMCC::AL)
1091 .Default(~0U);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001092 if (CC != ~0U) {
1093 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
Daniel Dunbar352e1482011-01-11 15:59:50 +00001094 PredicationCode = CC;
Bill Wendling52925b62010-10-29 23:50:21 +00001095 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001096
Daniel Dunbar352e1482011-01-11 15:59:50 +00001097 // Next, determine if we have a carry setting bit. We explicitly ignore all
1098 // the instructions we know end in 's'.
1099 if (Mnemonic.endswith("s") &&
1100 !(Mnemonic == "asrs" || Mnemonic == "cps" || Mnemonic == "mls" ||
1101 Mnemonic == "movs" || Mnemonic == "mrs" || Mnemonic == "smmls" ||
1102 Mnemonic == "vabs" || Mnemonic == "vcls" || Mnemonic == "vmls" ||
1103 Mnemonic == "vmrs" || Mnemonic == "vnmls" || Mnemonic == "vqabs" ||
1104 Mnemonic == "vrecps" || Mnemonic == "vrsqrts")) {
1105 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
1106 CarrySetting = true;
1107 }
1108
1109 return Mnemonic;
1110}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001111
1112/// \brief Given a canonical mnemonic, determine if the instruction ever allows
1113/// inclusion of carry set or predication code operands.
1114//
1115// FIXME: It would be nice to autogen this.
1116static void GetMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
1117 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001118 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
1119 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
1120 Mnemonic == "smull" || Mnemonic == "add" || Mnemonic == "adc" ||
1121 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
1122 Mnemonic == "umlal" || Mnemonic == "orr" || Mnemonic == "mov" ||
1123 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
1124 Mnemonic == "sbc" || Mnemonic == "mla" || Mnemonic == "umull" ||
1125 Mnemonic == "eor" || Mnemonic == "smlal" || Mnemonic == "mvn") {
1126 CanAcceptCarrySet = true;
1127 } else {
1128 CanAcceptCarrySet = false;
1129 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001130
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001131 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
1132 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
1133 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
1134 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
1135 Mnemonic == "dsb" || Mnemonic == "movs") {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001136 CanAcceptPredicationCode = false;
1137 } else {
1138 CanAcceptPredicationCode = true;
1139 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001140}
1141
1142/// Parse an arm instruction mnemonic followed by its operands.
1143bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
1144 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1145 // Create the leading tokens for the mnemonic, split by '.' characters.
1146 size_t Start = 0, Next = Name.find('.');
1147 StringRef Head = Name.slice(Start, Next);
1148
Daniel Dunbar352e1482011-01-11 15:59:50 +00001149 // Split out the predication code and carry setting flag from the mnemonic.
1150 unsigned PredicationCode;
1151 bool CarrySetting;
1152 Head = SplitMnemonicAndCC(Head, PredicationCode, CarrySetting);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001153
Chris Lattner3a697562010-10-28 17:20:03 +00001154 Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
Bill Wendling9717fa92010-11-21 10:56:05 +00001155
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001156 // Next, add the CCOut and ConditionCode operands, if needed.
1157 //
1158 // For mnemonics which can ever incorporate a carry setting bit or predication
1159 // code, our matching model involves us always generating CCOut and
1160 // ConditionCode operands to match the mnemonic "as written" and then we let
1161 // the matcher deal with finding the right instruction or generating an
1162 // appropriate error.
1163 bool CanAcceptCarrySet, CanAcceptPredicationCode;
1164 GetMnemonicAcceptInfo(Head, CanAcceptCarrySet, CanAcceptPredicationCode);
1165
1166 // Add the carry setting operand, if necessary.
1167 //
1168 // FIXME: It would be awesome if we could somehow invent a location such that
1169 // match errors on this operand would print a nice diagnostic about how the
1170 // 's' character in the mnemonic resulted in a CCOut operand.
1171 if (CanAcceptCarrySet) {
1172 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
1173 NameLoc));
1174 } else {
1175 // This mnemonic can't ever accept a carry set, but the user wrote one (or
1176 // misspelled another mnemonic).
1177
1178 // FIXME: Issue a nice error.
1179 }
1180
1181 // Add the predication code operand, if necessary.
1182 if (CanAcceptPredicationCode) {
1183 Operands.push_back(ARMOperand::CreateCondCode(
1184 ARMCC::CondCodes(PredicationCode), NameLoc));
1185 } else {
1186 // This mnemonic can't ever accept a predication code, but the user wrote
1187 // one (or misspelled another mnemonic).
1188
1189 // FIXME: Issue a nice error.
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001190 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001191
1192 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00001193 while (Next != StringRef::npos) {
1194 Start = Next;
1195 Next = Name.find('.', Start + 1);
1196 Head = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001197
Chris Lattner3a697562010-10-28 17:20:03 +00001198 Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
Daniel Dunbar5747b132010-08-11 06:37:16 +00001199 }
1200
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001201 bool isMCR = (Head == "mcr" || Head == "mcr2" ||
1202 Head == "mcrr" || Head == "mcrr2" ||
1203 Head == "mrc" || Head == "mrc2" ||
1204 Head == "mrrc" || Head == "mrrc2");
1205
Daniel Dunbar5747b132010-08-11 06:37:16 +00001206 // Read the remaining operands.
1207 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001208 // Read the first operand.
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001209 if (ParseOperand(Operands, isMCR)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00001210 Parser.EatToEndOfStatement();
1211 return true;
1212 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001213
1214 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00001215 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001216
1217 // Parse and remember the operand.
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001218 if (ParseOperand(Operands, isMCR)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00001219 Parser.EatToEndOfStatement();
1220 return true;
1221 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001222 }
1223 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001224
Chris Lattnercbf8a982010-09-11 16:18:25 +00001225 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1226 Parser.EatToEndOfStatement();
Chris Lattner34e53142010-09-08 05:10:46 +00001227 return TokError("unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00001228 }
Bill Wendling146018f2010-11-06 21:42:12 +00001229
Chris Lattner34e53142010-09-08 05:10:46 +00001230 Parser.Lex(); // Consume the EndOfStatement
Chris Lattner98986712010-01-14 22:21:20 +00001231 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001232}
1233
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001234bool ARMAsmParser::
1235MatchAndEmitInstruction(SMLoc IDLoc,
1236 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
1237 MCStreamer &Out) {
1238 MCInst Inst;
1239 unsigned ErrorInfo;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001240 MatchResultTy MatchResult, MatchResult2;
1241 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1242 if (MatchResult != Match_Success) {
1243 // If we get a Match_InvalidOperand it might be some arithmetic instruction
1244 // that does not update the condition codes. So try adding a CCOut operand
1245 // with a value of reg0.
1246 if (MatchResult == Match_InvalidOperand) {
1247 Operands.insert(Operands.begin() + 1,
1248 ARMOperand::CreateCCOut(0,
1249 ((ARMOperand*)Operands[0])->getStartLoc()));
1250 MatchResult2 = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1251 if (MatchResult2 == Match_Success)
1252 MatchResult = Match_Success;
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001253 else {
1254 ARMOperand *CCOut = ((ARMOperand*)Operands[1]);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001255 Operands.erase(Operands.begin() + 1);
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001256 delete CCOut;
1257 }
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001258 }
1259 // If we get a Match_MnemonicFail it might be some arithmetic instruction
1260 // that updates the condition codes if it ends in 's'. So see if the
1261 // mnemonic ends in 's' and if so try removing the 's' and adding a CCOut
1262 // operand with a value of CPSR.
1263 else if(MatchResult == Match_MnemonicFail) {
1264 // Get the instruction mnemonic, which is the first token.
1265 StringRef Mnemonic = ((ARMOperand*)Operands[0])->getToken();
1266 if (Mnemonic.substr(Mnemonic.size()-1) == "s") {
1267 // removed the 's' from the mnemonic for matching.
1268 StringRef MnemonicNoS = Mnemonic.slice(0, Mnemonic.size() - 1);
1269 SMLoc NameLoc = ((ARMOperand*)Operands[0])->getStartLoc();
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(MnemonicNoS, NameLoc));
1275 Operands.insert(Operands.begin() + 1,
1276 ARMOperand::CreateCCOut(ARM::CPSR, NameLoc));
1277 MatchResult2 = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1278 if (MatchResult2 == Match_Success)
1279 MatchResult = Match_Success;
1280 else {
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001281 ARMOperand *OldMnemonic = ((ARMOperand*)Operands[0]);
1282 Operands.erase(Operands.begin());
1283 delete OldMnemonic;
1284 Operands.insert(Operands.begin(),
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001285 ARMOperand::CreateToken(Mnemonic, NameLoc));
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001286 ARMOperand *CCOut = ((ARMOperand*)Operands[1]);
1287 Operands.erase(Operands.begin() + 1);
1288 delete CCOut;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001289 }
1290 }
1291 }
1292 }
1293 switch (MatchResult) {
Chris Lattnere73d4f82010-10-28 21:41:58 +00001294 case Match_Success:
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001295 Out.EmitInstruction(Inst);
1296 return false;
Chris Lattnere73d4f82010-10-28 21:41:58 +00001297 case Match_MissingFeature:
1298 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
1299 return true;
1300 case Match_InvalidOperand: {
1301 SMLoc ErrorLoc = IDLoc;
1302 if (ErrorInfo != ~0U) {
1303 if (ErrorInfo >= Operands.size())
1304 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00001305
Chris Lattnere73d4f82010-10-28 21:41:58 +00001306 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
1307 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
1308 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001309
Chris Lattnere73d4f82010-10-28 21:41:58 +00001310 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001311 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00001312 case Match_MnemonicFail:
1313 return Error(IDLoc, "unrecognized instruction mnemonic");
1314 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001315
Eric Christopherc223e2b2010-10-29 09:26:59 +00001316 llvm_unreachable("Implement any new match types added!");
Bill Wendling146018f2010-11-06 21:42:12 +00001317 return true;
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001318}
1319
Kevin Enderby515d5092009-10-15 20:48:48 +00001320/// ParseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001321bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
1322 StringRef IDVal = DirectiveID.getIdentifier();
1323 if (IDVal == ".word")
1324 return ParseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00001325 else if (IDVal == ".thumb")
1326 return ParseDirectiveThumb(DirectiveID.getLoc());
1327 else if (IDVal == ".thumb_func")
1328 return ParseDirectiveThumbFunc(DirectiveID.getLoc());
1329 else if (IDVal == ".code")
1330 return ParseDirectiveCode(DirectiveID.getLoc());
1331 else if (IDVal == ".syntax")
1332 return ParseDirectiveSyntax(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001333 return true;
1334}
1335
1336/// ParseDirectiveWord
1337/// ::= .word [ expression (, expression)* ]
1338bool ARMAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
1339 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1340 for (;;) {
1341 const MCExpr *Value;
1342 if (getParser().ParseExpression(Value))
1343 return true;
1344
Chris Lattneraaec2052010-01-19 19:46:13 +00001345 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001346
1347 if (getLexer().is(AsmToken::EndOfStatement))
1348 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00001349
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001350 // FIXME: Improve diagnostic.
1351 if (getLexer().isNot(AsmToken::Comma))
1352 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001353 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001354 }
1355 }
1356
Sean Callananb9a25b72010-01-19 20:27:46 +00001357 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001358 return false;
1359}
1360
Kevin Enderby515d5092009-10-15 20:48:48 +00001361/// ParseDirectiveThumb
1362/// ::= .thumb
1363bool ARMAsmParser::ParseDirectiveThumb(SMLoc L) {
1364 if (getLexer().isNot(AsmToken::EndOfStatement))
1365 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001366 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001367
1368 // TODO: set thumb mode
1369 // TODO: tell the MC streamer the mode
1370 // getParser().getStreamer().Emit???();
1371 return false;
1372}
1373
1374/// ParseDirectiveThumbFunc
1375/// ::= .thumbfunc symbol_name
1376bool ARMAsmParser::ParseDirectiveThumbFunc(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001377 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001378 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
Jim Grosbach83c40182010-11-05 22:11:33 +00001379 return Error(L, "unexpected token in .thumb_func directive");
Jim Grosbach642fc9c2010-11-05 22:33:53 +00001380 StringRef Name = Tok.getString();
Sean Callananb9a25b72010-01-19 20:27:46 +00001381 Parser.Lex(); // Consume the identifier token.
Kevin Enderby515d5092009-10-15 20:48:48 +00001382 if (getLexer().isNot(AsmToken::EndOfStatement))
1383 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001384 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001385
Jim Grosbach642fc9c2010-11-05 22:33:53 +00001386 // Mark symbol as a thumb symbol.
1387 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
1388 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00001389 return false;
1390}
1391
1392/// ParseDirectiveSyntax
1393/// ::= .syntax unified | divided
1394bool ARMAsmParser::ParseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001395 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001396 if (Tok.isNot(AsmToken::Identifier))
1397 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00001398 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00001399 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00001400 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00001401 else if (Mode == "divided" || Mode == "DIVIDED")
Sean Callananb9a25b72010-01-19 20:27:46 +00001402 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001403 else
1404 return Error(L, "unrecognized syntax mode in .syntax directive");
1405
1406 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00001407 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001408 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001409
1410 // TODO tell the MC streamer the mode
1411 // getParser().getStreamer().Emit???();
1412 return false;
1413}
1414
1415/// ParseDirectiveCode
1416/// ::= .code 16 | 32
1417bool ARMAsmParser::ParseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001418 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001419 if (Tok.isNot(AsmToken::Integer))
1420 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00001421 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00001422 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00001423 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00001424 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00001425 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001426 else
1427 return Error(L, "invalid operand to .code directive");
1428
1429 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00001430 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001431 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001432
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00001433 // FIXME: We need to be able switch subtargets at this point so that
1434 // MatchInstructionImpl() will work when it gets the AvailableFeatures which
1435 // includes Feature_IsThumb or not to match the right instructions. This is
1436 // blocked on the FIXME in llvm-mc.cpp when creating the TargetMachine.
1437 if (Val == 16){
1438 assert(TM.getSubtarget<ARMSubtarget>().isThumb() &&
1439 "switching between arm/thumb not yet suppported via .code 16)");
Jim Grosbach2a301702010-11-05 22:40:53 +00001440 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00001441 }
1442 else{
1443 assert(!TM.getSubtarget<ARMSubtarget>().isThumb() &&
1444 "switching between thumb/arm not yet suppported via .code 32)");
Jim Grosbach2a301702010-11-05 22:40:53 +00001445 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00001446 }
Jim Grosbach2a301702010-11-05 22:40:53 +00001447
Kevin Enderby515d5092009-10-15 20:48:48 +00001448 return false;
1449}
1450
Sean Callanan90b70972010-04-07 20:29:34 +00001451extern "C" void LLVMInitializeARMAsmLexer();
1452
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001453/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001454extern "C" void LLVMInitializeARMAsmParser() {
1455 RegisterAsmParser<ARMAsmParser> X(TheARMTarget);
1456 RegisterAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00001457 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001458}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001459
Chris Lattner0692ee62010-09-06 19:11:01 +00001460#define GET_REGISTER_MATCHER
1461#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001462#include "ARMGenAsmMatcher.inc"