blob: c2e8442026b6bc15ea7d44431cd8d67645d46a70 [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 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000238 if (!CE) return false;
239
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000240 // The offset must be a multiple of 4 in the range 0-1020.
241 int64_t Value = CE->getValue();
242 return ((Value & 0x3) == 0 && Value <= 1020 && Value >= -1020);
243 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000244 bool isMemModeRegThumb() const {
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000245 if (!isMemory() || !Mem.OffsetIsReg || Mem.Writeback)
Bill Wendlingf4caf692010-12-14 03:36:38 +0000246 return false;
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000247 return true;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000248 }
249 bool isMemModeImmThumb() const {
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000250 if (!isMemory() || Mem.OffsetIsReg || Mem.Writeback)
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000251 return false;
252
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000253 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
254 if (!CE) return false;
255
256 // The offset must be a multiple of 4 in the range 0-124.
257 uint64_t Value = CE->getValue();
258 return ((Value & 0x3) == 0 && Value <= 124);
259 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000260
261 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +0000262 // Add as immediates when possible. Null MCExpr = 0.
263 if (Expr == 0)
264 Inst.addOperand(MCOperand::CreateImm(0));
265 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000266 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
267 else
268 Inst.addOperand(MCOperand::CreateExpr(Expr));
269 }
270
Daniel Dunbar8462b302010-08-11 06:36:53 +0000271 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000272 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000273 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +0000274 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
275 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +0000276 }
277
Jim Grosbachd67641b2010-12-06 18:21:12 +0000278 void addCCOutOperands(MCInst &Inst, unsigned N) const {
279 assert(N == 1 && "Invalid number of operands!");
280 Inst.addOperand(MCOperand::CreateReg(getReg()));
281 }
282
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000283 void addRegOperands(MCInst &Inst, unsigned N) const {
284 assert(N == 1 && "Invalid number of operands!");
285 Inst.addOperand(MCOperand::CreateReg(getReg()));
286 }
287
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000288 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +0000289 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +0000290 const SmallVectorImpl<unsigned> &RegList = getRegList();
291 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000292 I = RegList.begin(), E = RegList.end(); I != E; ++I)
293 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000294 }
295
Bill Wendling0f630752010-11-17 04:32:08 +0000296 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
297 addRegListOperands(Inst, N);
298 }
299
300 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
301 addRegListOperands(Inst, N);
302 }
303
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000304 void addImmOperands(MCInst &Inst, unsigned N) const {
305 assert(N == 1 && "Invalid number of operands!");
306 addExpr(Inst, getImm());
307 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000308
Chris Lattner14b93852010-10-29 00:27:31 +0000309 void addMemMode5Operands(MCInst &Inst, unsigned N) const {
310 assert(N == 2 && isMemMode5() && "Invalid number of operands!");
Jim Grosbach16c74252010-10-29 14:46:02 +0000311
Chris Lattner14b93852010-10-29 00:27:31 +0000312 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
Bill Wendlinga60f1572010-11-06 10:48:18 +0000313 assert(!Mem.OffsetIsReg && "Invalid mode 5 operand");
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000314
Jim Grosbach80eb2332010-10-29 17:41:25 +0000315 // FIXME: #-0 is encoded differently than #0. Does the parser preserve
316 // the difference?
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000317 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
318 assert(CE && "Non-constant mode 5 offset operand!");
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000319
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000320 // The MCInst offset operand doesn't include the low two bits (like
321 // the instruction encoding).
322 int64_t Offset = CE->getValue() / 4;
323 if (Offset >= 0)
324 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add,
325 Offset)));
326 else
327 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub,
328 -Offset)));
Chris Lattner14b93852010-10-29 00:27:31 +0000329 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000330
Bill Wendlingf4caf692010-12-14 03:36:38 +0000331 void addMemModeRegThumbOperands(MCInst &Inst, unsigned N) const {
332 assert(N == 2 && isMemModeRegThumb() && "Invalid number of operands!");
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000333 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
Bill Wendlingf4caf692010-12-14 03:36:38 +0000334 Inst.addOperand(MCOperand::CreateReg(Mem.OffsetRegNum));
335 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000336
Bill Wendlingf4caf692010-12-14 03:36:38 +0000337 void addMemModeImmThumbOperands(MCInst &Inst, unsigned N) const {
338 assert(N == 2 && isMemModeImmThumb() && "Invalid number of operands!");
339 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
340 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
341 assert(CE && "Non-constant mode offset operand!");
342 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000343 }
344
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000345 virtual void dump(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +0000346
Chris Lattner3a697562010-10-28 17:20:03 +0000347 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
348 ARMOperand *Op = new ARMOperand(CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000349 Op->CC.Val = CC;
350 Op->StartLoc = S;
351 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000352 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000353 }
354
Jim Grosbachd67641b2010-12-06 18:21:12 +0000355 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
356 ARMOperand *Op = new ARMOperand(CCOut);
357 Op->Reg.RegNum = RegNum;
358 Op->StartLoc = S;
359 Op->EndLoc = S;
360 return Op;
361 }
362
Chris Lattner3a697562010-10-28 17:20:03 +0000363 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
364 ARMOperand *Op = new ARMOperand(Token);
Sean Callanan76264762010-04-02 22:27:05 +0000365 Op->Tok.Data = Str.data();
366 Op->Tok.Length = Str.size();
367 Op->StartLoc = S;
368 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000369 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000370 }
371
Bill Wendling50d0f582010-11-18 23:43:05 +0000372 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Chris Lattner3a697562010-10-28 17:20:03 +0000373 ARMOperand *Op = new ARMOperand(Register);
Sean Callanan76264762010-04-02 22:27:05 +0000374 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +0000375 Op->StartLoc = S;
376 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000377 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000378 }
379
Bill Wendling7729e062010-11-09 22:44:22 +0000380 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +0000381 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000382 SMLoc StartLoc, SMLoc EndLoc) {
Bill Wendling0f630752010-11-17 04:32:08 +0000383 KindTy Kind = RegisterList;
384
385 if (ARM::DPRRegClass.contains(Regs.front().first))
386 Kind = DPRRegisterList;
387 else if (ARM::SPRRegClass.contains(Regs.front().first))
388 Kind = SPRRegisterList;
389
390 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +0000391 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000392 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +0000393 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +0000394 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000395 Op->StartLoc = StartLoc;
396 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000397 return Op;
398 }
399
Chris Lattner3a697562010-10-28 17:20:03 +0000400 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
401 ARMOperand *Op = new ARMOperand(Immediate);
Sean Callanan76264762010-04-02 22:27:05 +0000402 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +0000403 Op->StartLoc = S;
404 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000405 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +0000406 }
407
Chris Lattner3a697562010-10-28 17:20:03 +0000408 static ARMOperand *CreateMem(unsigned BaseRegNum, bool OffsetIsReg,
Daniel Dunbar023835d2011-01-18 05:34:05 +0000409 const MCExpr *Offset, int OffsetRegNum,
Chris Lattner3a697562010-10-28 17:20:03 +0000410 bool OffsetRegShifted, enum ShiftType ShiftType,
411 const MCExpr *ShiftAmount, bool Preindexed,
412 bool Postindexed, bool Negative, bool Writeback,
413 SMLoc S, SMLoc E) {
Daniel Dunbar023835d2011-01-18 05:34:05 +0000414 assert((OffsetRegNum == -1 || OffsetIsReg) &&
415 "OffsetRegNum must imply OffsetIsReg!");
416 assert((!OffsetRegShifted || OffsetIsReg) &&
417 "OffsetRegShifted must imply OffsetIsReg!");
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000418 assert((Offset || OffsetIsReg) &&
419 "Offset must exists unless register offset is used!");
Daniel Dunbar023835d2011-01-18 05:34:05 +0000420 assert((!ShiftAmount || (OffsetIsReg && OffsetRegShifted)) &&
421 "Cannot have shift amount without shifted register offset!");
422 assert((!Offset || !OffsetIsReg) &&
423 "Cannot have expression offset and register offset!");
424
Chris Lattner3a697562010-10-28 17:20:03 +0000425 ARMOperand *Op = new ARMOperand(Memory);
Sean Callanan76264762010-04-02 22:27:05 +0000426 Op->Mem.BaseRegNum = BaseRegNum;
427 Op->Mem.OffsetIsReg = OffsetIsReg;
428 Op->Mem.Offset = Offset;
429 Op->Mem.OffsetRegNum = OffsetRegNum;
430 Op->Mem.OffsetRegShifted = OffsetRegShifted;
431 Op->Mem.ShiftType = ShiftType;
432 Op->Mem.ShiftAmount = ShiftAmount;
433 Op->Mem.Preindexed = Preindexed;
434 Op->Mem.Postindexed = Postindexed;
435 Op->Mem.Negative = Negative;
436 Op->Mem.Writeback = Writeback;
Jim Grosbach16c74252010-10-29 14:46:02 +0000437
Sean Callanan76264762010-04-02 22:27:05 +0000438 Op->StartLoc = S;
439 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000440 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000441 }
442};
443
444} // end anonymous namespace.
445
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000446void ARMOperand::dump(raw_ostream &OS) const {
447 switch (Kind) {
448 case CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000449 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000450 break;
Jim Grosbachd67641b2010-12-06 18:21:12 +0000451 case CCOut:
452 OS << "<ccout " << getReg() << ">";
453 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000454 case Immediate:
455 getImm()->print(OS);
456 break;
457 case Memory:
Bill Wendling50d0f582010-11-18 23:43:05 +0000458 OS << "<memory>";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000459 break;
460 case Register:
Bill Wendling50d0f582010-11-18 23:43:05 +0000461 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000462 break;
Bill Wendling0f630752010-11-17 04:32:08 +0000463 case RegisterList:
464 case DPRRegisterList:
465 case SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +0000466 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000467
Bill Wendling5fa22a12010-11-09 23:28:44 +0000468 const SmallVectorImpl<unsigned> &RegList = getRegList();
469 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000470 I = RegList.begin(), E = RegList.end(); I != E; ) {
471 OS << *I;
472 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000473 }
474
475 OS << ">";
476 break;
477 }
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000478 case Token:
479 OS << "'" << getToken() << "'";
480 break;
481 }
482}
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000483
484/// @name Auto-generated Match Functions
485/// {
486
487static unsigned MatchRegisterName(StringRef Name);
488
489/// }
490
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000491/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +0000492/// and if it is a register name the token is eaten and the register number is
493/// returned. Otherwise return -1.
494///
495int ARMAsmParser::TryParseRegister() {
496 const AsmToken &Tok = Parser.getTok();
497 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
Jim Grosbachd4462a52010-11-01 16:44:21 +0000498
Chris Lattnere5658fa2010-10-30 04:09:10 +0000499 // FIXME: Validate register for the current architecture; we have to do
500 // validation later, so maybe there is no need for this here.
Owen Anderson0c9f2502011-01-13 22:50:36 +0000501 std::string upperCase = Tok.getString().str();
502 std::string lowerCase = LowercaseString(upperCase);
503 unsigned RegNum = MatchRegisterName(lowerCase);
504 if (!RegNum) {
505 RegNum = StringSwitch<unsigned>(lowerCase)
506 .Case("r13", ARM::SP)
507 .Case("r14", ARM::LR)
508 .Case("r15", ARM::PC)
509 .Case("ip", ARM::R12)
510 .Default(0);
511 }
512 if (!RegNum) return -1;
513
Chris Lattnere5658fa2010-10-30 04:09:10 +0000514 Parser.Lex(); // Eat identifier token.
515 return RegNum;
516}
Jim Grosbachd4462a52010-11-01 16:44:21 +0000517
518
Bill Wendling50d0f582010-11-18 23:43:05 +0000519/// Try to parse a register name. The token must be an Identifier when called.
520/// If it's a register, an AsmOperand is created. Another AsmOperand is created
521/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +0000522///
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000523/// TODO this is likely to change to allow different register types and or to
524/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +0000525bool ARMAsmParser::
526TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +0000527 SMLoc S = Parser.getTok().getLoc();
528 int RegNo = TryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +0000529 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +0000530 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +0000531
Bill Wendling50d0f582010-11-18 23:43:05 +0000532 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000533
Chris Lattnere5658fa2010-10-30 04:09:10 +0000534 const AsmToken &ExclaimTok = Parser.getTok();
535 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +0000536 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
537 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +0000538 Parser.Lex(); // Eat exclaim token
Kevin Enderby99e6d4e2009-10-07 18:01:35 +0000539 }
540
Bill Wendling50d0f582010-11-18 23:43:05 +0000541 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000542}
543
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000544static int MatchMCRName(StringRef Name) {
545 // Use the same layout as the tablegen'erated register name matcher. Ugly,
546 // but efficient.
547 switch (Name.size()) {
548 default: break;
549 case 2:
550 if (Name[0] != 'p' && Name[0] != 'c')
551 return -1;
552 switch (Name[1]) {
553 default: return -1;
554 case '0': return 0;
555 case '1': return 1;
556 case '2': return 2;
557 case '3': return 3;
558 case '4': return 4;
559 case '5': return 5;
560 case '6': return 6;
561 case '7': return 7;
562 case '8': return 8;
563 case '9': return 9;
564 }
565 break;
566 case 3:
567 if ((Name[0] != 'p' && Name[0] != 'c') || Name[1] != '1')
568 return -1;
569 switch (Name[2]) {
570 default: return -1;
571 case '0': return 10;
572 case '1': return 11;
573 case '2': return 12;
574 case '3': return 13;
575 case '4': return 14;
576 case '5': return 15;
577 }
578 break;
579 }
580
581 llvm_unreachable("Unhandled coprocessor operand string!");
582 return -1;
583}
584
585/// TryParseMCRName - Try to parse an MCR/MRC symbolic operand
586/// name. The token must be an Identifier when called, and if it is a MCR
587/// operand name, the token is eaten and the operand is added to the
588/// operand list.
589bool ARMAsmParser::
590TryParseMCRName(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
591 SMLoc S = Parser.getTok().getLoc();
592 const AsmToken &Tok = Parser.getTok();
593 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
594
595 int Num = MatchMCRName(Tok.getString());
596 if (Num == -1)
597 return true;
598
599 Parser.Lex(); // Eat identifier token.
600 Operands.push_back(ARMOperand::CreateImm(
601 MCConstantExpr::Create(Num, getContext()), S, Parser.getTok().getLoc()));
602 return false;
603}
604
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000605/// Parse a register list, return it if successful else return null. The first
606/// token must be a '{' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +0000607bool ARMAsmParser::
608ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +0000609 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +0000610 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +0000611 SMLoc S = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000612
Bill Wendling7729e062010-11-09 22:44:22 +0000613 // Read the rest of the registers in the list.
614 unsigned PrevRegNum = 0;
Bill Wendling5fa22a12010-11-09 23:28:44 +0000615 SmallVector<std::pair<unsigned, SMLoc>, 32> Registers;
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000616
Bill Wendling7729e062010-11-09 22:44:22 +0000617 do {
Bill Wendlinge7176102010-11-06 22:36:58 +0000618 bool IsRange = Parser.getTok().is(AsmToken::Minus);
Bill Wendling7729e062010-11-09 22:44:22 +0000619 Parser.Lex(); // Eat non-identifier token.
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000620
Sean Callanan18b83232010-01-19 21:44:56 +0000621 const AsmToken &RegTok = Parser.getTok();
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000622 SMLoc RegLoc = RegTok.getLoc();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000623 if (RegTok.isNot(AsmToken::Identifier)) {
624 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000625 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000626 }
Bill Wendlinge7176102010-11-06 22:36:58 +0000627
Bill Wendling1d6a2652010-11-06 10:40:24 +0000628 int RegNum = TryParseRegister();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000629 if (RegNum == -1) {
630 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000631 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000632 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000633
Bill Wendlinge7176102010-11-06 22:36:58 +0000634 if (IsRange) {
635 int Reg = PrevRegNum;
636 do {
637 ++Reg;
638 Registers.push_back(std::make_pair(Reg, RegLoc));
639 } while (Reg != RegNum);
640 } else {
641 Registers.push_back(std::make_pair(RegNum, RegLoc));
642 }
643
644 PrevRegNum = RegNum;
Bill Wendling7729e062010-11-09 22:44:22 +0000645 } while (Parser.getTok().is(AsmToken::Comma) ||
646 Parser.getTok().is(AsmToken::Minus));
Bill Wendlinge7176102010-11-06 22:36:58 +0000647
648 // Process the right curly brace of the list.
Sean Callanan18b83232010-01-19 21:44:56 +0000649 const AsmToken &RCurlyTok = Parser.getTok();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000650 if (RCurlyTok.isNot(AsmToken::RCurly)) {
651 Error(RCurlyTok.getLoc(), "'}' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000652 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000653 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000654
Bill Wendlinge7176102010-11-06 22:36:58 +0000655 SMLoc E = RCurlyTok.getLoc();
656 Parser.Lex(); // Eat right curly brace token.
Jim Grosbach03f44a02010-11-29 23:18:01 +0000657
Bill Wendlinge7176102010-11-06 22:36:58 +0000658 // Verify the register list.
Bill Wendling5fa22a12010-11-09 23:28:44 +0000659 SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendlinge7176102010-11-06 22:36:58 +0000660 RI = Registers.begin(), RE = Registers.end();
661
Bill Wendling7caebff2011-01-12 21:20:59 +0000662 unsigned HighRegNum = getARMRegisterNumbering(RI->first);
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000663 bool EmittedWarning = false;
664
Bill Wendling7caebff2011-01-12 21:20:59 +0000665 DenseMap<unsigned, bool> RegMap;
666 RegMap[HighRegNum] = true;
667
Bill Wendlinge7176102010-11-06 22:36:58 +0000668 for (++RI; RI != RE; ++RI) {
Bill Wendling7729e062010-11-09 22:44:22 +0000669 const std::pair<unsigned, SMLoc> &RegInfo = *RI;
Bill Wendling7caebff2011-01-12 21:20:59 +0000670 unsigned Reg = getARMRegisterNumbering(RegInfo.first);
Bill Wendlinge7176102010-11-06 22:36:58 +0000671
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000672 if (RegMap[Reg]) {
Bill Wendlinge7176102010-11-06 22:36:58 +0000673 Error(RegInfo.second, "register duplicated in register list");
Bill Wendling50d0f582010-11-18 23:43:05 +0000674 return true;
Bill Wendlinge7176102010-11-06 22:36:58 +0000675 }
676
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000677 if (!EmittedWarning && Reg < HighRegNum)
Bill Wendlinge7176102010-11-06 22:36:58 +0000678 Warning(RegInfo.second,
679 "register not in ascending order in register list");
680
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000681 RegMap[Reg] = true;
682 HighRegNum = std::max(Reg, HighRegNum);
Bill Wendlinge7176102010-11-06 22:36:58 +0000683 }
684
Bill Wendling50d0f582010-11-18 23:43:05 +0000685 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
686 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000687}
688
Bill Wendlinge7176102010-11-06 22:36:58 +0000689/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000690/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +0000691///
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000692/// TODO Only preindexing and postindexing addressing are started, unindexed
693/// with option, etc are still to do.
Bill Wendling50d0f582010-11-18 23:43:05 +0000694bool ARMAsmParser::
695ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +0000696 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +0000697 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +0000698 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +0000699 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000700 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000701
Sean Callanan18b83232010-01-19 21:44:56 +0000702 const AsmToken &BaseRegTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +0000703 if (BaseRegTok.isNot(AsmToken::Identifier)) {
704 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000705 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000706 }
Chris Lattnere5658fa2010-10-30 04:09:10 +0000707 int BaseRegNum = TryParseRegister();
708 if (BaseRegNum == -1) {
Chris Lattner550276e2010-10-28 20:52:15 +0000709 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000710 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000711 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000712
Daniel Dunbar05710932011-01-18 05:34:17 +0000713 // The next token must either be a comma or a closing bracket.
714 const AsmToken &Tok = Parser.getTok();
715 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
716 return true;
717
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000718 bool Preindexed = false;
719 bool Postindexed = false;
720 bool OffsetIsReg = false;
721 bool Negative = false;
722 bool Writeback = false;
Daniel Dunbar05d8b712011-01-18 05:34:24 +0000723 ARMOperand *WBOp = 0;
724 int OffsetRegNum = -1;
725 bool OffsetRegShifted = false;
726 enum ShiftType ShiftType = Lsl;
727 const MCExpr *ShiftAmount = 0;
728 const MCExpr *Offset = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000729
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000730 // First look for preindexed address forms, that is after the "[Rn" we now
731 // have to see if the next token is a comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000732 if (Tok.is(AsmToken::Comma)) {
733 Preindexed = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000734 Parser.Lex(); // Eat comma token.
Daniel Dunbar05d8b712011-01-18 05:34:24 +0000735
Chris Lattner550276e2010-10-28 20:52:15 +0000736 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType, ShiftAmount,
737 Offset, OffsetIsReg, OffsetRegNum, E))
Bill Wendling50d0f582010-11-18 23:43:05 +0000738 return true;
Sean Callanan18b83232010-01-19 21:44:56 +0000739 const AsmToken &RBracTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +0000740 if (RBracTok.isNot(AsmToken::RBrac)) {
741 Error(RBracTok.getLoc(), "']' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000742 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000743 }
Sean Callanan76264762010-04-02 22:27:05 +0000744 E = RBracTok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000745 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000746
Sean Callanan18b83232010-01-19 21:44:56 +0000747 const AsmToken &ExclaimTok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000748 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +0000749 WBOp = ARMOperand::CreateToken(ExclaimTok.getString(),
750 ExclaimTok.getLoc());
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000751 Writeback = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000752 Parser.Lex(); // Eat exclaim token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000753 }
Daniel Dunbar05710932011-01-18 05:34:17 +0000754 } else {
755 // The "[Rn" we have so far was not followed by a comma.
756
Jim Grosbach80eb2332010-10-29 17:41:25 +0000757 // If there's anything other than the right brace, this is a post indexing
758 // addressing form.
Sean Callanan76264762010-04-02 22:27:05 +0000759 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000760 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000761
Sean Callanan18b83232010-01-19 21:44:56 +0000762 const AsmToken &NextTok = Parser.getTok();
Jim Grosbach03f44a02010-11-29 23:18:01 +0000763
Kevin Enderbye2a98dd2009-10-15 21:42:45 +0000764 if (NextTok.isNot(AsmToken::EndOfStatement)) {
Jim Grosbach80eb2332010-10-29 17:41:25 +0000765 Postindexed = true;
766 Writeback = true;
Bill Wendling50d0f582010-11-18 23:43:05 +0000767
Chris Lattner550276e2010-10-28 20:52:15 +0000768 if (NextTok.isNot(AsmToken::Comma)) {
769 Error(NextTok.getLoc(), "',' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000770 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000771 }
Bill Wendling50d0f582010-11-18 23:43:05 +0000772
Sean Callananb9a25b72010-01-19 20:27:46 +0000773 Parser.Lex(); // Eat comma token.
Bill Wendling50d0f582010-11-18 23:43:05 +0000774
Chris Lattner550276e2010-10-28 20:52:15 +0000775 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType,
Jim Grosbach16c74252010-10-29 14:46:02 +0000776 ShiftAmount, Offset, OffsetIsReg, OffsetRegNum,
Chris Lattner550276e2010-10-28 20:52:15 +0000777 E))
Bill Wendling50d0f582010-11-18 23:43:05 +0000778 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000779 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000780 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +0000781
782 // Force Offset to exist if used.
783 if (!OffsetIsReg) {
784 if (!Offset)
785 Offset = MCConstantExpr::Create(0, getContext());
786 }
787
788 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, OffsetIsReg, Offset,
789 OffsetRegNum, OffsetRegShifted,
790 ShiftType, ShiftAmount, Preindexed,
791 Postindexed, Negative, Writeback,
792 S, E));
793 if (WBOp)
794 Operands.push_back(WBOp);
795
796 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000797}
798
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000799/// Parse the offset of a memory operand after we have seen "[Rn," or "[Rn],"
800/// we will parse the following (were +/- means that a plus or minus is
801/// optional):
802/// +/-Rm
803/// +/-Rm, shift
804/// #offset
805/// we return false on success or an error otherwise.
806bool ARMAsmParser::ParseMemoryOffsetReg(bool &Negative,
Sean Callanan76264762010-04-02 22:27:05 +0000807 bool &OffsetRegShifted,
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000808 enum ShiftType &ShiftType,
809 const MCExpr *&ShiftAmount,
810 const MCExpr *&Offset,
811 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +0000812 int &OffsetRegNum,
813 SMLoc &E) {
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000814 Negative = false;
815 OffsetRegShifted = false;
816 OffsetIsReg = false;
817 OffsetRegNum = -1;
Sean Callanan18b83232010-01-19 21:44:56 +0000818 const AsmToken &NextTok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +0000819 E = NextTok.getLoc();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000820 if (NextTok.is(AsmToken::Plus))
Sean Callananb9a25b72010-01-19 20:27:46 +0000821 Parser.Lex(); // Eat plus token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000822 else if (NextTok.is(AsmToken::Minus)) {
823 Negative = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000824 Parser.Lex(); // Eat minus token
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000825 }
826 // See if there is a register following the "[Rn," or "[Rn]," we have so far.
Sean Callanan18b83232010-01-19 21:44:56 +0000827 const AsmToken &OffsetRegTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000828 if (OffsetRegTok.is(AsmToken::Identifier)) {
Chris Lattnere5658fa2010-10-30 04:09:10 +0000829 SMLoc CurLoc = OffsetRegTok.getLoc();
830 OffsetRegNum = TryParseRegister();
831 if (OffsetRegNum != -1) {
Chris Lattner550276e2010-10-28 20:52:15 +0000832 OffsetIsReg = true;
Chris Lattnere5658fa2010-10-30 04:09:10 +0000833 E = CurLoc;
Sean Callanan76264762010-04-02 22:27:05 +0000834 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000835 }
Jim Grosbachd4462a52010-11-01 16:44:21 +0000836
Bill Wendling12f40e92010-11-06 10:51:53 +0000837 // If we parsed a register as the offset then there can be a shift after that.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000838 if (OffsetRegNum != -1) {
839 // Look for a comma then a shift
Sean Callanan18b83232010-01-19 21:44:56 +0000840 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000841 if (Tok.is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +0000842 Parser.Lex(); // Eat comma token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000843
Sean Callanan18b83232010-01-19 21:44:56 +0000844 const AsmToken &Tok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +0000845 if (ParseShift(ShiftType, ShiftAmount, E))
Duncan Sands34727662010-07-12 08:16:59 +0000846 return Error(Tok.getLoc(), "shift expected");
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000847 OffsetRegShifted = true;
848 }
849 }
850 else { // the "[Rn," or "[Rn,]" we have so far was not followed by "Rm"
851 // Look for #offset following the "[Rn," or "[Rn],"
Sean Callanan18b83232010-01-19 21:44:56 +0000852 const AsmToken &HashTok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000853 if (HashTok.isNot(AsmToken::Hash))
854 return Error(HashTok.getLoc(), "'#' expected");
Jim Grosbach16c74252010-10-29 14:46:02 +0000855
Sean Callananb9a25b72010-01-19 20:27:46 +0000856 Parser.Lex(); // Eat hash token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000857
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000858 if (getParser().ParseExpression(Offset))
859 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000860 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000861 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000862 return false;
863}
864
865/// ParseShift as one of these two:
866/// ( lsl | lsr | asr | ror ) , # shift_amount
867/// rrx
868/// and returns true if it parses a shift otherwise it returns false.
Jim Grosbach16c74252010-10-29 14:46:02 +0000869bool ARMAsmParser::ParseShift(ShiftType &St, const MCExpr *&ShiftAmount,
Sean Callanan76264762010-04-02 22:27:05 +0000870 SMLoc &E) {
Sean Callanan18b83232010-01-19 21:44:56 +0000871 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000872 if (Tok.isNot(AsmToken::Identifier))
873 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +0000874 StringRef ShiftName = Tok.getString();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000875 if (ShiftName == "lsl" || ShiftName == "LSL")
876 St = Lsl;
877 else if (ShiftName == "lsr" || ShiftName == "LSR")
878 St = Lsr;
879 else if (ShiftName == "asr" || ShiftName == "ASR")
880 St = Asr;
881 else if (ShiftName == "ror" || ShiftName == "ROR")
882 St = Ror;
883 else if (ShiftName == "rrx" || ShiftName == "RRX")
884 St = Rrx;
885 else
886 return true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000887 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000888
889 // Rrx stands alone.
890 if (St == Rrx)
891 return false;
892
893 // Otherwise, there must be a '#' and a shift amount.
Sean Callanan18b83232010-01-19 21:44:56 +0000894 const AsmToken &HashTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000895 if (HashTok.isNot(AsmToken::Hash))
896 return Error(HashTok.getLoc(), "'#' expected");
Sean Callananb9a25b72010-01-19 20:27:46 +0000897 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000898
899 if (getParser().ParseExpression(ShiftAmount))
900 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000901
902 return false;
903}
904
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000905/// Parse a arm instruction operand. For now this parses the operand regardless
906/// of the mnemonic.
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000907bool ARMAsmParser::ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
908 bool isMCR){
Sean Callanan76264762010-04-02 22:27:05 +0000909 SMLoc S, E;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000910 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +0000911 default:
912 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +0000913 return true;
Kevin Enderby67b212e2011-01-13 20:32:36 +0000914 case AsmToken::Identifier:
Bill Wendling50d0f582010-11-18 23:43:05 +0000915 if (!TryParseRegisterWithWriteBack(Operands))
916 return false;
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000917 if (isMCR && !TryParseMCRName(Operands))
918 return false;
919
920 // Fall though for the Identifier case that is not a register or a
921 // special name.
Kevin Enderby67b212e2011-01-13 20:32:36 +0000922 case AsmToken::Integer: // things like 1f and 2b as a branch targets
923 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +0000924 // This was not a register so parse other operands that start with an
925 // identifier (like labels) as expressions and create them as immediates.
926 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +0000927 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +0000928 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +0000929 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000930 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +0000931 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
932 return false;
933 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000934 case AsmToken::LBrac:
Bill Wendling50d0f582010-11-18 23:43:05 +0000935 return ParseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000936 case AsmToken::LCurly:
Bill Wendling50d0f582010-11-18 23:43:05 +0000937 return ParseRegisterList(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000938 case AsmToken::Hash:
Kevin Enderby079469f2009-10-13 23:33:38 +0000939 // #42 -> immediate.
940 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
Sean Callanan76264762010-04-02 22:27:05 +0000941 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000942 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +0000943 const MCExpr *ImmVal;
944 if (getParser().ParseExpression(ImmVal))
Bill Wendling50d0f582010-11-18 23:43:05 +0000945 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000946 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +0000947 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
948 return false;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000949 case AsmToken::Colon: {
950 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +0000951 // FIXME: Check it's an expression prefix,
952 // e.g. (FOO - :lower16:BAR) isn't legal.
953 ARMMCExpr::VariantKind RefKind;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000954 if (ParsePrefix(RefKind))
955 return true;
956
Evan Cheng75972122011-01-13 07:58:56 +0000957 const MCExpr *SubExprVal;
958 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +0000959 return true;
960
Evan Cheng75972122011-01-13 07:58:56 +0000961 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
962 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +0000963 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +0000964 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +0000965 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000966 }
Jason W Kim9081b4b2011-01-11 23:53:41 +0000967 }
968}
969
Evan Cheng75972122011-01-13 07:58:56 +0000970// ParsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
971// :lower16: and :upper16:.
972bool ARMAsmParser::ParsePrefix(ARMMCExpr::VariantKind &RefKind) {
973 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000974
975 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +0000976 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +0000977 Parser.Lex(); // Eat ':'
978
979 if (getLexer().isNot(AsmToken::Identifier)) {
980 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
981 return true;
982 }
983
984 StringRef IDVal = Parser.getTok().getIdentifier();
985 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +0000986 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000987 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +0000988 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +0000989 } else {
990 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
991 return true;
992 }
993 Parser.Lex();
994
995 if (getLexer().isNot(AsmToken::Colon)) {
996 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
997 return true;
998 }
999 Parser.Lex(); // Eat the last ':'
1000 return false;
1001}
1002
1003const MCExpr *
1004ARMAsmParser::ApplyPrefixToExpr(const MCExpr *E,
1005 MCSymbolRefExpr::VariantKind Variant) {
1006 // Recurse over the given expression, rebuilding it to apply the given variant
1007 // to the leftmost symbol.
1008 if (Variant == MCSymbolRefExpr::VK_None)
1009 return E;
1010
1011 switch (E->getKind()) {
1012 case MCExpr::Target:
1013 llvm_unreachable("Can't handle target expr yet");
1014 case MCExpr::Constant:
1015 llvm_unreachable("Can't handle lower16/upper16 of constant yet");
1016
1017 case MCExpr::SymbolRef: {
1018 const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E);
1019
1020 if (SRE->getKind() != MCSymbolRefExpr::VK_None)
1021 return 0;
1022
1023 return MCSymbolRefExpr::Create(&SRE->getSymbol(), Variant, getContext());
1024 }
1025
1026 case MCExpr::Unary:
1027 llvm_unreachable("Can't handle unary expressions yet");
1028
1029 case MCExpr::Binary: {
1030 const MCBinaryExpr *BE = cast<MCBinaryExpr>(E);
1031 const MCExpr *LHS = ApplyPrefixToExpr(BE->getLHS(), Variant);
1032 const MCExpr *RHS = BE->getRHS();
1033 if (!LHS)
1034 return 0;
1035
1036 return MCBinaryExpr::Create(BE->getOpcode(), LHS, RHS, getContext());
1037 }
1038 }
1039
1040 assert(0 && "Invalid expression kind!");
1041 return 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001042}
1043
Daniel Dunbar352e1482011-01-11 15:59:50 +00001044/// \brief Given a mnemonic, split out possible predication code and carry
1045/// setting letters to form a canonical mnemonic and flags.
1046//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001047// FIXME: Would be nice to autogen this.
Daniel Dunbar352e1482011-01-11 15:59:50 +00001048static StringRef SplitMnemonicAndCC(StringRef Mnemonic,
1049 unsigned &PredicationCode,
1050 bool &CarrySetting) {
1051 PredicationCode = ARMCC::AL;
1052 CarrySetting = false;
1053
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001054 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00001055 //
1056 // FIXME: Would be nice to autogen this.
Daniel Dunbar8ab11122011-01-10 21:01:03 +00001057 if (Mnemonic == "teq" || Mnemonic == "vceq" ||
1058 Mnemonic == "movs" ||
1059 Mnemonic == "svc" ||
1060 (Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
1061 Mnemonic == "vmls" || Mnemonic == "vnmls") ||
1062 Mnemonic == "vacge" || Mnemonic == "vcge" ||
1063 Mnemonic == "vclt" ||
1064 Mnemonic == "vacgt" || Mnemonic == "vcgt" ||
1065 Mnemonic == "vcle" ||
1066 (Mnemonic == "smlal" || Mnemonic == "umaal" || Mnemonic == "umlal" ||
1067 Mnemonic == "vabal" || Mnemonic == "vmlal" || Mnemonic == "vpadal" ||
1068 Mnemonic == "vqdmlal"))
Daniel Dunbar352e1482011-01-11 15:59:50 +00001069 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00001070
Daniel Dunbar352e1482011-01-11 15:59:50 +00001071 // First, split out any predication code.
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001072 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001073 .Case("eq", ARMCC::EQ)
1074 .Case("ne", ARMCC::NE)
1075 .Case("hs", ARMCC::HS)
1076 .Case("lo", ARMCC::LO)
1077 .Case("mi", ARMCC::MI)
1078 .Case("pl", ARMCC::PL)
1079 .Case("vs", ARMCC::VS)
1080 .Case("vc", ARMCC::VC)
1081 .Case("hi", ARMCC::HI)
1082 .Case("ls", ARMCC::LS)
1083 .Case("ge", ARMCC::GE)
1084 .Case("lt", ARMCC::LT)
1085 .Case("gt", ARMCC::GT)
1086 .Case("le", ARMCC::LE)
1087 .Case("al", ARMCC::AL)
1088 .Default(~0U);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001089 if (CC != ~0U) {
1090 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
Daniel Dunbar352e1482011-01-11 15:59:50 +00001091 PredicationCode = CC;
Bill Wendling52925b62010-10-29 23:50:21 +00001092 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001093
Daniel Dunbar352e1482011-01-11 15:59:50 +00001094 // Next, determine if we have a carry setting bit. We explicitly ignore all
1095 // the instructions we know end in 's'.
1096 if (Mnemonic.endswith("s") &&
1097 !(Mnemonic == "asrs" || Mnemonic == "cps" || Mnemonic == "mls" ||
1098 Mnemonic == "movs" || Mnemonic == "mrs" || Mnemonic == "smmls" ||
1099 Mnemonic == "vabs" || Mnemonic == "vcls" || Mnemonic == "vmls" ||
1100 Mnemonic == "vmrs" || Mnemonic == "vnmls" || Mnemonic == "vqabs" ||
1101 Mnemonic == "vrecps" || Mnemonic == "vrsqrts")) {
1102 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
1103 CarrySetting = true;
1104 }
1105
1106 return Mnemonic;
1107}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001108
1109/// \brief Given a canonical mnemonic, determine if the instruction ever allows
1110/// inclusion of carry set or predication code operands.
1111//
1112// FIXME: It would be nice to autogen this.
1113static void GetMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
1114 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001115 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
1116 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
1117 Mnemonic == "smull" || Mnemonic == "add" || Mnemonic == "adc" ||
1118 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
1119 Mnemonic == "umlal" || Mnemonic == "orr" || Mnemonic == "mov" ||
1120 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
1121 Mnemonic == "sbc" || Mnemonic == "mla" || Mnemonic == "umull" ||
1122 Mnemonic == "eor" || Mnemonic == "smlal" || Mnemonic == "mvn") {
1123 CanAcceptCarrySet = true;
1124 } else {
1125 CanAcceptCarrySet = false;
1126 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001127
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00001128 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
1129 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
1130 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
1131 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
1132 Mnemonic == "dsb" || Mnemonic == "movs") {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001133 CanAcceptPredicationCode = false;
1134 } else {
1135 CanAcceptPredicationCode = true;
1136 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001137}
1138
1139/// Parse an arm instruction mnemonic followed by its operands.
1140bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
1141 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1142 // Create the leading tokens for the mnemonic, split by '.' characters.
1143 size_t Start = 0, Next = Name.find('.');
1144 StringRef Head = Name.slice(Start, Next);
1145
Daniel Dunbar352e1482011-01-11 15:59:50 +00001146 // Split out the predication code and carry setting flag from the mnemonic.
1147 unsigned PredicationCode;
1148 bool CarrySetting;
1149 Head = SplitMnemonicAndCC(Head, PredicationCode, CarrySetting);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001150
Chris Lattner3a697562010-10-28 17:20:03 +00001151 Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
Bill Wendling9717fa92010-11-21 10:56:05 +00001152
Daniel Dunbar3771dd02011-01-11 15:59:53 +00001153 // Next, add the CCOut and ConditionCode operands, if needed.
1154 //
1155 // For mnemonics which can ever incorporate a carry setting bit or predication
1156 // code, our matching model involves us always generating CCOut and
1157 // ConditionCode operands to match the mnemonic "as written" and then we let
1158 // the matcher deal with finding the right instruction or generating an
1159 // appropriate error.
1160 bool CanAcceptCarrySet, CanAcceptPredicationCode;
1161 GetMnemonicAcceptInfo(Head, CanAcceptCarrySet, CanAcceptPredicationCode);
1162
1163 // Add the carry setting operand, if necessary.
1164 //
1165 // FIXME: It would be awesome if we could somehow invent a location such that
1166 // match errors on this operand would print a nice diagnostic about how the
1167 // 's' character in the mnemonic resulted in a CCOut operand.
1168 if (CanAcceptCarrySet) {
1169 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
1170 NameLoc));
1171 } else {
1172 // This mnemonic can't ever accept a carry set, but the user wrote one (or
1173 // misspelled another mnemonic).
1174
1175 // FIXME: Issue a nice error.
1176 }
1177
1178 // Add the predication code operand, if necessary.
1179 if (CanAcceptPredicationCode) {
1180 Operands.push_back(ARMOperand::CreateCondCode(
1181 ARMCC::CondCodes(PredicationCode), NameLoc));
1182 } else {
1183 // This mnemonic can't ever accept a predication code, but the user wrote
1184 // one (or misspelled another mnemonic).
1185
1186 // FIXME: Issue a nice error.
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00001187 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001188
1189 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00001190 while (Next != StringRef::npos) {
1191 Start = Next;
1192 Next = Name.find('.', Start + 1);
1193 Head = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001194
Chris Lattner3a697562010-10-28 17:20:03 +00001195 Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
Daniel Dunbar5747b132010-08-11 06:37:16 +00001196 }
1197
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001198 bool isMCR = (Head == "mcr" || Head == "mcr2" ||
1199 Head == "mcrr" || Head == "mcrr2" ||
1200 Head == "mrc" || Head == "mrc2" ||
1201 Head == "mrrc" || Head == "mrrc2");
1202
Daniel Dunbar5747b132010-08-11 06:37:16 +00001203 // Read the remaining operands.
1204 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001205 // Read the first operand.
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001206 if (ParseOperand(Operands, isMCR)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00001207 Parser.EatToEndOfStatement();
1208 return true;
1209 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001210
1211 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00001212 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001213
1214 // Parse and remember the operand.
Owen Andersone4e5e2a2011-01-13 21:46:02 +00001215 if (ParseOperand(Operands, isMCR)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00001216 Parser.EatToEndOfStatement();
1217 return true;
1218 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001219 }
1220 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001221
Chris Lattnercbf8a982010-09-11 16:18:25 +00001222 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1223 Parser.EatToEndOfStatement();
Chris Lattner34e53142010-09-08 05:10:46 +00001224 return TokError("unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00001225 }
Bill Wendling146018f2010-11-06 21:42:12 +00001226
Chris Lattner34e53142010-09-08 05:10:46 +00001227 Parser.Lex(); // Consume the EndOfStatement
Chris Lattner98986712010-01-14 22:21:20 +00001228 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001229}
1230
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001231bool ARMAsmParser::
1232MatchAndEmitInstruction(SMLoc IDLoc,
1233 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
1234 MCStreamer &Out) {
1235 MCInst Inst;
1236 unsigned ErrorInfo;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001237 MatchResultTy MatchResult, MatchResult2;
1238 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1239 if (MatchResult != Match_Success) {
1240 // If we get a Match_InvalidOperand it might be some arithmetic instruction
1241 // that does not update the condition codes. So try adding a CCOut operand
1242 // with a value of reg0.
1243 if (MatchResult == Match_InvalidOperand) {
1244 Operands.insert(Operands.begin() + 1,
1245 ARMOperand::CreateCCOut(0,
1246 ((ARMOperand*)Operands[0])->getStartLoc()));
1247 MatchResult2 = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1248 if (MatchResult2 == Match_Success)
1249 MatchResult = Match_Success;
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001250 else {
1251 ARMOperand *CCOut = ((ARMOperand*)Operands[1]);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001252 Operands.erase(Operands.begin() + 1);
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001253 delete CCOut;
1254 }
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001255 }
1256 // If we get a Match_MnemonicFail it might be some arithmetic instruction
1257 // that updates the condition codes if it ends in 's'. So see if the
1258 // mnemonic ends in 's' and if so try removing the 's' and adding a CCOut
1259 // operand with a value of CPSR.
1260 else if(MatchResult == Match_MnemonicFail) {
1261 // Get the instruction mnemonic, which is the first token.
1262 StringRef Mnemonic = ((ARMOperand*)Operands[0])->getToken();
1263 if (Mnemonic.substr(Mnemonic.size()-1) == "s") {
1264 // removed the 's' from the mnemonic for matching.
1265 StringRef MnemonicNoS = Mnemonic.slice(0, Mnemonic.size() - 1);
1266 SMLoc NameLoc = ((ARMOperand*)Operands[0])->getStartLoc();
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001267 ARMOperand *OldMnemonic = ((ARMOperand*)Operands[0]);
1268 Operands.erase(Operands.begin());
1269 delete OldMnemonic;
1270 Operands.insert(Operands.begin(),
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001271 ARMOperand::CreateToken(MnemonicNoS, NameLoc));
1272 Operands.insert(Operands.begin() + 1,
1273 ARMOperand::CreateCCOut(ARM::CPSR, NameLoc));
1274 MatchResult2 = MatchInstructionImpl(Operands, Inst, ErrorInfo);
1275 if (MatchResult2 == Match_Success)
1276 MatchResult = Match_Success;
1277 else {
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001278 ARMOperand *OldMnemonic = ((ARMOperand*)Operands[0]);
1279 Operands.erase(Operands.begin());
1280 delete OldMnemonic;
1281 Operands.insert(Operands.begin(),
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001282 ARMOperand::CreateToken(Mnemonic, NameLoc));
Kevin Enderby44a9e8f2010-12-10 01:41:56 +00001283 ARMOperand *CCOut = ((ARMOperand*)Operands[1]);
1284 Operands.erase(Operands.begin() + 1);
1285 delete CCOut;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00001286 }
1287 }
1288 }
1289 }
1290 switch (MatchResult) {
Chris Lattnere73d4f82010-10-28 21:41:58 +00001291 case Match_Success:
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001292 Out.EmitInstruction(Inst);
1293 return false;
Chris Lattnere73d4f82010-10-28 21:41:58 +00001294 case Match_MissingFeature:
1295 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
1296 return true;
1297 case Match_InvalidOperand: {
1298 SMLoc ErrorLoc = IDLoc;
1299 if (ErrorInfo != ~0U) {
1300 if (ErrorInfo >= Operands.size())
1301 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00001302
Chris Lattnere73d4f82010-10-28 21:41:58 +00001303 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
1304 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
1305 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001306
Chris Lattnere73d4f82010-10-28 21:41:58 +00001307 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001308 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00001309 case Match_MnemonicFail:
1310 return Error(IDLoc, "unrecognized instruction mnemonic");
1311 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001312
Eric Christopherc223e2b2010-10-29 09:26:59 +00001313 llvm_unreachable("Implement any new match types added!");
Bill Wendling146018f2010-11-06 21:42:12 +00001314 return true;
Chris Lattnerfa42fad2010-10-28 21:28:01 +00001315}
1316
Kevin Enderby515d5092009-10-15 20:48:48 +00001317/// ParseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001318bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
1319 StringRef IDVal = DirectiveID.getIdentifier();
1320 if (IDVal == ".word")
1321 return ParseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00001322 else if (IDVal == ".thumb")
1323 return ParseDirectiveThumb(DirectiveID.getLoc());
1324 else if (IDVal == ".thumb_func")
1325 return ParseDirectiveThumbFunc(DirectiveID.getLoc());
1326 else if (IDVal == ".code")
1327 return ParseDirectiveCode(DirectiveID.getLoc());
1328 else if (IDVal == ".syntax")
1329 return ParseDirectiveSyntax(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001330 return true;
1331}
1332
1333/// ParseDirectiveWord
1334/// ::= .word [ expression (, expression)* ]
1335bool ARMAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
1336 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1337 for (;;) {
1338 const MCExpr *Value;
1339 if (getParser().ParseExpression(Value))
1340 return true;
1341
Chris Lattneraaec2052010-01-19 19:46:13 +00001342 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001343
1344 if (getLexer().is(AsmToken::EndOfStatement))
1345 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00001346
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001347 // FIXME: Improve diagnostic.
1348 if (getLexer().isNot(AsmToken::Comma))
1349 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001350 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001351 }
1352 }
1353
Sean Callananb9a25b72010-01-19 20:27:46 +00001354 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001355 return false;
1356}
1357
Kevin Enderby515d5092009-10-15 20:48:48 +00001358/// ParseDirectiveThumb
1359/// ::= .thumb
1360bool ARMAsmParser::ParseDirectiveThumb(SMLoc L) {
1361 if (getLexer().isNot(AsmToken::EndOfStatement))
1362 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001363 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001364
1365 // TODO: set thumb mode
1366 // TODO: tell the MC streamer the mode
1367 // getParser().getStreamer().Emit???();
1368 return false;
1369}
1370
1371/// ParseDirectiveThumbFunc
1372/// ::= .thumbfunc symbol_name
1373bool ARMAsmParser::ParseDirectiveThumbFunc(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001374 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001375 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
Jim Grosbach83c40182010-11-05 22:11:33 +00001376 return Error(L, "unexpected token in .thumb_func directive");
Jim Grosbach642fc9c2010-11-05 22:33:53 +00001377 StringRef Name = Tok.getString();
Sean Callananb9a25b72010-01-19 20:27:46 +00001378 Parser.Lex(); // Consume the identifier token.
Kevin Enderby515d5092009-10-15 20:48:48 +00001379 if (getLexer().isNot(AsmToken::EndOfStatement))
1380 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001381 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001382
Jim Grosbach642fc9c2010-11-05 22:33:53 +00001383 // Mark symbol as a thumb symbol.
1384 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
1385 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00001386 return false;
1387}
1388
1389/// ParseDirectiveSyntax
1390/// ::= .syntax unified | divided
1391bool ARMAsmParser::ParseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001392 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001393 if (Tok.isNot(AsmToken::Identifier))
1394 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00001395 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00001396 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00001397 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00001398 else if (Mode == "divided" || Mode == "DIVIDED")
Sean Callananb9a25b72010-01-19 20:27:46 +00001399 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001400 else
1401 return Error(L, "unrecognized syntax mode in .syntax directive");
1402
1403 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00001404 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001405 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001406
1407 // TODO tell the MC streamer the mode
1408 // getParser().getStreamer().Emit???();
1409 return false;
1410}
1411
1412/// ParseDirectiveCode
1413/// ::= .code 16 | 32
1414bool ARMAsmParser::ParseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001415 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001416 if (Tok.isNot(AsmToken::Integer))
1417 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00001418 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00001419 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00001420 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00001421 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00001422 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001423 else
1424 return Error(L, "invalid operand to .code directive");
1425
1426 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00001427 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001428 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001429
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00001430 // FIXME: We need to be able switch subtargets at this point so that
1431 // MatchInstructionImpl() will work when it gets the AvailableFeatures which
1432 // includes Feature_IsThumb or not to match the right instructions. This is
1433 // blocked on the FIXME in llvm-mc.cpp when creating the TargetMachine.
1434 if (Val == 16){
1435 assert(TM.getSubtarget<ARMSubtarget>().isThumb() &&
1436 "switching between arm/thumb not yet suppported via .code 16)");
Jim Grosbach2a301702010-11-05 22:40:53 +00001437 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00001438 }
1439 else{
1440 assert(!TM.getSubtarget<ARMSubtarget>().isThumb() &&
1441 "switching between thumb/arm not yet suppported via .code 32)");
Jim Grosbach2a301702010-11-05 22:40:53 +00001442 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderbyfef9ff42011-01-13 01:07:01 +00001443 }
Jim Grosbach2a301702010-11-05 22:40:53 +00001444
Kevin Enderby515d5092009-10-15 20:48:48 +00001445 return false;
1446}
1447
Sean Callanan90b70972010-04-07 20:29:34 +00001448extern "C" void LLVMInitializeARMAsmLexer();
1449
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001450/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001451extern "C" void LLVMInitializeARMAsmParser() {
1452 RegisterAsmParser<ARMAsmParser> X(TheARMTarget);
1453 RegisterAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00001454 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001455}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001456
Chris Lattner0692ee62010-09-06 19:11:01 +00001457#define GET_REGISTER_MATCHER
1458#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001459#include "ARMGenAsmMatcher.inc"